]> gerrit.simantics Code Review - simantics/platform.git/blob
27d382648a925934d46f4cb3da4dac3224e8bd0e
[simantics/platform.git] /
1 package org.simantics.graph.compiler.internal.templates;
2
3 import gnu.trove.map.hash.TIntIntHashMap;
4 import gnu.trove.map.hash.TIntObjectHashMap;
5 import gnu.trove.procedure.TIntObjectProcedure;
6 import gnu.trove.procedure.TObjectProcedure;
7 import gnu.trove.set.hash.TIntHashSet;
8
9 import org.simantics.graph.store.IStore;
10 import org.simantics.graph.store.IndexMappingUtils;
11
12 public class TemplateDefinitionStore implements IStore {
13         TIntObjectHashMap<TemplateDefinition> templateDefinitions;
14         TIntHashSet collisions = new TIntHashSet(); 
15
16         public TemplateDefinitionStore(TIntObjectHashMap<TemplateDefinition> templateDefinitions) {
17                 this.templateDefinitions = templateDefinitions;
18         }
19         
20         public TemplateDefinitionStore() {
21                 this(new TIntObjectHashMap<TemplateDefinition>());
22         }
23
24         @Override
25         public void map(final TIntIntHashMap map) {
26                 templateDefinitions = IndexMappingUtils.map(map, templateDefinitions, collisions);
27                 templateDefinitions.forEachValue(new TObjectProcedure<TemplateDefinition>() {                   
28                         @Override
29                         public boolean execute(TemplateDefinition template) {
30                                 template.map(map);
31                                 return true;
32                         }
33                 });
34         }
35         
36         public void forTemplateDefinitions(TIntObjectProcedure<TemplateDefinition> proc) {
37                 templateDefinitions.forEachEntry(proc);
38         }
39
40         public void add(int subject, TemplateDefinition templateDefinition) {
41                 templateDefinitions.put(subject, templateDefinition);
42         }
43
44         public boolean isEmpty() {
45                 return templateDefinitions.isEmpty();
46         }
47         
48         public TIntHashSet getCollisions() {
49                 return collisions;
50         }
51 }