]> gerrit.simantics Code Review - simantics/interop.git/blob - org.simantics.interop.mapping/src/org/simantics/interop/mapping/data/ResourceSplitIdentifiable.java
refs #3483
[simantics/interop.git] / org.simantics.interop.mapping / src / org / simantics / interop / mapping / data / ResourceSplitIdentifiable.java
1 package org.simantics.interop.mapping.data;\r
2 \r
3 \r
4 import java.util.ArrayList;\r
5 import java.util.List;\r
6 \r
7 import org.simantics.db.Resource;\r
8 \r
9 public class ResourceSplitIdentifiable extends ResourceIdentifiable {\r
10 \r
11         private static int counter = 0;\r
12         \r
13         //private Resource resource;\r
14         private int identifier;\r
15         private int index;\r
16         \r
17         \r
18         ResourceSplitIdentifiable(Resource resource, int index, int identifier) {\r
19                 super(resource);\r
20                 this.index = index;\r
21                 this.identifier = identifier;\r
22         }\r
23         \r
24         public static List<Identifiable> createIdentifiables(ResourceIdentifiable identifiable, int count) {\r
25                 List<Identifiable> result = new ArrayList<Identifiable>(count);\r
26                 int identifier = counter++;\r
27                 for (int i = 0; i < count; i++) {\r
28                         result.add(new ResourceSplitIdentifiable(identifiable.getResource(), i, identifier));\r
29                 }\r
30                 return result;\r
31         }\r
32         \r
33         public static List<Identifiable> createIdentifiables(Identifiable identifiable, int count) {\r
34                 Resource res = identifiable.getAdapter(Resource.class);\r
35                 if (res == null)\r
36                         return null;\r
37 \r
38                 Resource resources[] = identifiable.getAdapter(Resource[].class);\r
39                 \r
40                 if (resources.length > 1) {\r
41                         return ResourceSetSplitIdentifiable.createIdentifiables(identifiable, count);   \r
42                 } else {\r
43                         List<Identifiable> result = new ArrayList<Identifiable>(count);\r
44                         int identifier = counter++;\r
45                         for (int i = 0; i < count; i++) {\r
46                                 result.add(new ResourceSplitIdentifiable(res, i, identifier));\r
47                         }\r
48                         return result;\r
49                 }\r
50 \r
51         }\r
52         \r
53         @Override\r
54         public boolean equals(Object arg0) {\r
55                 if (arg0 == null)\r
56                         return false;\r
57                 if (this.getClass() != arg0.getClass())\r
58                         return false;\r
59                 ResourceSplitIdentifiable other = (ResourceSplitIdentifiable)arg0;\r
60                 if (identifier != other.identifier)\r
61                         return false;\r
62                 if (index != other.index)\r
63                         return false;\r
64                 return resource.equals(other.resource);\r
65         }\r
66         \r
67         @Override\r
68         public Identifiable merge(Identifiable other) {\r
69                 throw new RuntimeException("Cannot be merged");\r
70         }\r
71         \r
72         \r
73         \r
74 }\r