]> gerrit.simantics Code Review - simantics/interop.git/blob - org.simantics.interop.mapping/src/org/simantics/interop/mapping/data/ObjectSetIdentifiable.java
Replace log4j with slf4j
[simantics/interop.git] / org.simantics.interop.mapping / src / org / simantics / interop / mapping / data / ObjectSetIdentifiable.java
1 package org.simantics.interop.mapping.data;\r
2 \r
3 import java.util.ArrayList;\r
4 import java.util.Collection;\r
5 import java.util.HashSet;\r
6 import java.util.Set;\r
7 \r
8 \r
9 public class ObjectSetIdentifiable implements Identifiable {\r
10 \r
11         private Set<Object> objs;\r
12         \r
13         public ObjectSetIdentifiable(Object obj) {\r
14                 objs = new HashSet<Object>();\r
15                 objs.add(obj);\r
16         }\r
17         \r
18         public ObjectSetIdentifiable(Object... obj) {\r
19                 this.objs = new HashSet<Object>();\r
20                 for (Object r : obj)\r
21                         this.objs.add(r);\r
22         }\r
23         \r
24         public ObjectSetIdentifiable(Collection<Object> obj) {\r
25                 this.objs = new HashSet<Object>();\r
26                 for (Object r : obj)\r
27                         this.objs.add(r);\r
28         }\r
29         \r
30         public Set<Object> getObjects() {\r
31                 return objs;\r
32         }\r
33         \r
34         @SuppressWarnings("unchecked")\r
35         @Override\r
36         public <T> T getAdapter(Class<T> clazz) {\r
37                 if (clazz.equals(String.class)) {\r
38                         String s = "";\r
39                         for (Object o : objs)\r
40                                 s += o.toString() + " ";\r
41                         return (T)s;\r
42                 }\r
43                 return null;\r
44         }\r
45         \r
46         @Override\r
47         public int hashCode() {\r
48                 return objs.hashCode();\r
49         }\r
50         \r
51         @Override\r
52         public boolean equals(Object arg0) {\r
53                 if (arg0 == null)\r
54                         return false;\r
55                 if (this.getClass() != arg0.getClass())\r
56                         return false;\r
57                 ObjectSetIdentifiable other = (ObjectSetIdentifiable)arg0;\r
58                 return objs.equals(other.objs);\r
59         }\r
60         \r
61         @Override\r
62         public Identifiable merge(Identifiable other) {\r
63                 if (other instanceof ObjectIdentifiable) {\r
64                         Collection<Object> coll = new ArrayList<Object>();\r
65                         coll.addAll(this.objs);\r
66                         coll.add(((ObjectIdentifiable)other).getObject());\r
67                         ObjectSetIdentifiable i = new ObjectSetIdentifiable(coll);\r
68                         return i;\r
69                 } else if (other instanceof ObjectSetIdentifiable) {\r
70                         Collection<Object> coll = new ArrayList<Object>();\r
71                         coll.addAll(this.objs);\r
72                         coll.addAll(((ObjectSetIdentifiable)other).getObjects());\r
73                         ObjectSetIdentifiable i = new ObjectSetIdentifiable(coll);\r
74                         return i;\r
75                 }\r
76                 return null;\r
77         }\r
78         \r
79 }\r