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