--- /dev/null
+package org.simantics.interop.mapping.data;\r
+\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import org.simantics.db.Resource;\r
+\r
+public class ResourceSplitIdentifiable extends ResourceIdentifiable {\r
+\r
+ private static int counter = 0;\r
+ \r
+ //private Resource resource;\r
+ private int identifier;\r
+ private int index;\r
+ \r
+ \r
+ ResourceSplitIdentifiable(Resource resource, int index, int identifier) {\r
+ super(resource);\r
+ this.index = index;\r
+ this.identifier = identifier;\r
+ }\r
+ \r
+ public static List<Identifiable> createIdentifiables(ResourceIdentifiable identifiable, int count) {\r
+ List<Identifiable> result = new ArrayList<Identifiable>(count);\r
+ int identifier = counter++;\r
+ for (int i = 0; i < count; i++) {\r
+ result.add(new ResourceSplitIdentifiable(identifiable.getResource(), i, identifier));\r
+ }\r
+ return result;\r
+ }\r
+ \r
+ public static List<Identifiable> createIdentifiables(Identifiable identifiable, int count) {\r
+ Resource res = identifiable.getAdapter(Resource.class);\r
+ if (res == null)\r
+ return null;\r
+\r
+ Resource resources[] = identifiable.getAdapter(Resource[].class);\r
+ \r
+ if (resources.length > 1) {\r
+ return ResourceSetSplitIdentifiable.createIdentifiables(identifiable, count); \r
+ } else {\r
+ List<Identifiable> result = new ArrayList<Identifiable>(count);\r
+ int identifier = counter++;\r
+ for (int i = 0; i < count; i++) {\r
+ result.add(new ResourceSplitIdentifiable(res, i, identifier));\r
+ }\r
+ return result;\r
+ }\r
+\r
+ }\r
+ \r
+ @Override\r
+ public boolean equals(Object arg0) {\r
+ if (arg0 == null)\r
+ return false;\r
+ if (this.getClass() != arg0.getClass())\r
+ return false;\r
+ ResourceSplitIdentifiable other = (ResourceSplitIdentifiable)arg0;\r
+ if (identifier != other.identifier)\r
+ return false;\r
+ if (index != other.index)\r
+ return false;\r
+ return resource.equals(other.resource);\r
+ }\r
+ \r
+ @Override\r
+ public Identifiable merge(Identifiable other) {\r
+ throw new RuntimeException("Cannot be merged");\r
+ }\r
+ \r
+ \r
+ \r
+}\r