Statistics
| Revision:

svn-gvsig-desktop / branches / org.gvsig.desktop-cvsgis1 / 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 @ 45288

History | View | Annotate | Download (12.6 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.Iterator;
27
import java.util.List;
28
import javax.json.JsonArray;
29

    
30
import org.gvsig.fmap.dal.DataSet;
31
import org.gvsig.fmap.dal.exception.DataException;
32
import org.gvsig.tools.dispose.DisposableIterator;
33
import org.gvsig.tools.dispose.DisposableIterable;
34
import org.gvsig.tools.dynobject.DynObject;
35
import org.gvsig.tools.dynobject.DynObjectSet;
36
import org.gvsig.tools.exception.BaseException;
37
import org.gvsig.tools.util.IsEmpty;
38
import org.gvsig.tools.util.Size;
39
import org.gvsig.tools.util.Size64;
40
import org.gvsig.tools.visitor.IndexedVisitable;
41
import org.gvsig.tools.visitor.Visitor;
42

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

    
75
        /**
76
         * Returns the default {@link FeatureType} of this FeatureSet.
77
         * 
78
         * @return default {@link FeatureType} in this FeatureSet.
79
         */
80
        public FeatureType getDefaultFeatureType();
81

    
82
        /**
83
         * Returns a list of the {@link FeatureType}(s) in this FeatureSet.
84
         * 
85
         * @return list of the {@link FeatureType}(s) in this FeatureSet.
86
         */
87
        public List getFeatureTypes();
88

    
89
        /**
90
         * Returns the number of {@link Feature}(s) contained in this FeatureSet.
91
         * 
92
         * The value returned by this method won't be accurate when
93
         * the FeatureStore is being edited and this set's features
94
         * are modified, added or deleted.
95
         *  
96
         * @return number of {@link Feature}(s) contained in this FeatureSet.
97
         * 
98
         * @throws DataException
99
         */
100
    public long getSize() throws DataException;
101

    
102
    /**
103
     * Returns an iterator over the elements in this collection, in the order
104
     * (if any) defined when the collection was obtained.
105
     * 
106
     * The iterator starts at the specified position in this collection. The
107
     * specified index indicates the first element that would be returned by an
108
     * initial call to the <tt>next</tt> method. An initial call to the
109
     * <tt>previous</tt> method would return the element with the specified
110
     * index minus one.
111
     * 
112
     * <p>
113
     * <em>
114
     * <strong>NOTE:</strong> if you use this method to get the iterator, you
115
     * must get sure the iterator is disposed (@see
116
     * {@link DisposableIterator#dispose()}) in any case, even if an error occurs
117
     * while getting the data. It is recommended to use the <code>accept</code>
118
     * methods instead, which handle everything for you. 
119
     * Take into account the accept methods may use a fast iterator to 
120
     * get the features.
121
     * </em>
122
     * </p>
123
     * 
124
     * @see #accept(org.gvsig.tools.visitor.Visitor)
125
     * @see #accept(org.gvsig.tools.visitor.Visitor, long)
126
     * @see #fastIterator()
127
     * @see #fastIterator(long)
128
     * 
129
     * @param index
130
     *            index of first element to be returned from the iterator (by a
131
     *            call to the <tt>next</tt> method).
132
     * @return an iterator of the elements in this collection (in proper
133
     *         sequence), starting at the specified position in the collection.
134
     * @throws DataException
135
     *             if the index is out of range (index &lt; 0 || index &gt;
136
     *             size()).
137
     * @deprecated use {@link #fastIterator(long)} instead
138
     */
139
        DisposableIterator iterator(long index) throws DataException;
140

    
141
    DisposableIterator iterator(long index, long elements) throws DataException;
142

    
143
    /**
144
     * Returns an iterator over the elements in this collection, in the order
145
     * (if any) defined when the collection was obtained.
146
     * 
147
     * @see #accept(org.gvsig.tools.visitor.Visitor)
148
     * @see #accept(org.gvsig.tools.visitor.Visitor, long)
149
     * @see #fastIterator()
150
     * @see #fastIterator(long)
151
     * 
152
     * @return an iterator of the elements in this collection (in proper
153
     *         sequence).
154
     * 
155
     * @deprecated use fastiterator. In next versions the signature of this
156
     * method will be changed to "Iterator&lt;Feature&gt; iterator()".
157
     */
158
     @Override
159
     DisposableIterator iterator();
160

    
161
     DisposableFeatureSetIterable iterable();
162
     
163
     DisposableFeatureSetIterable iterable(boolean disposeFeatureSet);
164
     
165
    /**
166
     * Returns a fast iterator over this set.
167
     * <p>
168
     * Fast in this case means that each of the elements returned may be a
169
     * reused or pooled object instance, so don't use it to be stored in any
170
     * way.
171
     * </p>
172
     * <p>
173
     * If you need to store one of the {@link Feature} of the iterator, use the
174
     * {@link Feature#getCopy()} to create a clone of the object.
175
     * </p>
176
     * 
177
     * <p>
178
     * <em>
179
     * <strong>NOTE:</strong> if you use this method to get the iterator, you
180
     * must get sure the iterator is disposed (@see
181
     * {@link DisposableIterator#dispose()}) in any case, even if an error occurs
182
     * while getting the data. It is recommended to use the <code>accept</code>
183
     * methods instead, which handle everything for you. 
184
     * Take into account the accept methods may use a fast iterator to 
185
     * get the features.
186
     * </em>
187
     * </p>
188
     * 
189
     * @see #accept(org.gvsig.tools.visitor.Visitor)
190
     * @see #accept(org.gvsig.tools.visitor.Visitor, long)
191
     * 
192
     * @return an iterator over this set.
193
     * 
194
     * @throws DataException
195
     */
196
        public DisposableIterator fastIterator() throws DataException;
197

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

    
235
    public DisposableIterator fastIterator(long index, long elemets) throws DataException;
236

    
237
        /**
238
         * Return the first feature of the set.
239
         * If the set is empty return null.
240
         * 
241
         * This not is a good method to determine if the set is empty.
242
         * Use isEmpty instead.
243
         * 
244
         * This is a utility method that call iterator and retrieve the
245
         * first feature of the iterator.
246
         * 
247
         * @return the first fearure of the set or null. 
248
         */
249
        public Feature first();
250
        
251
        /**
252
         * Updates a {@link Feature} with the given {@link EditableFeature}.<br>
253
         * 
254
         * Any {@link DisposableIterator} from this store that was still in use can will not
255
         * reflect this change.
256
         * 
257
         * @param feature
258
         *            an instance of {@link EditableFeature} with which to update
259
         *            the associated {@link Feature}.
260
         * 
261
         * @throws DataException
262
         */
263
        public void update(EditableFeature feature) throws DataException;
264
        
265
        public void commitChanges() throws DataException;
266
        
267
        /**
268
         * Deletes a {@link Feature} from this FeatureSet.<br>
269
         * 
270
         * Any {@link DisposableIterator} from this store that was still in use will be
271
         * <i>unsafe</i>. Use {@link DisposableIterator#remove()} instead.
272
         * 
273
         * @param feature
274
         *            the {@link Feature} to delete.
275
         * 
276
         * @throws DataException
277
         */
278
        public void delete(Feature feature) throws DataException;
279

    
280
        /**
281
         * Inserts a new feature in this set. It needs to be an instance of
282
         * {@link EditableFeature} as it has not been stored yet.<br>
283
         * 
284
         * Any {@link DisposableIterator} from this store that was still in use can will not
285
         * reflect this change.
286
         * 
287
         * @param feature
288
         *            the {@link EditableFeature} to insert.
289
         * 
290
         * @throws DataException
291
         */
292
        public void insert(EditableFeature feature) throws DataException;
293

    
294
    /**
295
     * Returns a {@link DynObjectSet} of the contents of this set.
296
     * Defaults to fast iteration.
297
     * 
298
     * @return a {@link DynObjectSet}
299
     */
300
    public DynObjectSet getDynObjectSet();
301

    
302
    /**
303
     * Returns a {@link DynObjectSet} of the contents of this set.
304
     * 
305
     * @param fast
306
     *            if the set will be able to be iterated in a fast way, by
307
     *            reusing the {@link DynObject} instance for each
308
     *            {@link Feature} instance.
309
     * @return a {@link DynObjectSet}
310
     */
311
    public DynObjectSet getDynObjectSet(boolean fast);
312

    
313
    /**
314
     * Provides each value of this Store to the provided {@link Visitor},
315
     * beginning from the provided index position.
316
     * The values received through the {@link Visitor#visit(Object)} method
317
     * may be transient, reused or externally modifiable, so they can't
318
     * be used to be stored in any external form out of the visit method.
319
     * 
320
     * If you need to store any of the values out of the
321
     * {@link Visitor#visit(Object)} method execution, create a copy or clone
322
     * the received value in order to be stored.
323
     * 
324
     * @param visitor
325
     *            the visitor to apply to each value.
326
     * @param firstValueIndex
327
     *            index of first element to be visited by the {@link Visitor}
328
     * @exception BaseException
329
     *                if there is an error while performing the visit
330
     */
331
    @Override
332
    void accept(Visitor visitor, long firstValueIndex) throws BaseException;
333

    
334
    void accept(Visitor visitor, long firstValueIndex, long elements) throws BaseException;
335
    
336
    public FeatureStore getFeatureStore();
337
    
338
    public JsonArray toJSON();
339
}