for (PropertyDescriptorValue propertyDescriptor : propertyList) {
String name = propertyDescriptor.name();
boolean isInternal = INTERNAL_PROPERTY_NAME.contains(name);
JsObjectProperty property = valueBuilder.createObjectProperty(propertyDescriptor,
objectId, name);
if (isInternal) {
internalProperties.add(property);
} else {
properties.add(property);
}
}
if (internalPropertyList != null) {
for (InternalPropertyDescriptorValue propertyDescriptor : internalPropertyList) {
String name = propertyDescriptor.name();
JsVariable variable =
valueBuilder.createVariable(propertyDescriptor.value(), name);
internalProperties.add(variable);
}
}
final ObjectProperties result = new ObjectProperties() {
private volatile Map<String, JsVariable> propertyMap = null;
@Override
public List<? extends JsObjectProperty> properties() {
return properties;
}
@Override
public List<? extends JsVariable> internalProperties() {
return internalProperties;
}
@Override
public JsVariable getProperty(String name) {
Map<String, JsVariable> map = propertyMap;
if (map == null) {
List<? extends JsVariable> list = properties();
map = new HashMap<String, JsVariable>(list.size());
for (JsVariable property : list) {
map.put(property.getName(), property);
}
// Possibly overwrite other already created map, but we don't care about instance here.
propertyMap = map;
}
return map.get(name);