Statistics
| Revision:

root / trunk / libraries / libDataSource / src / org / gvsig / data / vectorial / MemoryFeatureCollection.java @ 19399

History | View | Annotate | Download (4.25 KB)

1
package org.gvsig.data.vectorial;
2

    
3
import java.util.ArrayList;
4
import java.util.Collection;
5
import java.util.Iterator;
6
import java.util.List;
7
import java.util.ListIterator;
8

    
9
import org.gvsig.data.IObservable;
10
import org.gvsig.data.IObserver;
11

    
12
public class MemoryFeatureCollection implements IFeatureCollection, IObserver {
13

    
14
        protected ArrayList features = new ArrayList();//<IFeatureID>
15
        protected Iterator iter = null;
16
        protected boolean allowmodify = true;
17

    
18
        public MemoryFeatureCollection() {
19

    
20
        }
21

    
22
        public void rewind() {
23
                iter = null;
24
                allowmodify = true;
25
        }
26

    
27
        public IFeature next() {
28
                if( iter == null ) {
29
                        iter = features.iterator();
30
                        allowmodify = false;
31
                }
32
                if( iter.hasNext() ) {
33
                        return (IFeature) iter.next();
34
                }
35
                return null;
36
        }
37

    
38
        public int size() {
39
                return features.size();
40
        }
41

    
42
        public boolean add(IFeature feature) {
43
                if( !allowmodify ) {
44
                        throw new RuntimeException();
45
                }
46
                return features.add(feature.getID());
47
        }
48

    
49
        public boolean add(IFeatureID id) {
50
                if( !allowmodify ) {
51
                        throw new RuntimeException();
52
                }
53
                return features.add(id);
54
        }
55

    
56
        public boolean contains(IFeatureID id) {
57
                return features.contains(id);
58
        }
59

    
60
        public boolean contains(IFeature feature) {
61
                return features.contains(feature.getID());
62
        }
63

    
64
        public boolean remove(IFeatureID id) {
65
                if( !allowmodify ) {
66
                        throw new RuntimeException();
67
                }
68
                return features.remove(id);
69
        }
70

    
71
        public boolean remove(IFeature feature) {
72
                if( !allowmodify ) {
73
                        throw new RuntimeException();
74
                }
75
                return features.remove(feature.getID());
76
        }
77

    
78
        public Object set(int i, IFeatureID id) {
79
                if( !allowmodify ) {
80
                        throw new RuntimeException();
81
                }
82
                return features.set(i, id);
83
        }
84

    
85
        public Object set(int i, IFeature feature) {
86
                if( !allowmodify ) {
87
                        throw new RuntimeException();
88
                }
89
                return features.set(i, feature.getID());
90
        }
91

    
92

    
93

    
94
        //==============================================
95

    
96

    
97

    
98
        public boolean add(Object arg0) {
99
                throw new RuntimeException();
100
        }
101

    
102
        public void add(int arg0, Object arg1) {
103
                if( !allowmodify ) {
104
                        throw new RuntimeException();
105
                }
106
                features.add(arg0,(IFeatureID)arg1);
107
        }
108

    
109
        public boolean addAll(Collection arg0) {
110
                if( !allowmodify ) {
111
                        throw new RuntimeException();
112
                }
113
                return features.addAll(arg0);
114
        }
115

    
116
        public boolean addAll(int arg0, Collection arg1) {
117
                if( !allowmodify ) {
118
                        throw new RuntimeException();
119
                }
120
                return features.addAll(arg0,arg1);
121
        }
122

    
123
        public void clear() {
124
                if( !allowmodify ) {
125
                        throw new RuntimeException();
126
                }
127
                features.clear();
128
        }
129

    
130
        public boolean contains(Object arg0) {
131
                return features.contains(arg0);
132
        }
133

    
134
        public boolean containsAll(Collection arg0) {
135
                return features.containsAll(arg0);
136
        }
137

    
138
        public Object get(int arg0) {
139
                return features.get(arg0);
140
        }
141

    
142
        public int indexOf(Object arg0) {
143
                return features.indexOf(arg0);
144
        }
145

    
146
        public boolean isEmpty() {
147
                return features.isEmpty();
148
        }
149

    
150
        public Iterator iterator() {
151
                return features.iterator();
152
        }
153

    
154
        public int lastIndexOf(Object arg0) {
155
                return features.lastIndexOf(arg0);
156
        }
157

    
158
        public ListIterator listIterator() {
159
                return features.listIterator();
160
        }
161

    
162
        public ListIterator listIterator(int arg0) {
163
                return features.listIterator(arg0);
164
        }
165

    
166
        public boolean remove(Object arg0) {
167
                if( !allowmodify ) {
168
                        throw new RuntimeException();
169
                }
170
                return features.remove(arg0);
171
        }
172

    
173
        public Object remove(int arg0) {
174
                if( !allowmodify ) {
175
                        throw new RuntimeException();
176
                }
177
                return features.remove(arg0);
178
        }
179

    
180
        public boolean removeAll(Collection arg0) {
181
                if( !allowmodify ) {
182
                        throw new RuntimeException();
183
                }
184
                return features.removeAll(arg0);
185
        }
186

    
187
        public boolean retainAll(Collection arg0) {
188
                if( !allowmodify ) {
189
                        throw new RuntimeException();
190
                }
191
                return features.retainAll(arg0);
192
        }
193

    
194
        public Object set(int arg0, Object arg1) {
195
                throw new RuntimeException();
196
        }
197

    
198
        public List subList(int arg0, int arg1) {
199
                return features.subList(arg0, arg1);
200
        }
201

    
202
        public Object[] toArray() {
203
                return features.toArray();
204
        }
205

    
206
        public Object[] toArray(Object[] arg0) {
207
                return features.toArray(arg0);
208
        }
209

    
210
        public void update(IObservable obsevable, Object notification) {
211
                // TODO Auto-generated method stub
212

    
213
        }
214
}