]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/templates/ListTemplate.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.graph.compiler / src / org / simantics / graph / compiler / internal / templates / ListTemplate.java
diff --git a/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/templates/ListTemplate.java b/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/internal/templates/ListTemplate.java
new file mode 100644 (file)
index 0000000..e30b1a5
--- /dev/null
@@ -0,0 +1,39 @@
+package org.simantics.graph.compiler.internal.templates;\r
+\r
+import java.util.Collection;\r
+\r
+import org.simantics.graph.compiler.ExternalFileLoader;\r
+import org.simantics.graph.query.IGraph;\r
+import org.simantics.graph.query.Paths;\r
+import org.simantics.graph.store.GraphStore;\r
+import org.simantics.ltk.Problem;\r
+\r
+public enum ListTemplate implements ITemplate {\r
+       \r
+       INSTANCE;\r
+       \r
+       @Override\r
+       public void apply(IGraph graph, GraphStore store,\r
+                       int[] parameters, ExternalFileLoader fileLoader, Collection<Problem> problems) {\r
+               createList(graph.getPaths(), store, parameters);\r
+       }\r
+       \r
+       public static void createList(Paths paths, GraphStore store, int[] parameters) {\r
+           int InstanceOf = store.identities.createPathToId(paths.InstanceOf);\r
+               int Entry = store.identities.createPathToId(paths.List_Entry);\r
+               int Next = store.identities.createPathToId(paths.List_Next);\r
+               int Element = store.identities.createPathToId(paths.List_Element);\r
+\r
+               int oldEntry = parameters[0];           \r
+               for(int i=1;i<parameters.length;++i) {\r
+                   int newEntry = store.identities.newResource();\r
+                   store.statements.add(newEntry, InstanceOf, Entry);\r
+                   store.statements.add(oldEntry, Next, newEntry);                 \r
+                   store.statements.add(newEntry, Element, parameters[i]);\r
+                   oldEntry = newEntry;\r
+               }\r
+               store.statements.add(oldEntry, Next, parameters[0]);\r
+       }\r
+\r
+}\r
+\r