]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - 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
diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ArraySet.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ArraySet.java
new file mode 100644 (file)
index 0000000..d7e0aa8
--- /dev/null
@@ -0,0 +1,130 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.db.impl.graph;\r
+\r
+import java.util.Collection;\r
+import java.util.Iterator;\r
+import java.util.Set;\r
+\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.impl.query.IntSet;\r
+import org.simantics.db.impl.query.QuerySupport;\r
+\r
+public class ArraySet implements Set<Resource> {\r
+    \r
+    final Resource[] set;\r
+\r
+    ArraySet(IntSet intSet, QuerySupport support) {\r
+        \r
+        if(intSet.data == null) {\r
+            if(intSet.sizeOrData != IntSet.NO_DATA) {\r
+                set = new Resource[] { support.getResource(intSet.sizeOrData) };\r
+            } else {\r
+                set = Resource.NONE;\r
+            }\r
+        } else {\r
+            set = new Resource[intSet.sizeOrData];\r
+            for(int i=0;i<intSet.sizeOrData;i++) set[i] = support.getResource(intSet.data[i]);\r
+        }\r
+        \r
+    }\r
+    \r
+    @Override\r
+    public boolean add(Resource e) {\r
+        throw new UnsupportedOperationException();\r
+    }\r
+\r
+    @Override\r
+    public boolean addAll(Collection<? extends Resource> c) {\r
+        throw new UnsupportedOperationException();\r
+    }\r
+\r
+    @Override\r
+    public void clear() {\r
+        throw new UnsupportedOperationException();\r
+    }\r
+\r
+    @Override\r
+    public boolean contains(Object o) {\r
+        for(int i=0;i<set.length;i++) if(o.equals(set[i])) return true;\r
+        return false;\r
+    }\r
+\r
+    @Override\r
+    public boolean containsAll(Collection<?> c) {\r
+        throw new UnsupportedOperationException();\r
+    }\r
+\r
+    @Override\r
+    public boolean isEmpty() {\r
+        return set.length == 0;\r
+    }\r
+\r
+    @Override\r
+    public Iterator<Resource> iterator() {\r
+        \r
+        class ArraySetIterator implements Iterator<Resource> {\r
+            \r
+            int next = 0;\r
+\r
+            @Override\r
+            public boolean hasNext() {\r
+                return next < set.length;\r
+            }\r
+\r
+            @Override\r
+            public Resource next() {\r
+                return set[next++];\r
+            }\r
+\r
+            @Override\r
+            public void remove() {\r
+                throw new UnsupportedOperationException();\r
+            }\r
+            \r
+        }\r
+        \r
+        return new ArraySetIterator();\r
+        \r
+    }\r
+\r
+    @Override\r
+    public boolean remove(Object o) {\r
+        throw new UnsupportedOperationException();\r
+    }\r
+\r
+    @Override\r
+    public boolean removeAll(Collection<?> c) {\r
+        throw new UnsupportedOperationException();\r
+    }\r
+\r
+    @Override\r
+    public boolean retainAll(Collection<?> c) {\r
+        throw new UnsupportedOperationException();\r
+    }\r
+\r
+    @Override\r
+    public int size() {\r
+        return set.length;\r
+    }\r
+\r
+    @Override\r
+    public Object[] toArray() {\r
+        throw new UnsupportedOperationException();\r
+    }\r
+\r
+    @Override\r
+    public <T> T[] toArray(T[] a) {\r
+        throw new UnsupportedOperationException();\r
+    }\r
+\r
+}\r