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 @ 46672

History | View | Annotate | Download (13.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.Collections;
27
import java.util.Iterator;
28
import java.util.List;
29
import javax.json.JsonArray;
30
import javax.json.JsonArrayBuilder;
31
import org.gvsig.fmap.dal.DataSet;
32
import org.gvsig.fmap.dal.exception.DataException;
33
import org.gvsig.tools.dispose.DisposableIterable;
34
import org.gvsig.tools.dispose.DisposableIterator;
35
import org.gvsig.tools.dynobject.DynObject;
36
import org.gvsig.tools.dynobject.DynObjectSet;
37
import org.gvsig.tools.exception.BaseException;
38
import org.gvsig.tools.util.IsEmpty;
39
import org.gvsig.tools.util.Size;
40
import org.gvsig.tools.util.Size64;
41
import org.gvsig.tools.visitor.IndexedVisitable;
42
import org.gvsig.tools.visitor.Visitor;
43

    
44
/**
45
 * A FeatureSet represents a set of {@link Feature}(s). These sets of features
46
 * are typically obtained directly from a {@link FeatureStore}, or through a
47
 * {@link FeatureQuery}.
48
 *
49
 * A FeatureSet may contain subsets of {@link Feature}(s) of different
50
 * {@link FeatureType}(s). It allows iterating and editing the features.
51
 *
52
 * FIXME: Actualizar javadoc
53
 *
54
 * Si el store en el que esta basado el featureset es modificado, se realiza un
55
 * update, insert, delete o se modifican los featuretype de este, el FeatureSet
56
 * quedara invalidado, y cualquier acceso a el provocara que se lance una
57
 * excepcion de tiempo de ejecucion ConcurrentModificationException.
58
 *
59
 * Habria que indicar que invocar al metodo accept del interface visitor
60
 * provocara la excepcion ConcurrentModificationException si el store a sido
61
 * modificado desde otro punto.
62
 *
63
 * Indicar que los metodos insert/delete/update ademas de actuar sobre el set,
64
 * actuan sobre el store en el que este esta basado, pero que no invalidan el
65
 * set sobre el que se ejecutan. No se si esto deberia hacerse mencion en esos
66
 * metodos o en la doc general del featureset.
67
 *
68
 */
69
public interface FeatureSet extends DataSet, Size64, Size, IsEmpty, IndexedVisitable, Iterable<Feature> {
70

    
71
    public interface DisposableFeatureSetIterable
72
            extends DisposableIterable<Feature>, Iterator<Feature>, Size64, IsEmpty {
73
        
74
        public static DisposableFeatureSetIterable EMPTY_DISPOSABLE_FEATURE_SET_ITERABLE = new DisposableFeatureSetIterable() {
75
            @Override
76
            public FeatureSet getFeatureSet() {
77
                return null;
78
            }
79

    
80
            @Override
81
            public Iterator<Feature> iterator() {
82
                return Collections.EMPTY_LIST.iterator();
83
            }
84

    
85
            @Override
86
            public void dispose() {
87
            }
88

    
89
            @Override
90
            public boolean hasNext() {
91
                return false;
92
            }
93

    
94
            @Override
95
            public Feature next() {
96
                return null;
97
            }
98

    
99
            @Override
100
            public long size64() {
101
                return 0;
102
            }
103

    
104
            @Override
105
            public boolean isEmpty() {
106
                return false;
107
            }
108
        };
109
        
110
        public FeatureSet getFeatureSet();
111
    }
112

    
113
    /**
114
     * Returns the default {@link FeatureType} of this FeatureSet.
115
     *
116
     * @return default {@link FeatureType} in this FeatureSet.
117
     */
118
    public FeatureType getDefaultFeatureType();
119

    
120
    /**
121
     * Returns a list of the {@link FeatureType}(s) in this FeatureSet.
122
     *
123
     * @return list of the {@link FeatureType}(s) in this FeatureSet.
124
     */
125
    public List getFeatureTypes();
126

    
127
    /**
128
     * Returns the number of {@link Feature}(s) contained in this FeatureSet.
129
     *
130
     * The value returned by this method won't be accurate when the FeatureStore
131
     * is being edited and this set's features are modified, added or deleted.
132
     *
133
     * @return number of {@link Feature}(s) contained in this FeatureSet.
134
     *
135
     * @throws DataException
136
     */
137
    public long getSize() throws DataException;
138

    
139
    /**
140
     * Returns an iterator over the elements in this collection, in the order
141
     * (if any) defined when the collection was obtained.
142
     *
143
     * The iterator starts at the specified position in this collection. The
144
     * specified index indicates the first element that would be returned by an
145
     * initial call to the <tt>next</tt> method. An initial call to the
146
     * <tt>previous</tt> method would return the element with the specified
147
     * index minus one.
148
     *
149
     * <p>
150
     * <em>
151
     * <strong>NOTE:</strong> if you use this method to get the iterator, you
152
     * must get sure the iterator is disposed (@see
153
     * {@link DisposableIterator#dispose()}) in any case, even if an error
154
     * occurs while getting the data. It is recommended to use the
155
     * <code>accept</code> methods instead, which handle everything for you.
156
     * Take into account the accept methods may use a fast iterator to get the
157
     * features.
158
     * </em>
159
     * </p>
160
     *
161
     * @see #accept(org.gvsig.tools.visitor.Visitor)
162
     * @see #accept(org.gvsig.tools.visitor.Visitor, long)
163
     * @see #fastIterator()
164
     * @see #fastIterator(long)
165
     *
166
     * @param index index of first element to be returned from the iterator (by
167
     * a call to the <tt>next</tt> method).
168
     * @return an iterator of the elements in this collection (in proper
169
     * sequence), starting at the specified position in the collection.
170
     * @throws DataException if the index is out of range (index &lt; 0 || index
171
     * &gt; size()).
172
     * @deprecated use {@link #fastIterator(long)} instead
173
     */
174
    DisposableIterator iterator(long index) throws DataException;
175

    
176
    DisposableIterator iterator(long index, long elements) throws DataException;
177

    
178
    /**
179
     * Returns an iterator over the elements in this collection, in the order
180
     * (if any) defined when the collection was obtained.
181
     *
182
     * @see #accept(org.gvsig.tools.visitor.Visitor)
183
     * @see #accept(org.gvsig.tools.visitor.Visitor, long)
184
     * @see #fastIterator()
185
     * @see #fastIterator(long)
186
     *
187
     * @return an iterator of the elements in this collection (in proper
188
     * sequence).
189
     *
190
     * @deprecated use fastiterator. In next versions the signature of this
191
     * method will be changed to "Iterator&lt;Feature&gt; iterator()".
192
     */
193
    @Override
194
    DisposableIterator iterator();
195

    
196
    DisposableFeatureSetIterable iterable();
197

    
198
    DisposableFeatureSetIterable iterable(boolean disposeFeatureSet);
199

    
200
    /**
201
     * Returns a fast iterator over this set.
202
     * <p>
203
     * Fast in this case means that each of the elements returned may be a
204
     * reused or pooled object instance, so don't use it to be stored in any
205
     * way.
206
     * </p>
207
     * <p>
208
     * If you need to store one of the {@link Feature} of the iterator, use the
209
     * {@link Feature#getCopy()} to create a clone of the object.
210
     * </p>
211
     *
212
     * <p>
213
     * <em>
214
     * <strong>NOTE:</strong> if you use this method to get the iterator, you
215
     * must get sure the iterator is disposed (@see
216
     * {@link DisposableIterator#dispose()}) in any case, even if an error
217
     * occurs while getting the data. It is recommended to use the
218
     * <code>accept</code> methods instead, which handle everything for you.
219
     * Take into account the accept methods may use a fast iterator to get the
220
     * features.
221
     * </em>
222
     * </p>
223
     *
224
     * @see #accept(org.gvsig.tools.visitor.Visitor)
225
     * @see #accept(org.gvsig.tools.visitor.Visitor, long)
226
     *
227
     * @return an iterator over this set.
228
     *
229
     * @throws DataException
230
     */
231
    public DisposableIterator fastIterator() throws DataException;
232

    
233
    /**
234
     * Returns a fast iterator over this set, starting from the given index.
235
     * <p>
236
     * Fast in this case means that each of the elements returned may be a
237
     * reused or pooled object instance, so don't use it to be stored in any
238
     * way.
239
     * </p>
240
     * <p>
241
     * If you need to store one of the {@link Feature} of the iterator, use the
242
     * {@link Feature#getCopy()} to create a clone of the object.
243
     * </p>
244
     *
245
     * <p>
246
     * <em>
247
     * <strong>NOTE:</strong> if you use this method to get the iterator, you
248
     * must get sure the iterator is disposed (@see
249
     * {@link DisposableIterator#dispose()}) in any case, even if an error
250
     * occurs while getting the data. It is recommended to use the
251
     * <code>accept</code> methods instead, which handle everything for you.
252
     * Take into account the accept methods may use a fast iterator to get the
253
     * features.
254
     * </em>
255
     * </p>
256
     *
257
     * @see #accept(org.gvsig.tools.visitor.Visitor)
258
     * @see #accept(org.gvsig.tools.visitor.Visitor, long)
259
     *
260
     * @param index position in which the iterator is initially located.
261
     *
262
     * @return an iterator initially located at the position indicated by the
263
     * given index
264
     *
265
     * @throws DataException
266
     */
267
    public DisposableIterator fastIterator(long index) throws DataException;
268

    
269
    public DisposableIterator fastIterator(long index, long elemets) throws DataException;
270

    
271
    /**
272
     * Return the first feature of the set. If the set is empty return null.
273
     *
274
     * This not is a good method to determine if the set is empty. Use isEmpty
275
     * instead.
276
     *
277
     * This is a utility method that call iterator and retrieve the first
278
     * feature of the iterator.
279
     *
280
     * @return the first fearure of the set or null.
281
     */
282
    public Feature first();
283

    
284
    /**
285
     * Updates a {@link Feature} with the given {@link EditableFeature}.<br>
286
     *
287
     * Any {@link DisposableIterator} from this store that was still in use can
288
     * will not reflect this change.
289
     *
290
     * @param feature an instance of {@link EditableFeature} with which to
291
     * update the associated {@link Feature}.
292
     *
293
     * @throws DataException
294
     */
295
    public void update(EditableFeature feature) throws DataException;
296

    
297
    public void commitChanges() throws DataException;
298

    
299
    /**
300
     * Deletes a {@link Feature} from this FeatureSet.<br>
301
     *
302
     * Any {@link DisposableIterator} from this store that was still in use will
303
     * be
304
     * <i>unsafe</i>. Use {@link DisposableIterator#remove()} instead.
305
     *
306
     * @param feature the {@link Feature} to delete.
307
     *
308
     * @throws DataException
309
     */
310
    public void delete(Feature feature) throws DataException;
311

    
312
    /**
313
     * Inserts a new feature in this set. It needs to be an instance of
314
     * {@link EditableFeature} as it has not been stored yet.<br>
315
     *
316
     * Any {@link DisposableIterator} from this store that was still in use can
317
     * will not reflect this change.
318
     *
319
     * @param feature the {@link EditableFeature} to insert.
320
     *
321
     * @throws DataException
322
     */
323
    public void insert(EditableFeature feature) throws DataException;
324

    
325
    /**
326
     * Returns a {@link DynObjectSet} of the contents of this set. Defaults to
327
     * fast iteration.
328
     *
329
     * @return a {@link DynObjectSet}
330
     */
331
    public DynObjectSet getDynObjectSet();
332

    
333
    /**
334
     * Returns a {@link DynObjectSet} of the contents of this set.
335
     *
336
     * @param fast if the set will be able to be iterated in a fast way, by
337
     * reusing the {@link DynObject} instance for each {@link Feature} instance.
338
     * @return a {@link DynObjectSet}
339
     */
340
    public DynObjectSet getDynObjectSet(boolean fast);
341

    
342
    /**
343
     * Provides each value of this Store to the provided {@link Visitor},
344
     * beginning from the provided index position. The values received through
345
     * the {@link Visitor#visit(Object)} method may be transient, reused or
346
     * externally modifiable, so they can't be used to be stored in any external
347
     * form out of the visit method.
348
     *
349
     * If you need to store any of the values out of the
350
     * {@link Visitor#visit(Object)} method execution, create a copy or clone
351
     * the received value in order to be stored.
352
     *
353
     * @param visitor the visitor to apply to each value.
354
     * @param firstValueIndex index of first element to be visited by the
355
     * {@link Visitor}
356
     * @exception BaseException if there is an error while performing the visit
357
     */
358
    @Override
359
    void accept(Visitor visitor, long firstValueIndex) throws BaseException;
360

    
361
    void accept(Visitor visitor, long firstValueIndex, long elements) throws BaseException;
362

    
363
    public FeatureStore getFeatureStore();
364

    
365
    @Deprecated 
366
    public JsonArray toJSON();
367
    
368
    public JsonArray toJson();
369

    
370
    public JsonArrayBuilder toJsonBuilder();
371
    
372
}