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