]> gerrit.simantics Code Review - simantics/platform.git/blob
45aa25faa22739d9a89d166ff026bfb9c2de8c00
[simantics/platform.git] /
1 package org.simantics.graph.compiler.internal.templates;
2
3 import java.util.Collection;
4
5 import org.simantics.graph.compiler.ExternalFileLoader;
6 import org.simantics.graph.query.IGraph;
7 import org.simantics.graph.query.Paths;
8 import org.simantics.graph.store.GraphStore;
9 import org.simantics.ltk.Problem;
10
11 public enum OrderedSetTemplate implements ITemplate {
12         
13         INSTANCE;
14         
15         @Override
16         public void apply(IGraph graph, GraphStore store,
17                         int[] parameters, ExternalFileLoader fileLoader, Collection<Problem> problems) {
18                 createList(graph.getPaths(), store, parameters);
19         }
20         
21         public static void createList(Paths paths, GraphStore store, int[] parameters) {
22                 int InverseOf = store.identities.createPathToId(paths.InverseOf);
23                 int SubrelationOf = store.identities.createPathToId(paths.SubrelationOf);
24                 int HasNext = store.identities.createPathToId(paths.HasNext);
25                 int HasPrevious = store.identities.createPathToId(paths.HasPrevious);
26                 
27                 int relation = parameters[0];           
28                 store.statements.add(relation, SubrelationOf, HasNext);
29                 int inverse = store.identities.newResource();
30                 store.statements.add(inverse, SubrelationOf, HasPrevious);
31                 store.statements.add(relation, InverseOf, inverse);
32                 
33                 for(int i=1;i<parameters.length;++i)
34                         store.statements.add(parameters[i-1], relation, parameters[i]);
35                 store.statements.add(parameters[parameters.length-1], relation, relation);
36         }
37
38 }
39