root / branches / Mobile_Compatible_Hito_1 / libFMap_dataFile / src / org / gvsig / data / datastores / vectorial / file / dbf / DBFFeatureCollection.java @ 21571
History | View | Annotate | Download (5.88 KB)
1 |
package org.gvsig.data.datastores.vectorial.file.dbf; |
---|---|
2 |
|
3 |
import java.util.ArrayList; |
4 |
import java.util.Collection; |
5 |
import java.util.Iterator; |
6 |
import java.util.NoSuchElementException; |
7 |
|
8 |
import org.gvsig.data.ReadException; |
9 |
import org.gvsig.data.vectorial.AbstractFeatureCollection; |
10 |
import org.gvsig.data.vectorial.FeatureManager; |
11 |
import org.gvsig.data.vectorial.Feature; |
12 |
import org.gvsig.data.vectorial.FeatureID; |
13 |
import org.gvsig.data.vectorial.FeatureStore; |
14 |
import org.gvsig.data.vectorial.FeatureType; |
15 |
//import org.gvsig.data.vectorial.expressionevaluator.FeatureFilter;
|
16 |
import org.gvsig.util.observer.DefaultObservable; |
17 |
import org.opengis.filter.Filter; |
18 |
|
19 |
public class DBFFeatureCollection extends AbstractFeatureCollection { |
20 |
protected DefaultObservable observable = new DefaultObservable(); |
21 |
protected ArrayList featureIDs=new ArrayList();//<FeatureID> |
22 |
protected FeatureType featureType;
|
23 |
protected Filter filter; |
24 |
protected FeatureStore store;
|
25 |
//private FeatureFilter parser = null;
|
26 |
protected FeatureManager featureManager;
|
27 |
protected long driverFeatureCount=0; |
28 |
protected long size=-1; |
29 |
|
30 |
public DBFFeatureCollection(FeatureManager fm,DBFStore store,FeatureType type, Filter filter) throws ReadException { |
31 |
this.featureManager=fm;
|
32 |
this.store=store;
|
33 |
driverFeatureCount=store.getFeatureCount(); |
34 |
this.featureType=type;
|
35 |
this.filter=filter;
|
36 |
//if (this.filter!=null)
|
37 |
// parser = new FeatureFilter(filter,this.featureType);
|
38 |
|
39 |
} |
40 |
|
41 |
public int size() { |
42 |
this.checkModified();
|
43 |
if (this.size < 0){ |
44 |
if (filter==null){ |
45 |
this.size = driverFeatureCount;
|
46 |
if (featureManager!=null){ |
47 |
this.size += featureManager.getNum();
|
48 |
} |
49 |
} else {
|
50 |
Iterator iterator= this.iterator(); |
51 |
this.size=0; |
52 |
try {
|
53 |
while(true){ |
54 |
iterator.next(); |
55 |
size++; |
56 |
} |
57 |
} catch (NoSuchElementException e) { |
58 |
//End
|
59 |
} |
60 |
} |
61 |
} |
62 |
return (int)this.size; |
63 |
} |
64 |
|
65 |
public boolean isEmpty() { |
66 |
this.checkModified();
|
67 |
return (size()==0); |
68 |
} |
69 |
|
70 |
public boolean contains(Object o) { |
71 |
this.checkModified();
|
72 |
Iterator iterator= this.iterator(); |
73 |
while(iterator.hasNext()){
|
74 |
Feature feature=(Feature)iterator.next(); |
75 |
if (feature.getID().equals(((Feature)o).getID())){
|
76 |
return true; |
77 |
} |
78 |
} |
79 |
return false; |
80 |
} |
81 |
|
82 |
public Iterator iterator() { |
83 |
this.checkModified();
|
84 |
DBFIterator dbfIter=new DBFIterator(this.featureType); |
85 |
return dbfIter;
|
86 |
} |
87 |
|
88 |
public Object[] toArray() { |
89 |
this.checkModified();
|
90 |
ArrayList features= new ArrayList(); |
91 |
Iterator iterator= this.iterator(); |
92 |
while(iterator.hasNext()){
|
93 |
Feature feature=(Feature)iterator.next(); |
94 |
features.add(feature); |
95 |
} |
96 |
return features.toArray();
|
97 |
} |
98 |
|
99 |
public Object[] toArray(Object[] a) { |
100 |
this.checkModified();
|
101 |
ArrayList features= new ArrayList(); |
102 |
Iterator iterator= this.iterator(); |
103 |
while(iterator.hasNext()){
|
104 |
Feature feature=(Feature)iterator.next(); |
105 |
features.add(feature); |
106 |
} |
107 |
return features.toArray(a);
|
108 |
} |
109 |
|
110 |
public boolean add(Object o) { |
111 |
throw new UnsupportedOperationException(); |
112 |
} |
113 |
|
114 |
public boolean remove(Object o) { |
115 |
throw new UnsupportedOperationException(); |
116 |
} |
117 |
|
118 |
public boolean containsAll(Collection c) { |
119 |
this.checkModified();
|
120 |
Iterator iter = c.iterator();
|
121 |
while (iter.hasNext()){
|
122 |
if (!this.contains(iter.next())){ |
123 |
return false; |
124 |
} |
125 |
} |
126 |
return true; |
127 |
|
128 |
} |
129 |
|
130 |
public boolean addAll(Collection c) { |
131 |
throw new UnsupportedOperationException(); |
132 |
} |
133 |
|
134 |
public boolean removeAll(Collection c) { |
135 |
throw new UnsupportedOperationException(); |
136 |
} |
137 |
|
138 |
public boolean retainAll(Collection c) { |
139 |
throw new UnsupportedOperationException(); |
140 |
} |
141 |
|
142 |
public void clear() { |
143 |
throw new UnsupportedOperationException(); |
144 |
} |
145 |
|
146 |
|
147 |
protected class DBFIterator implements Iterator{ |
148 |
protected long position=0; |
149 |
private boolean nextChecked=false; |
150 |
private Feature feature;
|
151 |
private FeatureType featureType;
|
152 |
|
153 |
public DBFIterator(FeatureType featureType){
|
154 |
this.featureType=featureType;
|
155 |
position=0;
|
156 |
} |
157 |
|
158 |
|
159 |
protected FeatureID createCurrentFeatureID(long pos){ |
160 |
if (pos<driverFeatureCount){
|
161 |
return new DBFFeatureID((DBFStore)store,pos); |
162 |
} else {
|
163 |
return null; |
164 |
} |
165 |
} |
166 |
|
167 |
public boolean hasNext(){ |
168 |
checkModified(); |
169 |
|
170 |
Feature feature=null;
|
171 |
if (nextChecked){
|
172 |
return this.feature != null; |
173 |
} |
174 |
nextChecked=true;
|
175 |
while (true){ |
176 |
if (position<driverFeatureCount){
|
177 |
FeatureID featureID = this.createCurrentFeatureID(position);
|
178 |
try {
|
179 |
feature=featureID.getFeature(featureType); |
180 |
} catch (ReadException e) {
|
181 |
throw new RuntimeException(e); |
182 |
} |
183 |
}else if (featureManager!=null && (position-driverFeatureCount)<featureManager.getNum()){ |
184 |
int pos=(int)(position-driverFeatureCount); |
185 |
try {
|
186 |
feature=featureManager.getFeature(pos,store,this.featureType);
|
187 |
} catch (ReadException e) {
|
188 |
throw new RuntimeException(e); |
189 |
} |
190 |
}else{
|
191 |
this.feature = null; |
192 |
return false; |
193 |
} |
194 |
|
195 |
position++; |
196 |
|
197 |
if(featureManager!=null && featureManager.isDeleted(feature)) |
198 |
continue;
|
199 |
|
200 |
if (filter == null) { |
201 |
this.feature=feature;
|
202 |
return true; |
203 |
|
204 |
} else {
|
205 |
if (filter.evaluate(feature)){
|
206 |
this.feature=feature;
|
207 |
return true; |
208 |
}else{
|
209 |
continue;
|
210 |
} |
211 |
} |
212 |
} |
213 |
} |
214 |
|
215 |
public Object next() { |
216 |
checkModified(); |
217 |
if (!nextChecked){
|
218 |
hasNext(); |
219 |
} |
220 |
if (this.feature == null) |
221 |
throw new NoSuchElementException(); |
222 |
nextChecked=false;
|
223 |
Feature feature = this.feature;
|
224 |
this.feature = null; |
225 |
return feature;
|
226 |
} |
227 |
|
228 |
public void remove() { |
229 |
throw new UnsupportedOperationException(); |
230 |
} |
231 |
|
232 |
} |
233 |
|
234 |
|
235 |
public void dispose() { |
236 |
this.observable.deleteObservers();
|
237 |
this.observable = null; |
238 |
this.featureIDs.clear();
|
239 |
this.featureIDs = null; |
240 |
this.featureType = null; |
241 |
this.store = null; |
242 |
this.filter = null; |
243 |
this.featureManager = null; |
244 |
; |
245 |
} |
246 |
|
247 |
} |