]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/procedures/DefaultValueTyping.java
98ae7b943a6e1bdbc588c124e9070e6db8d1762f
[simantics/platform.git] / bundles / org.simantics.graph.compiler / src / org / simantics / graph / compiler / internal / procedures / DefaultValueTyping.java
1 package org.simantics.graph.compiler.internal.procedures;
2
3 import gnu.trove.procedure.TIntObjectProcedure;
4 import gnu.trove.set.hash.TIntHashSet;
5
6 import org.simantics.graph.compiler.internal.store.IPreValue;
7 import org.simantics.graph.compiler.internal.store.PreValueStore;
8 import org.simantics.graph.query.Path;
9 import org.simantics.graph.query.Paths;
10 import org.simantics.graph.store.GraphStore;
11
12 public class DefaultValueTyping implements Runnable {
13
14         GraphStore store;
15         Paths paths;
16         
17         public DefaultValueTyping(Paths paths, GraphStore store) {
18             this.paths = paths;
19                 this.store = store;
20         }
21
22         @Override
23         public void run() {
24                 final int instanceOfId = store.identities.createPathToId(paths.InstanceOf);
25                 final TIntHashSet 
26                         instanceOfDomain = store.statements.getRelationDomain(instanceOfId);
27                 PreValueStore preValues = store.getStore(PreValueStore.class);
28                 preValues.forEachPreValue(new TIntObjectProcedure<IPreValue>() {                
29                         @Override
30                         public boolean execute(int a, IPreValue b) {
31                                 if(!instanceOfDomain.contains(a)) {
32                                         Path defaultType = b.getDefaultType(paths);
33                                         if(defaultType != null)
34                                                 store.statements.add(a, 
35                                                                 instanceOfId,
36                                                                 store.identities.createPathToId(defaultType)
37                                                         );
38                                 }
39                                 return true;
40                         }
41                 });
42         }       
43
44 }