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

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

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

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

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

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

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

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

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

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

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

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

    
231
        /**
232
         * Updates a {@link Feature} with the given {@link EditableFeature}.<br>
233
         * 
234
         * Any {@link DisposableIterator} from this store that was still in use can will not
235
         * reflect this change.
236
         * 
237
         * @param feature
238
         *            an instance of {@link EditableFeature} with which to update
239
         *            the associated {@link Feature}.
240
         * 
241
         * @throws DataException
242
         */
243
        public void update(EditableFeature feature) throws DataException;
244

    
245
        /**
246
         * Deletes a {@link Feature} from this FeatureSet.<br>
247
         * 
248
         * Any {@link DisposableIterator} from this store that was still in use will be
249
         * <i>unsafe</i>. Use {@link DisposableIterator#remove()} instead.
250
         * 
251
         * @param feature
252
         *            the {@link Feature} to delete.
253
         * 
254
         * @throws DataException
255
         */
256
        public void delete(Feature feature) throws DataException;
257

    
258
        /**
259
         * Inserts a new feature in this set. It needs to be an instance of
260
         * {@link EditableFeature} as it has not been stored yet.<br>
261
         * 
262
         * Any {@link DisposableIterator} from this store that was still in use can will not
263
         * reflect this change.
264
         * 
265
         * @param feature
266
         *            the {@link EditableFeature} to insert.
267
         * 
268
         * @throws DataException
269
         */
270
        public void insert(EditableFeature feature) throws DataException;
271

    
272
    /**
273
     * Returns a {@link DynObjectSet} of the contents of this set.
274
     * Defaults to fast iteration.
275
     * 
276
     * @return a {@link DynObjectSet}
277
     */
278
    public DynObjectSet getDynObjectSet();
279

    
280
    /**
281
     * Returns a {@link DynObjectSet} of the contents of this set.
282
     * 
283
     * @param fast
284
     *            if the set will be able to be iterated in a fast way, by
285
     *            reusing the {@link DynObject} instance for each
286
     *            {@link Feature} instance.
287
     * @return a {@link DynObjectSet}
288
     */
289
    public DynObjectSet getDynObjectSet(boolean fast);
290

    
291
    /**
292
     * Provides each value of this Store to the provided {@link Visitor},
293
     * beginning from the provided index position.
294
     * The values received through the {@link Visitor#visit(Object)} method
295
     * may be transient, reused or externally modifiable, so they can't
296
     * be used to be stored in any external form out of the visit method.
297
     * 
298
     * If you need to store any of the values out of the
299
     * {@link Visitor#visit(Object)} method execution, create a copy or clone
300
     * the received value in order to be stored.
301
     * 
302
     * @param visitor
303
     *            the visitor to apply to each value.
304
     * @param firstValueIndex
305
     *            index of first element to be visited by the {@link Visitor}
306
     * @exception BaseException
307
     *                if there is an error while performing the visit
308
     */
309
    void accept(Visitor visitor, long firstValueIndex) throws BaseException;
310
}