import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Function;
import org.simantics.scl.compiler.constants.Constant;
import org.simantics.scl.compiler.elaboration.chr.CHRRuleset;
public abstract class LazyModule implements Module {
- String moduleName;
- private THashMap<String, SCLValue> values = new THashMap<String, SCLValue>();
- private THashMap<String, SCLRelation> relations = new THashMap<String, SCLRelation>();
- private THashMap<String, SCLEntityType> entityTypes = new THashMap<String, SCLEntityType>();
+ private final String moduleName;
+ private final ConcurrentHashMap<String, SCLValue> values = new ConcurrentHashMap<String, SCLValue>();
+ private final ConcurrentHashMap<String, SCLRelation> relations = new ConcurrentHashMap<String, SCLRelation>();
+ private final ConcurrentHashMap<String, SCLEntityType> entityTypes = new ConcurrentHashMap<String, SCLEntityType>();
protected abstract SCLValue createValue(String name);
public void findValuesForPrefix(final Collection<SCLValue> values, final String prefix) {
}
+ private final Function<String, SCLValue> createValue = this::createValue;
+
@Override
public SCLValue getValue(String name) {
- if(values.containsKey(name))
- return values.get(name);
- else {
- SCLValue value = createValue(name);
- values.put(name, value);
- return value;
- }
+ return values.computeIfAbsent(name, createValue);
}
@Override
return null;
}
+ private final Function<String, SCLRelation> createRelation = this::createRelation;
+
public SCLRelation getRelation(String name) {
- if(relations.containsKey(name))
- return relations.get(name);
- else {
- SCLRelation relation = createRelation(name);
- relations.put(name, relation);
- return relation;
- }
+ return relations.computeIfAbsent(name, createRelation);
}
+ private final Function<String, SCLEntityType> createEntityType = this::createEntityType;
+
public SCLEntityType getEntityType(String name) {
- if(entityTypes.containsKey(name))
- return entityTypes.get(name);
- else {
- SCLEntityType entityType = createEntityType(name);
- entityTypes.put(name, entityType);
- return entityType;
- }
+ return entityTypes.computeIfAbsent(name, createEntityType);
}
@Override