svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.api / src / main / java / org / gvsig / fmap / dal / feature / FeatureSet.java @ 47049
History | View | Annotate | Download (16.5 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.fmap.dal.feature; |
25 |
|
26 |
import java.util.List; |
27 |
import javax.json.JsonArray; |
28 |
import javax.json.JsonArrayBuilder; |
29 |
import org.gvsig.expressionevaluator.Expression; |
30 |
import org.gvsig.fmap.dal.DataSet; |
31 |
import org.gvsig.fmap.dal.DataStore; |
32 |
import org.gvsig.fmap.dal.exception.DataException; |
33 |
import static org.gvsig.fmap.dal.feature.DisposableFeatureSetIterable.EMPTY_DISPOSABLE_FEATURE_SET_ITERABLE; |
34 |
import org.gvsig.json.Json; |
35 |
import org.gvsig.tools.dispose.DisposableIterator; |
36 |
import static org.gvsig.tools.dispose.DisposableIterator.EMPTY_DISPOSABLE_ITERATOR; |
37 |
import org.gvsig.tools.dynobject.DynObject; |
38 |
import org.gvsig.tools.dynobject.DynObjectSet; |
39 |
import static org.gvsig.tools.dynobject.DynObjectSet.EMPTY_DYNOBJECTSET; |
40 |
import org.gvsig.tools.exception.BaseException; |
41 |
import org.gvsig.tools.util.IsEmpty; |
42 |
import org.gvsig.tools.util.Size; |
43 |
import org.gvsig.tools.util.Size64; |
44 |
import org.gvsig.tools.visitor.IndexedVisitable; |
45 |
import org.gvsig.tools.visitor.Visitor; |
46 |
|
47 |
/**
|
48 |
* A FeatureSet represents a set of {@link Feature}(s). These sets of features
|
49 |
* are typically obtained directly from a {@link FeatureStore}, or through a
|
50 |
* {@link FeatureQuery}.
|
51 |
*
|
52 |
* A FeatureSet may contain subsets of {@link Feature}(s) of different
|
53 |
* {@link FeatureType}(s). It allows iterating and editing the features.
|
54 |
*
|
55 |
* FIXME: Actualizar javadoc
|
56 |
*
|
57 |
* Si el store en el que esta basado el featureset es modificado, se realiza un
|
58 |
* update, insert, delete o se modifican los featuretype de este, el FeatureSet
|
59 |
* quedara invalidado, y cualquier acceso a el provocara que se lance una
|
60 |
* excepcion de tiempo de ejecucion ConcurrentModificationException.
|
61 |
*
|
62 |
* Habria que indicar que invocar al metodo accept del interface visitor
|
63 |
* provocara la excepcion ConcurrentModificationException si el store a sido
|
64 |
* modificado desde otro punto.
|
65 |
*
|
66 |
* Indicar que los metodos insert/delete/update ademas de actuar sobre el set,
|
67 |
* actuan sobre el store en el que este esta basado, pero que no invalidan el
|
68 |
* set sobre el que se ejecutan. No se si esto deberia hacerse mencion en esos
|
69 |
* metodos o en la doc general del featureset.
|
70 |
*
|
71 |
*/
|
72 |
public interface FeatureSet extends DataSet, Size64, Size, IsEmpty, IndexedVisitable, Iterable<Feature> { |
73 |
|
74 |
public static FeatureSet EMPTY_FEATURESET = new FeatureSet() { |
75 |
@Override
|
76 |
public FeatureType getDefaultFeatureType() {
|
77 |
return null; |
78 |
} |
79 |
|
80 |
@Override
|
81 |
public List getFeatureTypes() { |
82 |
return null; |
83 |
} |
84 |
|
85 |
@Override
|
86 |
public long getSize() throws DataException { |
87 |
return 0; |
88 |
} |
89 |
|
90 |
@Override
|
91 |
public DisposableIterator iterator(long index) throws DataException { |
92 |
return EMPTY_DISPOSABLE_ITERATOR;
|
93 |
} |
94 |
|
95 |
@Override
|
96 |
public DisposableIterator iterator(long index, long elements) throws DataException { |
97 |
return EMPTY_DISPOSABLE_ITERATOR;
|
98 |
} |
99 |
|
100 |
@Override
|
101 |
public DisposableFeatureSetIterable iterable() {
|
102 |
return EMPTY_DISPOSABLE_FEATURE_SET_ITERABLE;
|
103 |
} |
104 |
|
105 |
@Override
|
106 |
public DisposableFeatureSetIterable iterable(boolean disposeFeatureSet) { |
107 |
return EMPTY_DISPOSABLE_FEATURE_SET_ITERABLE;
|
108 |
} |
109 |
|
110 |
@Override
|
111 |
public DisposableIterator fastIterator() throws DataException { |
112 |
return EMPTY_DISPOSABLE_ITERATOR;
|
113 |
} |
114 |
|
115 |
@Override
|
116 |
public DisposableIterator fastIterator(long index) throws DataException { |
117 |
return EMPTY_DISPOSABLE_ITERATOR;
|
118 |
} |
119 |
|
120 |
@Override
|
121 |
public DisposableIterator fastIterator(long index, long elemets) throws DataException { |
122 |
return EMPTY_DISPOSABLE_ITERATOR;
|
123 |
} |
124 |
|
125 |
@Override
|
126 |
public Feature first() {
|
127 |
return null; |
128 |
} |
129 |
|
130 |
@Override
|
131 |
public void update(EditableFeature feature) throws DataException { |
132 |
} |
133 |
|
134 |
@Override
|
135 |
public void commitChanges() throws DataException { |
136 |
} |
137 |
|
138 |
@Override
|
139 |
public void delete(Feature feature) throws DataException { |
140 |
} |
141 |
|
142 |
@Override
|
143 |
public void insert(EditableFeature feature) throws DataException { |
144 |
} |
145 |
|
146 |
@Override
|
147 |
public DynObjectSet getDynObjectSet() {
|
148 |
return EMPTY_DYNOBJECTSET;
|
149 |
} |
150 |
|
151 |
@Override
|
152 |
public DynObjectSet getDynObjectSet(boolean fast) { |
153 |
return EMPTY_DYNOBJECTSET;
|
154 |
} |
155 |
|
156 |
@Override
|
157 |
public void accept(Visitor visitor, long firstValueIndex) throws BaseException { |
158 |
} |
159 |
|
160 |
@Override
|
161 |
public void accept(Visitor visitor, long firstValueIndex, long elements) throws BaseException { |
162 |
} |
163 |
|
164 |
@Override
|
165 |
public FeatureStore getFeatureStore() {
|
166 |
return null; |
167 |
} |
168 |
|
169 |
@Override
|
170 |
public JsonArray toJSON() {
|
171 |
return toJson();
|
172 |
} |
173 |
|
174 |
@Override
|
175 |
public JsonArray toJson() {
|
176 |
return Json.createArrayBuilder().build();
|
177 |
} |
178 |
|
179 |
@Override
|
180 |
public JsonArrayBuilder toJsonBuilder() {
|
181 |
return Json.createArrayBuilder();
|
182 |
} |
183 |
|
184 |
@Override
|
185 |
public boolean isFromStore(DataStore store) { |
186 |
return false; |
187 |
} |
188 |
|
189 |
@Override
|
190 |
public void accept(Visitor visitor) throws BaseException { |
191 |
} |
192 |
|
193 |
@Override
|
194 |
public void dispose() { |
195 |
// Do nothing
|
196 |
} |
197 |
|
198 |
@Override
|
199 |
public long size64() { |
200 |
return 0; |
201 |
} |
202 |
|
203 |
@Override
|
204 |
public int size() { |
205 |
return 0; |
206 |
} |
207 |
|
208 |
@Override
|
209 |
public boolean isEmpty() { |
210 |
return true; |
211 |
} |
212 |
|
213 |
@Override
|
214 |
public DisposableIterator<Feature> iterator() {
|
215 |
return EMPTY_DISPOSABLE_ITERATOR;
|
216 |
} |
217 |
|
218 |
@Override
|
219 |
public Expression makeFilter(int maxfeatures) { |
220 |
return null; |
221 |
} |
222 |
|
223 |
}; |
224 |
|
225 |
/**
|
226 |
* Returns the default {@link FeatureType} of this FeatureSet.
|
227 |
*
|
228 |
* @return default {@link FeatureType} in this FeatureSet.
|
229 |
*/
|
230 |
public FeatureType getDefaultFeatureType();
|
231 |
|
232 |
/**
|
233 |
* Returns a list of the {@link FeatureType}(s) in this FeatureSet.
|
234 |
*
|
235 |
* @return list of the {@link FeatureType}(s) in this FeatureSet.
|
236 |
*/
|
237 |
public List getFeatureTypes(); |
238 |
|
239 |
/**
|
240 |
* Returns the number of {@link Feature}(s) contained in this FeatureSet.
|
241 |
*
|
242 |
* The value returned by this method won't be accurate when the FeatureStore
|
243 |
* is being edited and this set's features are modified, added or deleted.
|
244 |
*
|
245 |
* @return number of {@link Feature}(s) contained in this FeatureSet.
|
246 |
*
|
247 |
* @throws DataException
|
248 |
*/
|
249 |
public long getSize() throws DataException; |
250 |
|
251 |
/**
|
252 |
* Returns an iterator over the elements in this collection, in the order
|
253 |
* (if any) defined when the collection was obtained.
|
254 |
*
|
255 |
* The iterator starts at the specified position in this collection. The
|
256 |
* specified index indicates the first element that would be returned by an
|
257 |
* initial call to the <tt>next</tt> method. An initial call to the
|
258 |
* <tt>previous</tt> method would return the element with the specified
|
259 |
* index minus one.
|
260 |
*
|
261 |
* <p>
|
262 |
* <em>
|
263 |
* <strong>NOTE:</strong> if you use this method to get the iterator, you
|
264 |
* must get sure the iterator is disposed (@see
|
265 |
* {@link DisposableIterator#dispose()}) in any case, even if an error
|
266 |
* occurs while getting the data. It is recommended to use the
|
267 |
* <code>accept</code> methods instead, which handle everything for you.
|
268 |
* Take into account the accept methods may use a fast iterator to get the
|
269 |
* features.
|
270 |
* </em>
|
271 |
* </p>
|
272 |
*
|
273 |
* @see #accept(org.gvsig.tools.visitor.Visitor)
|
274 |
* @see #accept(org.gvsig.tools.visitor.Visitor, long)
|
275 |
* @see #fastIterator()
|
276 |
* @see #fastIterator(long)
|
277 |
*
|
278 |
* @param index index of first element to be returned from the iterator (by
|
279 |
* a call to the <tt>next</tt> method).
|
280 |
* @return an iterator of the elements in this collection (in proper
|
281 |
* sequence), starting at the specified position in the collection.
|
282 |
* @throws DataException if the index is out of range (index < 0 || index
|
283 |
* > size()).
|
284 |
* @deprecated use {@link #fastIterator(long)} instead
|
285 |
*/
|
286 |
DisposableIterator iterator(long index) throws DataException; |
287 |
|
288 |
DisposableIterator iterator(long index, long elements) throws DataException; |
289 |
|
290 |
/**
|
291 |
* Returns an iterator over the elements in this collection, in the order
|
292 |
* (if any) defined when the collection was obtained.
|
293 |
*
|
294 |
* @see #accept(org.gvsig.tools.visitor.Visitor)
|
295 |
* @see #accept(org.gvsig.tools.visitor.Visitor, long)
|
296 |
* @see #fastIterator()
|
297 |
* @see #fastIterator(long)
|
298 |
*
|
299 |
* @return an iterator of the elements in this collection (in proper
|
300 |
* sequence).
|
301 |
*
|
302 |
* @deprecated use fastiterator. In next versions the signature of this
|
303 |
* method will be changed to "Iterator<Feature> iterator()".
|
304 |
*/
|
305 |
@Override
|
306 |
DisposableIterator iterator(); |
307 |
|
308 |
DisposableFeatureSetIterable iterable(); |
309 |
|
310 |
DisposableFeatureSetIterable iterable(boolean disposeFeatureSet);
|
311 |
|
312 |
/**
|
313 |
* Returns a fast iterator over this set.
|
314 |
* <p>
|
315 |
* Fast in this case means that each of the elements returned may be a
|
316 |
* reused or pooled object instance, so don't use it to be stored in any
|
317 |
* way.
|
318 |
* </p>
|
319 |
* <p>
|
320 |
* If you need to store one of the {@link Feature} of the iterator, use the
|
321 |
* {@link Feature#getCopy()} to create a clone of the object.
|
322 |
* </p>
|
323 |
*
|
324 |
* <p>
|
325 |
* <em>
|
326 |
* <strong>NOTE:</strong> if you use this method to get the iterator, you
|
327 |
* must get sure the iterator is disposed (@see
|
328 |
* {@link DisposableIterator#dispose()}) in any case, even if an error
|
329 |
* occurs while getting the data. It is recommended to use the
|
330 |
* <code>accept</code> methods instead, which handle everything for you.
|
331 |
* Take into account the accept methods may use a fast iterator to get the
|
332 |
* features.
|
333 |
* </em>
|
334 |
* </p>
|
335 |
*
|
336 |
* @see #accept(org.gvsig.tools.visitor.Visitor)
|
337 |
* @see #accept(org.gvsig.tools.visitor.Visitor, long)
|
338 |
*
|
339 |
* @return an iterator over this set.
|
340 |
*
|
341 |
* @throws DataException
|
342 |
*/
|
343 |
public DisposableIterator fastIterator() throws DataException; |
344 |
|
345 |
/**
|
346 |
* Returns a fast iterator over this set, starting from the given index.
|
347 |
* <p>
|
348 |
* Fast in this case means that each of the elements returned may be a
|
349 |
* reused or pooled object instance, so don't use it to be stored in any
|
350 |
* way.
|
351 |
* </p>
|
352 |
* <p>
|
353 |
* If you need to store one of the {@link Feature} of the iterator, use the
|
354 |
* {@link Feature#getCopy()} to create a clone of the object.
|
355 |
* </p>
|
356 |
*
|
357 |
* <p>
|
358 |
* <em>
|
359 |
* <strong>NOTE:</strong> if you use this method to get the iterator, you
|
360 |
* must get sure the iterator is disposed (@see
|
361 |
* {@link DisposableIterator#dispose()}) in any case, even if an error
|
362 |
* occurs while getting the data. It is recommended to use the
|
363 |
* <code>accept</code> methods instead, which handle everything for you.
|
364 |
* Take into account the accept methods may use a fast iterator to get the
|
365 |
* features.
|
366 |
* </em>
|
367 |
* </p>
|
368 |
*
|
369 |
* @see #accept(org.gvsig.tools.visitor.Visitor)
|
370 |
* @see #accept(org.gvsig.tools.visitor.Visitor, long)
|
371 |
*
|
372 |
* @param index position in which the iterator is initially located.
|
373 |
*
|
374 |
* @return an iterator initially located at the position indicated by the
|
375 |
* given index
|
376 |
*
|
377 |
* @throws DataException
|
378 |
*/
|
379 |
public DisposableIterator fastIterator(long index) throws DataException; |
380 |
|
381 |
public DisposableIterator fastIterator(long index, long elemets) throws DataException; |
382 |
|
383 |
/**
|
384 |
* Return the first feature of the set. If the set is empty return null.
|
385 |
*
|
386 |
* This not is a good method to determine if the set is empty. Use isEmpty
|
387 |
* instead.
|
388 |
*
|
389 |
* This is a utility method that call iterator and retrieve the first
|
390 |
* feature of the iterator.
|
391 |
*
|
392 |
* @return the first fearure of the set or null.
|
393 |
*/
|
394 |
public Feature first();
|
395 |
|
396 |
/**
|
397 |
* Updates a {@link Feature} with the given {@link EditableFeature}.<br>
|
398 |
*
|
399 |
* Any {@link DisposableIterator} from this store that was still in use can
|
400 |
* will not reflect this change.
|
401 |
*
|
402 |
* @param feature an instance of {@link EditableFeature} with which to
|
403 |
* update the associated {@link Feature}.
|
404 |
*
|
405 |
* @throws DataException
|
406 |
*/
|
407 |
public void update(EditableFeature feature) throws DataException; |
408 |
|
409 |
public void commitChanges() throws DataException; |
410 |
|
411 |
/**
|
412 |
* Deletes a {@link Feature} from this FeatureSet.<br>
|
413 |
*
|
414 |
* Any {@link DisposableIterator} from this store that was still in use will
|
415 |
* be
|
416 |
* <i>unsafe</i>. Use {@link DisposableIterator#remove()} instead.
|
417 |
*
|
418 |
* @param feature the {@link Feature} to delete.
|
419 |
*
|
420 |
* @throws DataException
|
421 |
*/
|
422 |
public void delete(Feature feature) throws DataException; |
423 |
|
424 |
/**
|
425 |
* Inserts a new feature in this set. It needs to be an instance of
|
426 |
* {@link EditableFeature} as it has not been stored yet.<br>
|
427 |
*
|
428 |
* Any {@link DisposableIterator} from this store that was still in use can
|
429 |
* will not reflect this change.
|
430 |
*
|
431 |
* @param feature the {@link EditableFeature} to insert.
|
432 |
*
|
433 |
* @throws DataException
|
434 |
*/
|
435 |
public void insert(EditableFeature feature) throws DataException; |
436 |
|
437 |
/**
|
438 |
* Returns a {@link DynObjectSet} of the contents of this set. Defaults to
|
439 |
* fast iteration.
|
440 |
*
|
441 |
* @return a {@link DynObjectSet}
|
442 |
*/
|
443 |
public DynObjectSet getDynObjectSet();
|
444 |
|
445 |
/**
|
446 |
* Returns a {@link DynObjectSet} of the contents of this set.
|
447 |
*
|
448 |
* @param fast if the set will be able to be iterated in a fast way, by
|
449 |
* reusing the {@link DynObject} instance for each {@link Feature} instance.
|
450 |
* @return a {@link DynObjectSet}
|
451 |
*/
|
452 |
public DynObjectSet getDynObjectSet(boolean fast); |
453 |
|
454 |
/**
|
455 |
* Provides each value of this Store to the provided {@link Visitor},
|
456 |
* beginning from the provided index position. The values received through
|
457 |
* the {@link Visitor#visit(Object)} method may be transient, reused or
|
458 |
* externally modifiable, so they can't be used to be stored in any external
|
459 |
* form out of the visit method.
|
460 |
*
|
461 |
* If you need to store any of the values out of the
|
462 |
* {@link Visitor#visit(Object)} method execution, create a copy or clone
|
463 |
* the received value in order to be stored.
|
464 |
*
|
465 |
* @param visitor the visitor to apply to each value.
|
466 |
* @param firstValueIndex index of first element to be visited by the
|
467 |
* {@link Visitor}
|
468 |
* @exception BaseException if there is an error while performing the visit
|
469 |
*/
|
470 |
@Override
|
471 |
void accept(Visitor visitor, long firstValueIndex) throws BaseException; |
472 |
|
473 |
void accept(Visitor visitor, long firstValueIndex, long elements) throws BaseException; |
474 |
|
475 |
public FeatureStore getFeatureStore();
|
476 |
|
477 |
@Deprecated
|
478 |
public JsonArray toJSON();
|
479 |
|
480 |
public JsonArray toJson();
|
481 |
|
482 |
public JsonArrayBuilder toJsonBuilder();
|
483 |
|
484 |
public Expression makeFilter(int maxfeatures); |
485 |
|
486 |
} |