]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/VariableMapImpl.java
Some enhancements made by Antti for multiple readers
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / variable / VariableMapImpl.java
1 package org.simantics.db.layer0.variable;
2
3 import java.util.HashMap;
4 import java.util.Map;
5 import java.util.Set;
6
7 import org.simantics.db.ReadGraph;
8 import org.simantics.db.exception.DatabaseException;
9
10 abstract public class VariableMapImpl implements VariableMap {
11
12         @Override
13         public Variable getVariable(ReadGraph graph, Variable context, String name) throws DatabaseException {
14                 return getVariables(graph, context, null).get(name);
15         }
16
17         @Override
18         public Map<String, Variable> getVariables(ReadGraph graph, Variable context, String classification, Map<String, Variable> map) throws DatabaseException {
19                 
20         Map<String,Variable> all = getVariables(graph, context, null);
21         if(all.isEmpty()) return all;
22     
23         for(Map.Entry<String, Variable> entry : all.entrySet()) {
24         
25                 Set<String> classifications = entry.getValue().getClassifications(graph);
26                 if(classifications.contains(classification)) {
27                         if(map == null) map = new HashMap<String,Variable>();
28                         map.put(entry.getKey(), entry.getValue());
29                 }
30         }
31         
32         return map;
33                 
34         }
35
36 }