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 @ 46575
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 |
import javax.json.JsonArrayBuilder; |
30 |
|
31 |
import org.gvsig.fmap.dal.DataSet; |
32 |
import org.gvsig.fmap.dal.exception.DataException; |
33 |
import org.gvsig.tools.dispose.DisposableIterator; |
34 |
import org.gvsig.tools.dispose.DisposableIterable; |
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 FeatureSet getFeatureSet();
|
75 |
} |
76 |
|
77 |
/**
|
78 |
* Returns the default {@link FeatureType} of this FeatureSet.
|
79 |
*
|
80 |
* @return default {@link FeatureType} in this FeatureSet.
|
81 |
*/
|
82 |
public FeatureType getDefaultFeatureType();
|
83 |
|
84 |
/**
|
85 |
* Returns a list of the {@link FeatureType}(s) in this FeatureSet.
|
86 |
*
|
87 |
* @return list of the {@link FeatureType}(s) in this FeatureSet.
|
88 |
*/
|
89 |
public List getFeatureTypes(); |
90 |
|
91 |
/**
|
92 |
* Returns the number of {@link Feature}(s) contained in this FeatureSet.
|
93 |
*
|
94 |
* The value returned by this method won't be accurate when the FeatureStore
|
95 |
* is being edited and this set's features are modified, added or deleted.
|
96 |
*
|
97 |
* @return number of {@link Feature}(s) contained in this FeatureSet.
|
98 |
*
|
99 |
* @throws DataException
|
100 |
*/
|
101 |
public long getSize() throws DataException; |
102 |
|
103 |
/**
|
104 |
* Returns an iterator over the elements in this collection, in the order
|
105 |
* (if any) defined when the collection was obtained.
|
106 |
*
|
107 |
* The iterator starts at the specified position in this collection. The
|
108 |
* specified index indicates the first element that would be returned by an
|
109 |
* initial call to the <tt>next</tt> method. An initial call to the
|
110 |
* <tt>previous</tt> method would return the element with the specified
|
111 |
* index minus one.
|
112 |
*
|
113 |
* <p>
|
114 |
* <em>
|
115 |
* <strong>NOTE:</strong> if you use this method to get the iterator, you
|
116 |
* must get sure the iterator is disposed (@see
|
117 |
* {@link DisposableIterator#dispose()}) in any case, even if an error
|
118 |
* occurs while getting the data. It is recommended to use the
|
119 |
* <code>accept</code> methods instead, which handle everything for you.
|
120 |
* Take into account the accept methods may use a fast iterator to get the
|
121 |
* features.
|
122 |
* </em>
|
123 |
* </p>
|
124 |
*
|
125 |
* @see #accept(org.gvsig.tools.visitor.Visitor)
|
126 |
* @see #accept(org.gvsig.tools.visitor.Visitor, long)
|
127 |
* @see #fastIterator()
|
128 |
* @see #fastIterator(long)
|
129 |
*
|
130 |
* @param index index of first element to be returned from the iterator (by
|
131 |
* a 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 if the index is out of range (index < 0 || index
|
135 |
* > size()).
|
136 |
* @deprecated use {@link #fastIterator(long)} instead
|
137 |
*/
|
138 |
DisposableIterator iterator(long index) throws DataException; |
139 |
|
140 |
DisposableIterator iterator(long index, long elements) throws DataException; |
141 |
|
142 |
/**
|
143 |
* Returns an iterator over the elements in this collection, in the order
|
144 |
* (if any) defined when the collection was obtained.
|
145 |
*
|
146 |
* @see #accept(org.gvsig.tools.visitor.Visitor)
|
147 |
* @see #accept(org.gvsig.tools.visitor.Visitor, long)
|
148 |
* @see #fastIterator()
|
149 |
* @see #fastIterator(long)
|
150 |
*
|
151 |
* @return an iterator of the elements in this collection (in proper
|
152 |
* sequence).
|
153 |
*
|
154 |
* @deprecated use fastiterator. In next versions the signature of this
|
155 |
* method will be changed to "Iterator<Feature> iterator()".
|
156 |
*/
|
157 |
@Override
|
158 |
DisposableIterator iterator(); |
159 |
|
160 |
DisposableFeatureSetIterable iterable(); |
161 |
|
162 |
DisposableFeatureSetIterable iterable(boolean disposeFeatureSet);
|
163 |
|
164 |
/**
|
165 |
* Returns a fast iterator over this set.
|
166 |
* <p>
|
167 |
* Fast in this case means that each of the elements returned may be a
|
168 |
* reused or pooled object instance, so don't use it to be stored in any
|
169 |
* way.
|
170 |
* </p>
|
171 |
* <p>
|
172 |
* If you need to store one of the {@link Feature} of the iterator, use the
|
173 |
* {@link Feature#getCopy()} to create a clone of the object.
|
174 |
* </p>
|
175 |
*
|
176 |
* <p>
|
177 |
* <em>
|
178 |
* <strong>NOTE:</strong> if you use this method to get the iterator, you
|
179 |
* must get sure the iterator is disposed (@see
|
180 |
* {@link DisposableIterator#dispose()}) in any case, even if an error
|
181 |
* occurs while getting the data. It is recommended to use the
|
182 |
* <code>accept</code> methods instead, which handle everything for you.
|
183 |
* Take into account the accept methods may use a fast iterator to get the
|
184 |
* features.
|
185 |
* </em>
|
186 |
* </p>
|
187 |
*
|
188 |
* @see #accept(org.gvsig.tools.visitor.Visitor)
|
189 |
* @see #accept(org.gvsig.tools.visitor.Visitor, long)
|
190 |
*
|
191 |
* @return an iterator over this set.
|
192 |
*
|
193 |
* @throws DataException
|
194 |
*/
|
195 |
public DisposableIterator fastIterator() throws DataException; |
196 |
|
197 |
/**
|
198 |
* Returns a fast iterator over this set, starting from the given index.
|
199 |
* <p>
|
200 |
* Fast in this case means that each of the elements returned may be a
|
201 |
* reused or pooled object instance, so don't use it to be stored in any
|
202 |
* way.
|
203 |
* </p>
|
204 |
* <p>
|
205 |
* If you need to store one of the {@link Feature} of the iterator, use the
|
206 |
* {@link Feature#getCopy()} to create a clone of the object.
|
207 |
* </p>
|
208 |
*
|
209 |
* <p>
|
210 |
* <em>
|
211 |
* <strong>NOTE:</strong> if you use this method to get the iterator, you
|
212 |
* must get sure the iterator is disposed (@see
|
213 |
* {@link DisposableIterator#dispose()}) in any case, even if an error
|
214 |
* occurs while getting the data. It is recommended to use the
|
215 |
* <code>accept</code> methods instead, which handle everything for you.
|
216 |
* Take into account the accept methods may use a fast iterator to get the
|
217 |
* features.
|
218 |
* </em>
|
219 |
* </p>
|
220 |
*
|
221 |
* @see #accept(org.gvsig.tools.visitor.Visitor)
|
222 |
* @see #accept(org.gvsig.tools.visitor.Visitor, long)
|
223 |
*
|
224 |
* @param index position in which the iterator is initially located.
|
225 |
*
|
226 |
* @return an iterator initially located at the position indicated by the
|
227 |
* given index
|
228 |
*
|
229 |
* @throws DataException
|
230 |
*/
|
231 |
public DisposableIterator fastIterator(long index) throws DataException; |
232 |
|
233 |
public DisposableIterator fastIterator(long index, long elemets) throws DataException; |
234 |
|
235 |
/**
|
236 |
* Return the first feature of the set. If the set is empty return null.
|
237 |
*
|
238 |
* This not is a good method to determine if the set is empty. Use isEmpty
|
239 |
* instead.
|
240 |
*
|
241 |
* This is a utility method that call iterator and retrieve the first
|
242 |
* feature of the iterator.
|
243 |
*
|
244 |
* @return the first fearure of the set or null.
|
245 |
*/
|
246 |
public Feature first();
|
247 |
|
248 |
/**
|
249 |
* Updates a {@link Feature} with the given {@link EditableFeature}.<br>
|
250 |
*
|
251 |
* Any {@link DisposableIterator} from this store that was still in use can
|
252 |
* will not reflect this change.
|
253 |
*
|
254 |
* @param feature an instance of {@link EditableFeature} with which to
|
255 |
* update the associated {@link Feature}.
|
256 |
*
|
257 |
* @throws DataException
|
258 |
*/
|
259 |
public void update(EditableFeature feature) throws DataException; |
260 |
|
261 |
public void commitChanges() throws DataException; |
262 |
|
263 |
/**
|
264 |
* Deletes a {@link Feature} from this FeatureSet.<br>
|
265 |
*
|
266 |
* Any {@link DisposableIterator} from this store that was still in use will
|
267 |
* be
|
268 |
* <i>unsafe</i>. Use {@link DisposableIterator#remove()} instead.
|
269 |
*
|
270 |
* @param feature the {@link Feature} to delete.
|
271 |
*
|
272 |
* @throws DataException
|
273 |
*/
|
274 |
public void delete(Feature feature) throws DataException; |
275 |
|
276 |
/**
|
277 |
* Inserts a new feature in this set. It needs to be an instance of
|
278 |
* {@link EditableFeature} as it has not been stored yet.<br>
|
279 |
*
|
280 |
* Any {@link DisposableIterator} from this store that was still in use can
|
281 |
* will not reflect this change.
|
282 |
*
|
283 |
* @param feature the {@link EditableFeature} to insert.
|
284 |
*
|
285 |
* @throws DataException
|
286 |
*/
|
287 |
public void insert(EditableFeature feature) throws DataException; |
288 |
|
289 |
/**
|
290 |
* Returns a {@link DynObjectSet} of the contents of this set. Defaults to
|
291 |
* fast iteration.
|
292 |
*
|
293 |
* @return a {@link DynObjectSet}
|
294 |
*/
|
295 |
public DynObjectSet getDynObjectSet();
|
296 |
|
297 |
/**
|
298 |
* Returns a {@link DynObjectSet} of the contents of this set.
|
299 |
*
|
300 |
* @param fast if the set will be able to be iterated in a fast way, by
|
301 |
* reusing the {@link DynObject} instance for each {@link Feature} instance.
|
302 |
* @return a {@link DynObjectSet}
|
303 |
*/
|
304 |
public DynObjectSet getDynObjectSet(boolean fast); |
305 |
|
306 |
/**
|
307 |
* Provides each value of this Store to the provided {@link Visitor},
|
308 |
* beginning from the provided index position. The values received through
|
309 |
* the {@link Visitor#visit(Object)} method may be transient, reused or
|
310 |
* externally modifiable, so they can't be used to be stored in any external
|
311 |
* form out of the visit method.
|
312 |
*
|
313 |
* If you need to store any of the values out of the
|
314 |
* {@link Visitor#visit(Object)} method execution, create a copy or clone
|
315 |
* the received value in order to be stored.
|
316 |
*
|
317 |
* @param visitor the visitor to apply to each value.
|
318 |
* @param firstValueIndex index of first element to be visited by the
|
319 |
* {@link Visitor}
|
320 |
* @exception BaseException if there is an error while performing the visit
|
321 |
*/
|
322 |
@Override
|
323 |
void accept(Visitor visitor, long firstValueIndex) throws BaseException; |
324 |
|
325 |
void accept(Visitor visitor, long firstValueIndex, long elements) throws BaseException; |
326 |
|
327 |
public FeatureStore getFeatureStore();
|
328 |
|
329 |
@Deprecated
|
330 |
public JsonArray toJSON();
|
331 |
|
332 |
public JsonArray toJson();
|
333 |
|
334 |
public JsonArrayBuilder toJsonBuilder();
|
335 |
|
336 |
} |