Statistics
| Revision:

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 40559 jjdelcerro
/**
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 40435 jjdelcerro
package org.gvsig.fmap.dal.feature;
25
26
import java.util.List;
27 44655 jjdelcerro
import javax.json.JsonArray;
28 45696 jjdelcerro
import javax.json.JsonArrayBuilder;
29 47049 jjdelcerro
import org.gvsig.expressionevaluator.Expression;
30 40435 jjdelcerro
import org.gvsig.fmap.dal.DataSet;
31 47049 jjdelcerro
import org.gvsig.fmap.dal.DataStore;
32 40435 jjdelcerro
import org.gvsig.fmap.dal.exception.DataException;
33 47049 jjdelcerro
import static org.gvsig.fmap.dal.feature.DisposableFeatureSetIterable.EMPTY_DISPOSABLE_FEATURE_SET_ITERABLE;
34
import org.gvsig.json.Json;
35 40435 jjdelcerro
import org.gvsig.tools.dispose.DisposableIterator;
36 47049 jjdelcerro
import static org.gvsig.tools.dispose.DisposableIterator.EMPTY_DISPOSABLE_ITERATOR;
37 40435 jjdelcerro
import org.gvsig.tools.dynobject.DynObject;
38
import org.gvsig.tools.dynobject.DynObjectSet;
39 47049 jjdelcerro
import static org.gvsig.tools.dynobject.DynObjectSet.EMPTY_DYNOBJECTSET;
40 40435 jjdelcerro
import org.gvsig.tools.exception.BaseException;
41 45425 jjdelcerro
import org.gvsig.tools.util.IsEmpty;
42 44390 jjdelcerro
import org.gvsig.tools.util.Size;
43
import org.gvsig.tools.util.Size64;
44 40435 jjdelcerro
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 45541 fdiaz
 *
52 40435 jjdelcerro
 * A FeatureSet may contain subsets of {@link Feature}(s) of different
53
 * {@link FeatureType}(s). It allows iterating and editing the features.
54 45541 fdiaz
 *
55 40435 jjdelcerro
 * FIXME: Actualizar javadoc
56 45541 fdiaz
 *
57 40435 jjdelcerro
 * 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 45541 fdiaz
 *
62 40435 jjdelcerro
 * 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 45541 fdiaz
 *
66 40435 jjdelcerro
 * 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 45541 fdiaz
 *
71 40435 jjdelcerro
 */
72 45425 jjdelcerro
public interface FeatureSet extends DataSet, Size64, Size, IsEmpty, IndexedVisitable, Iterable<Feature> {
73 45541 fdiaz
74 47049 jjdelcerro
    public static FeatureSet EMPTY_FEATURESET = new FeatureSet() {
75
        @Override
76
        public FeatureType getDefaultFeatureType() {
77
            return null;
78
        }
79 46672 fdiaz
80 47049 jjdelcerro
        @Override
81
        public List getFeatureTypes() {
82
            return null;
83
        }
84 46672 fdiaz
85 47049 jjdelcerro
        @Override
86
        public long getSize() throws DataException {
87
            return 0;
88
        }
89 46672 fdiaz
90 47049 jjdelcerro
        @Override
91
        public DisposableIterator iterator(long index) throws DataException {
92
            return EMPTY_DISPOSABLE_ITERATOR;
93
        }
94 46672 fdiaz
95 47049 jjdelcerro
        @Override
96
        public DisposableIterator iterator(long index, long elements) throws DataException {
97
            return EMPTY_DISPOSABLE_ITERATOR;
98
        }
99 46672 fdiaz
100 47049 jjdelcerro
        @Override
101
        public DisposableFeatureSetIterable iterable() {
102
            return EMPTY_DISPOSABLE_FEATURE_SET_ITERABLE;
103
        }
104 46672 fdiaz
105 47049 jjdelcerro
        @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 46672 fdiaz
223 47049 jjdelcerro
    };
224
225 45541 fdiaz
    /**
226
     * Returns the default {@link FeatureType} of this FeatureSet.
227
     *
228
     * @return default {@link FeatureType} in this FeatureSet.
229
     */
230
    public FeatureType getDefaultFeatureType();
231 40435 jjdelcerro
232 45541 fdiaz
    /**
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 40435 jjdelcerro
239 45541 fdiaz
    /**
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 40435 jjdelcerro
    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 45541 fdiaz
     *
255 40435 jjdelcerro
     * 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 45541 fdiaz
     *
261 40435 jjdelcerro
     * <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 45541 fdiaz
     * {@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 40435 jjdelcerro
     * </em>
271
     * </p>
272 45541 fdiaz
     *
273 40435 jjdelcerro
     * @see #accept(org.gvsig.tools.visitor.Visitor)
274
     * @see #accept(org.gvsig.tools.visitor.Visitor, long)
275
     * @see #fastIterator()
276
     * @see #fastIterator(long)
277 45541 fdiaz
     *
278
     * @param index index of first element to be returned from the iterator (by
279
     * a call to the <tt>next</tt> method).
280 40435 jjdelcerro
     * @return an iterator of the elements in this collection (in proper
281 45541 fdiaz
     * sequence), starting at the specified position in the collection.
282
     * @throws DataException if the index is out of range (index &lt; 0 || index
283
     * &gt; size()).
284 40435 jjdelcerro
     * @deprecated use {@link #fastIterator(long)} instead
285
     */
286 45541 fdiaz
    DisposableIterator iterator(long index) throws DataException;
287 40435 jjdelcerro
288 43358 jjdelcerro
    DisposableIterator iterator(long index, long elements) throws DataException;
289
290 40435 jjdelcerro
    /**
291
     * Returns an iterator over the elements in this collection, in the order
292
     * (if any) defined when the collection was obtained.
293 45541 fdiaz
     *
294 40435 jjdelcerro
     * @see #accept(org.gvsig.tools.visitor.Visitor)
295
     * @see #accept(org.gvsig.tools.visitor.Visitor, long)
296
     * @see #fastIterator()
297
     * @see #fastIterator(long)
298 45541 fdiaz
     *
299 40435 jjdelcerro
     * @return an iterator of the elements in this collection (in proper
300 45541 fdiaz
     * sequence).
301
     *
302 42535 jjdelcerro
     * @deprecated use fastiterator. In next versions the signature of this
303 43358 jjdelcerro
     * method will be changed to "Iterator&lt;Feature&gt; iterator()".
304 40435 jjdelcerro
     */
305 45541 fdiaz
    @Override
306
    DisposableIterator iterator();
307 40435 jjdelcerro
308 45541 fdiaz
    DisposableFeatureSetIterable iterable();
309
310
    DisposableFeatureSetIterable iterable(boolean disposeFeatureSet);
311
312 40435 jjdelcerro
    /**
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 45541 fdiaz
     *
324 40435 jjdelcerro
     * <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 45541 fdiaz
     * {@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 40435 jjdelcerro
     * </em>
334
     * </p>
335 45541 fdiaz
     *
336 40435 jjdelcerro
     * @see #accept(org.gvsig.tools.visitor.Visitor)
337
     * @see #accept(org.gvsig.tools.visitor.Visitor, long)
338 45541 fdiaz
     *
339 40435 jjdelcerro
     * @return an iterator over this set.
340 45541 fdiaz
     *
341 40435 jjdelcerro
     * @throws DataException
342
     */
343 45541 fdiaz
    public DisposableIterator fastIterator() throws DataException;
344 40435 jjdelcerro
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 45541 fdiaz
     *
357 40435 jjdelcerro
     * <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 45541 fdiaz
     * {@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 40435 jjdelcerro
     * </em>
367
     * </p>
368 45541 fdiaz
     *
369 40435 jjdelcerro
     * @see #accept(org.gvsig.tools.visitor.Visitor)
370
     * @see #accept(org.gvsig.tools.visitor.Visitor, long)
371 45541 fdiaz
     *
372
     * @param index position in which the iterator is initially located.
373
     *
374 40435 jjdelcerro
     * @return an iterator initially located at the position indicated by the
375 45541 fdiaz
     * given index
376
     *
377 40435 jjdelcerro
     * @throws DataException
378
     */
379 43987 jjdelcerro
    public DisposableIterator fastIterator(long index) throws DataException;
380 40435 jjdelcerro
381 43358 jjdelcerro
    public DisposableIterator fastIterator(long index, long elemets) throws DataException;
382
383 45541 fdiaz
    /**
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 40435 jjdelcerro
396 45541 fdiaz
    /**
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 40435 jjdelcerro
409 45541 fdiaz
    public void commitChanges() throws DataException;
410
411 40435 jjdelcerro
    /**
412 45541 fdiaz
     * 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 40435 jjdelcerro
     * @return a {@link DynObjectSet}
442
     */
443
    public DynObjectSet getDynObjectSet();
444
445
    /**
446
     * Returns a {@link DynObjectSet} of the contents of this set.
447 45541 fdiaz
     *
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 40435 jjdelcerro
     * @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 45541 fdiaz
     * 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 40435 jjdelcerro
     * 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 45541 fdiaz
     *
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 40435 jjdelcerro
     */
470 43358 jjdelcerro
    @Override
471 40435 jjdelcerro
    void accept(Visitor visitor, long firstValueIndex) throws BaseException;
472 43358 jjdelcerro
473
    void accept(Visitor visitor, long firstValueIndex, long elements) throws BaseException;
474 45541 fdiaz
475 44092 omartinez
    public FeatureStore getFeatureStore();
476 45541 fdiaz
477 45696 jjdelcerro
    @Deprecated
478 44655 jjdelcerro
    public JsonArray toJSON();
479 45696 jjdelcerro
480
    public JsonArray toJson();
481
482
    public JsonArrayBuilder toJsonBuilder();
483
484 47049 jjdelcerro
    public Expression makeFilter(int maxfeatures);
485
486 45541 fdiaz
}