]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ArraySet.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / graph / ArraySet.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.db.impl.graph;\r
13 \r
14 import java.util.Collection;\r
15 import java.util.Iterator;\r
16 import java.util.Set;\r
17 \r
18 import org.simantics.db.Resource;\r
19 import org.simantics.db.impl.query.IntSet;\r
20 import org.simantics.db.impl.query.QuerySupport;\r
21 \r
22 public class ArraySet implements Set<Resource> {\r
23     \r
24     final Resource[] set;\r
25 \r
26     ArraySet(IntSet intSet, QuerySupport support) {\r
27         \r
28         if(intSet.data == null) {\r
29             if(intSet.sizeOrData != IntSet.NO_DATA) {\r
30                 set = new Resource[] { support.getResource(intSet.sizeOrData) };\r
31             } else {\r
32                 set = Resource.NONE;\r
33             }\r
34         } else {\r
35             set = new Resource[intSet.sizeOrData];\r
36             for(int i=0;i<intSet.sizeOrData;i++) set[i] = support.getResource(intSet.data[i]);\r
37         }\r
38         \r
39     }\r
40     \r
41     @Override\r
42     public boolean add(Resource e) {\r
43         throw new UnsupportedOperationException();\r
44     }\r
45 \r
46     @Override\r
47     public boolean addAll(Collection<? extends Resource> c) {\r
48         throw new UnsupportedOperationException();\r
49     }\r
50 \r
51     @Override\r
52     public void clear() {\r
53         throw new UnsupportedOperationException();\r
54     }\r
55 \r
56     @Override\r
57     public boolean contains(Object o) {\r
58         for(int i=0;i<set.length;i++) if(o.equals(set[i])) return true;\r
59         return false;\r
60     }\r
61 \r
62     @Override\r
63     public boolean containsAll(Collection<?> c) {\r
64         throw new UnsupportedOperationException();\r
65     }\r
66 \r
67     @Override\r
68     public boolean isEmpty() {\r
69         return set.length == 0;\r
70     }\r
71 \r
72     @Override\r
73     public Iterator<Resource> iterator() {\r
74         \r
75         class ArraySetIterator implements Iterator<Resource> {\r
76             \r
77             int next = 0;\r
78 \r
79             @Override\r
80             public boolean hasNext() {\r
81                 return next < set.length;\r
82             }\r
83 \r
84             @Override\r
85             public Resource next() {\r
86                 return set[next++];\r
87             }\r
88 \r
89             @Override\r
90             public void remove() {\r
91                 throw new UnsupportedOperationException();\r
92             }\r
93             \r
94         }\r
95         \r
96         return new ArraySetIterator();\r
97         \r
98     }\r
99 \r
100     @Override\r
101     public boolean remove(Object o) {\r
102         throw new UnsupportedOperationException();\r
103     }\r
104 \r
105     @Override\r
106     public boolean removeAll(Collection<?> c) {\r
107         throw new UnsupportedOperationException();\r
108     }\r
109 \r
110     @Override\r
111     public boolean retainAll(Collection<?> c) {\r
112         throw new UnsupportedOperationException();\r
113     }\r
114 \r
115     @Override\r
116     public int size() {\r
117         return set.length;\r
118     }\r
119 \r
120     @Override\r
121     public Object[] toArray() {\r
122         throw new UnsupportedOperationException();\r
123     }\r
124 \r
125     @Override\r
126     public <T> T[] toArray(T[] a) {\r
127         throw new UnsupportedOperationException();\r
128     }\r
129 \r
130 }\r