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

History | View | Annotate | Download (12.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

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

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

    
66
        /**
67
         * Returns the default {@link FeatureType} of this FeatureSet.
68
         * 
69
         * @return default {@link FeatureType} in this FeatureSet.
70
         */
71
        public FeatureType getDefaultFeatureType();
72

    
73
        /**
74
         * Returns a list of the {@link FeatureType}(s) in this FeatureSet.
75
         * 
76
         * @return list of the {@link FeatureType}(s) in this FeatureSet.
77
         */
78
        public List getFeatureTypes();
79

    
80
        /**
81
         * Returns the number of {@link Feature}(s) contained in this FeatureSet.
82
         * 
83
         * The value returned by this method won't be accurate when
84
         * the FeatureStore is being edited and this set's features
85
         * are modified, added or deleted.
86
         *  
87
         * @return number of {@link Feature}(s) contained in this FeatureSet.
88
         * 
89
         * @throws DataException
90
         */
91
    public long getSize() throws DataException;
92

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

    
132
    DisposableIterator iterator(long index, long elements) throws DataException;
133

    
134
    /**
135
     * Returns an iterator over the elements in this collection, in the order
136
     * (if any) defined when the collection was obtained.
137
     * 
138
     * @see #accept(org.gvsig.tools.visitor.Visitor)
139
     * @see #accept(org.gvsig.tools.visitor.Visitor, long)
140
     * @see #fastIterator()
141
     * @see #fastIterator(long)
142
     * 
143
     * @return an iterator of the elements in this collection (in proper
144
     *         sequence).
145
     * 
146
     * @deprecated use fastiterator. In next versions the signature of this
147
     * method will be changed to "Iterator&lt;Feature&gt; iterator()".
148
     */
149
     DisposableIterator iterator();
150

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

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

    
221
    public DisposableIterator fastIterator(long index, long elemets) throws DataException;
222

    
223
        /**
224
         * Indicates whether this FeatureSet contains zero features.
225
         * 
226
         * The value returned by this method won't be accurate when
227
         * the FeatureStore is being edited and this set's features
228
         * are modified, added or deleted.
229
         *  
230
         * @return true if this FeatureSet is empty, false otherwise.
231
         * 
232
         * @throws DataException
233
         */
234
        boolean isEmpty() throws DataException;
235

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

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

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

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

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

    
333
    void accept(Visitor visitor, long firstValueIndex, long elements) throws BaseException;
334
    
335
    public FeatureStore getFeatureStore();
336
}