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 @ 46505
History | View | Annotate | Download (12.6 KB)
1 | 40559 | jjdelcerro | /**
|
---|---|---|---|
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 | 40435 | jjdelcerro | package org.gvsig.fmap.dal.feature; |
25 | |||
26 | 45291 | omartinez | import java.util.Iterator; |
27 | 40435 | jjdelcerro | import java.util.List; |
28 | 44655 | jjdelcerro | import javax.json.JsonArray; |
29 | 45696 | jjdelcerro | import javax.json.JsonArrayBuilder; |
30 | 40435 | jjdelcerro | |
31 | import org.gvsig.fmap.dal.DataSet; |
||
32 | import org.gvsig.fmap.dal.exception.DataException; |
||
33 | import org.gvsig.tools.dispose.DisposableIterator; |
||
34 | 45195 | omartinez | import org.gvsig.tools.dispose.DisposableIterable; |
35 | 40435 | jjdelcerro | import org.gvsig.tools.dynobject.DynObject; |
36 | import org.gvsig.tools.dynobject.DynObjectSet; |
||
37 | import org.gvsig.tools.exception.BaseException; |
||
38 | 45425 | jjdelcerro | import org.gvsig.tools.util.IsEmpty; |
39 | 44390 | jjdelcerro | import org.gvsig.tools.util.Size; |
40 | import org.gvsig.tools.util.Size64; |
||
41 | 40435 | jjdelcerro | 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 | 45541 | fdiaz | *
|
49 | 40435 | jjdelcerro | * A FeatureSet may contain subsets of {@link Feature}(s) of different
|
50 | * {@link FeatureType}(s). It allows iterating and editing the features.
|
||
51 | 45541 | fdiaz | *
|
52 | 40435 | jjdelcerro | * FIXME: Actualizar javadoc
|
53 | 45541 | fdiaz | *
|
54 | 40435 | jjdelcerro | * 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 | 45541 | fdiaz | *
|
59 | 40435 | jjdelcerro | * 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 | 45541 | fdiaz | *
|
63 | 40435 | jjdelcerro | * 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 | 45541 | fdiaz | *
|
68 | 40435 | jjdelcerro | */
|
69 | 45425 | jjdelcerro | public interface FeatureSet extends DataSet, Size64, Size, IsEmpty, IndexedVisitable, Iterable<Feature> { |
70 | 45541 | fdiaz | |
71 | public interface DisposableFeatureSetIterable |
||
72 | 45425 | jjdelcerro | extends DisposableIterable<Feature>, Iterator<Feature>, Size64, IsEmpty { |
73 | 45195 | omartinez | |
74 | 45541 | fdiaz | public FeatureSet getFeatureSet();
|
75 | } |
||
76 | 45100 | jjdelcerro | |
77 | 45541 | fdiaz | /**
|
78 | * Returns the default {@link FeatureType} of this FeatureSet.
|
||
79 | *
|
||
80 | * @return default {@link FeatureType} in this FeatureSet.
|
||
81 | */
|
||
82 | public FeatureType getDefaultFeatureType();
|
||
83 | 40435 | jjdelcerro | |
84 | 45541 | fdiaz | /**
|
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 | 40435 | jjdelcerro | |
91 | 45541 | fdiaz | /**
|
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 | 40435 | jjdelcerro | 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 | 45541 | fdiaz | *
|
107 | 40435 | jjdelcerro | * 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 | 45541 | fdiaz | *
|
113 | 40435 | jjdelcerro | * <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 | 45541 | fdiaz | * {@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 | 40435 | jjdelcerro | * </em>
|
123 | * </p>
|
||
124 | 45541 | fdiaz | *
|
125 | 40435 | jjdelcerro | * @see #accept(org.gvsig.tools.visitor.Visitor)
|
126 | * @see #accept(org.gvsig.tools.visitor.Visitor, long)
|
||
127 | * @see #fastIterator()
|
||
128 | * @see #fastIterator(long)
|
||
129 | 45541 | fdiaz | *
|
130 | * @param index index of first element to be returned from the iterator (by
|
||
131 | * a call to the <tt>next</tt> method).
|
||
132 | 40435 | jjdelcerro | * @return an iterator of the elements in this collection (in proper
|
133 | 45541 | fdiaz | * 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 | 40435 | jjdelcerro | * @deprecated use {@link #fastIterator(long)} instead
|
137 | */
|
||
138 | 45541 | fdiaz | DisposableIterator iterator(long index) throws DataException; |
139 | 40435 | jjdelcerro | |
140 | 43358 | jjdelcerro | DisposableIterator iterator(long index, long elements) throws DataException; |
141 | |||
142 | 40435 | jjdelcerro | /**
|
143 | * Returns an iterator over the elements in this collection, in the order
|
||
144 | * (if any) defined when the collection was obtained.
|
||
145 | 45541 | fdiaz | *
|
146 | 40435 | jjdelcerro | * @see #accept(org.gvsig.tools.visitor.Visitor)
|
147 | * @see #accept(org.gvsig.tools.visitor.Visitor, long)
|
||
148 | * @see #fastIterator()
|
||
149 | * @see #fastIterator(long)
|
||
150 | 45541 | fdiaz | *
|
151 | 40435 | jjdelcerro | * @return an iterator of the elements in this collection (in proper
|
152 | 45541 | fdiaz | * sequence).
|
153 | *
|
||
154 | 42535 | jjdelcerro | * @deprecated use fastiterator. In next versions the signature of this
|
155 | 43358 | jjdelcerro | * method will be changed to "Iterator<Feature> iterator()".
|
156 | 40435 | jjdelcerro | */
|
157 | 45541 | fdiaz | @Override
|
158 | DisposableIterator iterator(); |
||
159 | 40435 | jjdelcerro | |
160 | 45541 | fdiaz | DisposableFeatureSetIterable iterable(); |
161 | |||
162 | DisposableFeatureSetIterable iterable(boolean disposeFeatureSet);
|
||
163 | |||
164 | 40435 | jjdelcerro | /**
|
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 | 45541 | fdiaz | *
|
176 | 40435 | jjdelcerro | * <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 | 45541 | fdiaz | * {@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 | 40435 | jjdelcerro | * </em>
|
186 | * </p>
|
||
187 | 45541 | fdiaz | *
|
188 | 40435 | jjdelcerro | * @see #accept(org.gvsig.tools.visitor.Visitor)
|
189 | * @see #accept(org.gvsig.tools.visitor.Visitor, long)
|
||
190 | 45541 | fdiaz | *
|
191 | 40435 | jjdelcerro | * @return an iterator over this set.
|
192 | 45541 | fdiaz | *
|
193 | 40435 | jjdelcerro | * @throws DataException
|
194 | */
|
||
195 | 45541 | fdiaz | public DisposableIterator fastIterator() throws DataException; |
196 | 40435 | jjdelcerro | |
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 | 45541 | fdiaz | *
|
209 | 40435 | jjdelcerro | * <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 | 45541 | fdiaz | * {@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 | 40435 | jjdelcerro | * </em>
|
219 | * </p>
|
||
220 | 45541 | fdiaz | *
|
221 | 40435 | jjdelcerro | * @see #accept(org.gvsig.tools.visitor.Visitor)
|
222 | * @see #accept(org.gvsig.tools.visitor.Visitor, long)
|
||
223 | 45541 | fdiaz | *
|
224 | * @param index position in which the iterator is initially located.
|
||
225 | *
|
||
226 | 40435 | jjdelcerro | * @return an iterator initially located at the position indicated by the
|
227 | 45541 | fdiaz | * given index
|
228 | *
|
||
229 | 40435 | jjdelcerro | * @throws DataException
|
230 | */
|
||
231 | 43987 | jjdelcerro | public DisposableIterator fastIterator(long index) throws DataException; |
232 | 40435 | jjdelcerro | |
233 | 43358 | jjdelcerro | public DisposableIterator fastIterator(long index, long elemets) throws DataException; |
234 | |||
235 | 45541 | fdiaz | /**
|
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 | 40435 | jjdelcerro | |
248 | 45541 | fdiaz | /**
|
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 | 40435 | jjdelcerro | |
261 | 45541 | fdiaz | public void commitChanges() throws DataException; |
262 | |||
263 | 40435 | jjdelcerro | /**
|
264 | 45541 | fdiaz | * 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 | 40435 | jjdelcerro | * @return a {@link DynObjectSet}
|
294 | */
|
||
295 | public DynObjectSet getDynObjectSet();
|
||
296 | |||
297 | /**
|
||
298 | * Returns a {@link DynObjectSet} of the contents of this set.
|
||
299 | 45541 | fdiaz | *
|
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 | 40435 | jjdelcerro | * @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 | 45541 | fdiaz | * 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 | 40435 | jjdelcerro | * 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 | 45541 | fdiaz | *
|
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 | 40435 | jjdelcerro | */
|
322 | 43358 | jjdelcerro | @Override
|
323 | 40435 | jjdelcerro | void accept(Visitor visitor, long firstValueIndex) throws BaseException; |
324 | 43358 | jjdelcerro | |
325 | void accept(Visitor visitor, long firstValueIndex, long elements) throws BaseException; |
||
326 | 45541 | fdiaz | |
327 | 44092 | omartinez | public FeatureStore getFeatureStore();
|
328 | 45541 | fdiaz | |
329 | 45696 | jjdelcerro | @Deprecated
|
330 | 44655 | jjdelcerro | public JsonArray toJSON();
|
331 | 45696 | jjdelcerro | |
332 | public JsonArray toJson();
|
||
333 | |||
334 | public JsonArrayBuilder toJsonBuilder();
|
||
335 | |||
336 | 45541 | fdiaz | } |