Revision 19448 trunk/libraries/libDataSourceBaseDrivers/src/org/gvsig/data/datastores/vectorial/driver/dbf/DBFFeatureCollection.java
DBFFeatureCollection.java | ||
---|---|---|
4 | 4 |
import java.util.Collection; |
5 | 5 |
import java.util.ConcurrentModificationException; |
6 | 6 |
import java.util.Iterator; |
7 |
import java.util.NoSuchElementException; |
|
7 | 8 |
|
8 |
import jj2000.j2k.NoNextElementException; |
|
9 |
|
|
10 | 9 |
import org.gvsig.data.ComplexObservable; |
11 | 10 |
import org.gvsig.data.IObservable; |
11 |
import org.gvsig.data.datastores.vectorial.driver.AbstractDriver; |
|
12 | 12 |
import org.gvsig.data.vectorial.IFeature; |
13 | 13 |
import org.gvsig.data.vectorial.IFeatureCollection; |
14 | 14 |
import org.gvsig.data.vectorial.IFeatureID; |
15 |
import org.gvsig.data.vectorial.IFeatureStoreNotification; |
|
15 | 16 |
import org.gvsig.data.vectorial.IFeatureType; |
16 | 17 |
import org.gvsig.data.vectorial.expansionadapter.FeatureManager; |
17 | 18 |
import org.gvsig.data.vectorial.filter.FeatureFilterParser; |
... | ... | |
21 | 22 |
protected ArrayList featureIDs=new ArrayList();//<IFeatureID> |
22 | 23 |
protected IFeatureType featureType; |
23 | 24 |
protected String filter; |
24 |
protected String order; |
|
25 |
protected DBFDriver driver; |
|
25 |
protected AbstractDriver driver; |
|
26 | 26 |
private FeatureFilterParser parser = null; |
27 | 27 |
protected FeatureManager featureManager; |
28 | 28 |
protected long driverFeatureCount=0; |
29 | 29 |
protected boolean modified=false; |
30 | 30 |
|
31 |
public DBFFeatureCollection(FeatureManager fm,DBFDriver driver,IFeatureType type, String filter, String order) {
|
|
31 |
public DBFFeatureCollection(FeatureManager fm,DBFDriver driver,IFeatureType type, String filter) { |
|
32 | 32 |
this.featureManager=fm; |
33 | 33 |
this.driver=driver; |
34 | 34 |
driverFeatureCount=driver.getFeatureCount(); |
35 | 35 |
this.featureType=type; |
36 | 36 |
this.filter=filter; |
37 |
if (filter!=null) |
|
38 |
parseExpression(filter);
|
|
39 |
this.order=order; |
|
37 |
if (this.filter!=null)
|
|
38 |
parser = new FeatureFilterParser(filter,this.featureType);
|
|
39 |
|
|
40 | 40 |
} |
41 |
protected void parseExpression(String filter){ |
|
42 |
parser = new FeatureFilterParser(filter,this.featureType); |
|
43 |
} |
|
44 | 41 |
|
45 |
protected boolean evaluate(IFeature feature) throws Exception{ |
|
46 |
if (filter==null){ |
|
47 |
return true; |
|
48 |
} |
|
49 |
return parser.match(feature); |
|
42 |
protected void checkModified(){ |
|
43 |
if (modified) |
|
44 |
throw new ConcurrentModificationException("FeatureCollection modified"); |
|
50 | 45 |
} |
51 | 46 |
|
52 | 47 |
public int size() { |
53 | 48 |
if (filter==null){ |
54 | 49 |
return (int)(driverFeatureCount+featureManager.getNum()); |
55 | 50 |
} |
56 |
DBFIterator iterator= (DBFIterator)iterator();
|
|
51 |
Iterator iterator= this.iterator();
|
|
57 | 52 |
int size=0; |
58 | 53 |
while(iterator.hasNext()){ |
59 | 54 |
size++; |
60 | 55 |
} |
61 | 56 |
return size; |
62 |
// return featureIDs.size(); |
|
63 | 57 |
} |
64 | 58 |
|
65 | 59 |
public boolean isEmpty() { |
66 | 60 |
return (size()==0); |
67 |
// return featureIDs.isEmpty(); |
|
68 | 61 |
} |
69 | 62 |
|
70 | 63 |
public boolean contains(Object o) { |
71 |
DBFIterator iterator= (DBFIterator)iterator();
|
|
64 |
Iterator iterator= this.iterator();
|
|
72 | 65 |
while(iterator.hasNext()){ |
73 | 66 |
IFeature feature=(IFeature)iterator.next(); |
74 | 67 |
if (feature.getID().equals(((IFeature)o).getID())){ |
... | ... | |
85 | 78 |
|
86 | 79 |
public Object[] toArray() { |
87 | 80 |
ArrayList features= new ArrayList(); |
88 |
DBFIterator iterator= (DBFIterator)iterator();
|
|
81 |
Iterator iterator= this.iterator();
|
|
89 | 82 |
while(iterator.hasNext()){ |
90 | 83 |
IFeature feature=(IFeature)iterator.next(); |
91 | 84 |
features.add(feature); |
92 | 85 |
} |
93 | 86 |
return features.toArray(); |
94 |
|
|
95 |
// return featureIDs.toArray(); |
|
96 | 87 |
} |
97 | 88 |
|
98 | 89 |
public Object[] toArray(Object[] a) { |
99 | 90 |
ArrayList features= new ArrayList(); |
100 |
DBFIterator iterator= (DBFIterator)iterator();
|
|
91 |
Iterator iterator= this.iterator();
|
|
101 | 92 |
while(iterator.hasNext()){ |
102 | 93 |
IFeature feature=(IFeature)iterator.next(); |
103 | 94 |
features.add(feature); |
104 | 95 |
} |
105 | 96 |
return features.toArray(a); |
106 |
// return featureIDs.toArray(a); |
|
107 | 97 |
} |
108 | 98 |
|
109 | 99 |
public boolean add(Object o) { |
110 |
return false; |
|
111 |
// return featureIDs.add((IFeatureID)o); |
|
100 |
throw new UnsupportedOperationException(); |
|
112 | 101 |
} |
113 | 102 |
|
114 | 103 |
public boolean remove(Object o) { |
115 |
return false; |
|
116 |
// return featureIDs.remove(o); |
|
104 |
throw new UnsupportedOperationException(); |
|
117 | 105 |
} |
118 | 106 |
|
119 | 107 |
public boolean containsAll(Collection c) { |
120 |
return false; |
|
121 |
// return featureIDs.containsAll(c); |
|
108 |
Iterator iter = c.iterator(); |
|
109 |
while (iter.hasNext()){ |
|
110 |
if (!this.contains(iter.next())){ |
|
111 |
return false; |
|
112 |
} |
|
113 |
} |
|
114 |
return true; |
|
115 |
|
|
122 | 116 |
} |
123 | 117 |
|
124 | 118 |
public boolean addAll(Collection c) { |
125 |
return false; |
|
126 |
// return featureIDs.addAll(c); |
|
119 |
throw new UnsupportedOperationException(); |
|
127 | 120 |
} |
128 | 121 |
|
129 | 122 |
public boolean removeAll(Collection c) { |
130 |
return false; |
|
131 |
// return featureIDs.removeAll(c); |
|
123 |
throw new UnsupportedOperationException(); |
|
132 | 124 |
} |
133 | 125 |
|
134 | 126 |
public boolean retainAll(Collection c) { |
135 |
return false; |
|
136 |
// return featureIDs.retainAll(c); |
|
127 |
throw new UnsupportedOperationException(); |
|
137 | 128 |
} |
138 | 129 |
|
139 | 130 |
public void clear() { |
140 |
// featureIDs.clear();
|
|
131 |
throw new UnsupportedOperationException();
|
|
141 | 132 |
} |
142 | 133 |
|
143 | 134 |
public void update(IObservable obsevable, Object notification) { |
144 |
modified=true; |
|
135 |
if (modified){ |
|
136 |
return; |
|
137 |
} |
|
138 |
String type = ((IFeatureStoreNotification)notification).getType(); |
|
139 |
if (type.equalsIgnoreCase(IFeatureStoreNotification.AFTER_INSERT) || |
|
140 |
type.equalsIgnoreCase(IFeatureStoreNotification.AFTER_DELETE) || |
|
141 |
type.equalsIgnoreCase(IFeatureStoreNotification.AFTER_UPDATE)){ |
|
142 |
modified=true; |
|
143 |
} |
|
145 | 144 |
|
145 |
|
|
146 | 146 |
} |
147 |
private class DBFIterator implements Iterator{
|
|
148 |
private long position=0;
|
|
149 |
private boolean nextChecket=false;
|
|
147 |
protected class DBFIterator implements Iterator{
|
|
148 |
protected long position=0;
|
|
149 |
private boolean nextChecked=false;
|
|
150 | 150 |
private IFeature feature; |
151 |
|
|
151 | 152 |
public DBFIterator(){ |
152 | 153 |
position=0; |
153 | 154 |
} |
155 |
|
|
156 |
protected void checkModified(){ |
|
157 |
if (modified) |
|
158 |
throw new ConcurrentModificationException("FeatureCollection modified"); |
|
159 |
} |
|
160 |
|
|
161 |
protected IFeatureID createCurrectDriverFeatureID(){ |
|
162 |
if (position<driverFeatureCount){ |
|
163 |
return new DBFFeatureID((DBFDriver)driver,position); |
|
164 |
} else { |
|
165 |
return null; |
|
166 |
} |
|
167 |
} |
|
168 |
|
|
154 | 169 |
public boolean hasNext(){ |
170 |
checkModified(); |
|
171 |
|
|
155 | 172 |
IFeature feature=null; |
156 |
if (nextChecket){
|
|
173 |
if (nextChecked){
|
|
157 | 174 |
return feature != null; |
158 | 175 |
} |
159 |
nextChecket=true;
|
|
176 |
nextChecked=true;
|
|
160 | 177 |
while (true){ |
161 | 178 |
if (position<driverFeatureCount){ |
162 |
IFeatureID featureID=new DBFFeatureID(driver,position);
|
|
179 |
IFeatureID featureID = this.createCurrectDriverFeatureID();
|
|
163 | 180 |
feature=featureID.getFeature(featureType); |
164 | 181 |
}else if ((position-driverFeatureCount)<featureManager.getNum()){ |
165 | 182 |
int pos=(int)(position-driverFeatureCount); |
... | ... | |
174 | 191 |
if(featureManager.isDeleted(feature)) |
175 | 192 |
continue; |
176 | 193 |
|
177 |
try { |
|
178 |
if (evaluate(feature)){ |
|
179 |
this.feature=feature; |
|
180 |
return true; |
|
181 |
}else{ |
|
182 |
continue; |
|
194 |
if (filter == null) { |
|
195 |
this.feature=feature; |
|
196 |
return true; |
|
197 |
|
|
198 |
} else { |
|
199 |
try { |
|
200 |
if (parser.match(feature)){ |
|
201 |
this.feature=feature; |
|
202 |
return true; |
|
203 |
}else{ |
|
204 |
continue; |
|
205 |
} |
|
206 |
} catch (Exception e) { |
|
207 |
// TODO Auto-generated catch block |
|
208 |
e.printStackTrace(); |
|
183 | 209 |
} |
184 |
} catch (Exception e) { |
|
185 |
// TODO Auto-generated catch block |
|
186 |
e.printStackTrace(); |
|
187 | 210 |
} |
188 | 211 |
} |
189 | 212 |
} |
190 | 213 |
|
191 | 214 |
public Object next() { |
192 |
// IFeature feature=((IFeatureID)featureIDs.get(position)).getFeature(featureType); |
|
193 |
// position++; |
|
194 |
if (!nextChecket){ |
|
215 |
checkModified(); |
|
216 |
if (!nextChecked){ |
|
195 | 217 |
hasNext(); |
196 | 218 |
} |
197 |
if (modified) |
|
198 |
throw new ConcurrentModificationException("FeatureCollection modified"); |
|
199 | 219 |
if (feature == null) |
200 |
throw new NoNextElementException();
|
|
201 |
nextChecket=false;
|
|
220 |
throw new NoSuchElementException();
|
|
221 |
nextChecked=false;
|
|
202 | 222 |
return feature; |
203 | 223 |
} |
204 | 224 |
|
205 | 225 |
public void remove() { |
206 |
// featureIDs.remove(position);
|
|
226 |
throw new UnsupportedOperationException();
|
|
207 | 227 |
} |
208 | 228 |
|
209 | 229 |
} |
Also available in: Unified diff