]> gerrit.simantics Code Review - simantics/platform.git/blob
f9855ce712d87741a4dfa5066f9b8ebcceca126b
[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 ListTemplate 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 InstanceOf = store.identities.createPathToId(paths.InstanceOf);
23                 int Entry = store.identities.createPathToId(paths.List_Entry);
24                 int Next = store.identities.createPathToId(paths.List_Next);
25                 int Element = store.identities.createPathToId(paths.List_Element);
26
27                 int oldEntry = parameters[0];           
28                 for(int i=1;i<parameters.length;++i) {
29                     int newEntry = store.identities.newResource();
30                     store.statements.add(newEntry, InstanceOf, Entry);
31                     store.statements.add(oldEntry, Next, newEntry);                 
32                     store.statements.add(newEntry, Element, parameters[i]);
33                     oldEntry = newEntry;
34                 }
35                 store.statements.add(oldEntry, Next, parameters[0]);
36         }
37
38 }
39