Revision 45541

View differences:

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

  
70
    public interface DisposableFeatureSetIterable
71 71
            extends DisposableIterable<Feature>, Iterator<Feature>, Size64, IsEmpty {
72
        }
73 72
        
73
        public FeatureSet getFeatureSet();
74
    }
74 75

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

  
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();
83
    /**
84
     * Returns a list of the {@link FeatureType}(s) in this FeatureSet.
85
     *
86
     * @return list of the {@link FeatureType}(s) in this FeatureSet.
87
     */
88
    public List getFeatureTypes();
88 89

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

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

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

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

  
161
     DisposableFeatureSetIterable iterable();
162
     
163
     DisposableFeatureSetIterable iterable(boolean disposeFeatureSet);
164
     
159
    DisposableFeatureSetIterable iterable();
160

  
161
    DisposableFeatureSetIterable iterable(boolean disposeFeatureSet);
162

  
165 163
    /**
166 164
     * Returns a fast iterator over this set.
167 165
     * <p>
......
173 171
     * If you need to store one of the {@link Feature} of the iterator, use the
174 172
     * {@link Feature#getCopy()} to create a clone of the object.
175 173
     * </p>
176
     * 
174
     *
177 175
     * <p>
178 176
     * <em>
179 177
     * <strong>NOTE:</strong> if you use this method to get the iterator, you
180 178
     * 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.
179
     * {@link DisposableIterator#dispose()}) in any case, even if an error
180
     * occurs while getting the data. It is recommended to use the
181
     * <code>accept</code> methods instead, which handle everything for you.
182
     * Take into account the accept methods may use a fast iterator to get the
183
     * features.
186 184
     * </em>
187 185
     * </p>
188
     * 
186
     *
189 187
     * @see #accept(org.gvsig.tools.visitor.Visitor)
190 188
     * @see #accept(org.gvsig.tools.visitor.Visitor, long)
191
     * 
189
     *
192 190
     * @return an iterator over this set.
193
     * 
191
     *
194 192
     * @throws DataException
195 193
     */
196
	public DisposableIterator fastIterator() throws DataException;
194
    public DisposableIterator fastIterator() throws DataException;
197 195

  
198 196
    /**
199 197
     * Returns a fast iterator over this set, starting from the given index.
......
206 204
     * If you need to store one of the {@link Feature} of the iterator, use the
207 205
     * {@link Feature#getCopy()} to create a clone of the object.
208 206
     * </p>
209
     * 
207
     *
210 208
     * <p>
211 209
     * <em>
212 210
     * <strong>NOTE:</strong> if you use this method to get the iterator, you
213 211
     * 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.
212
     * {@link DisposableIterator#dispose()}) in any case, even if an error
213
     * occurs while getting the data. It is recommended to use the
214
     * <code>accept</code> methods instead, which handle everything for you.
215
     * Take into account the accept methods may use a fast iterator to get the
216
     * features.
219 217
     * </em>
220 218
     * </p>
221
     * 
219
     *
222 220
     * @see #accept(org.gvsig.tools.visitor.Visitor)
223 221
     * @see #accept(org.gvsig.tools.visitor.Visitor, long)
224
     * 
225
     * @param index
226
     *            position in which the iterator is initially located.
227
     * 
222
     *
223
     * @param index position in which the iterator is initially located.
224
     *
228 225
     * @return an iterator initially located at the position indicated by the
229
     *         given index
230
     * 
226
     * given index
227
     *
231 228
     * @throws DataException
232 229
     */
233 230
    public DisposableIterator fastIterator(long index) throws DataException;
234 231

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

  
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;
234
    /**
235
     * Return the first feature of the set. If the set is empty return null.
236
     *
237
     * This not is a good method to determine if the set is empty. Use isEmpty
238
     * instead.
239
     *
240
     * This is a utility method that call iterator and retrieve the first
241
     * feature of the iterator.
242
     *
243
     * @return the first fearure of the set or null.
244
     */
245
    public Feature first();
279 246

  
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;
247
    /**
248
     * Updates a {@link Feature} with the given {@link EditableFeature}.<br>
249
     *
250
     * Any {@link DisposableIterator} from this store that was still in use can
251
     * will not reflect this change.
252
     *
253
     * @param feature an instance of {@link EditableFeature} with which to
254
     * update the associated {@link Feature}.
255
     *
256
     * @throws DataException
257
     */
258
    public void update(EditableFeature feature) throws DataException;
293 259

  
260
    public void commitChanges() throws DataException;
261

  
294 262
    /**
295
     * Returns a {@link DynObjectSet} of the contents of this set.
296
     * Defaults to fast iteration.
297
     * 
263
     * Deletes a {@link Feature} from this FeatureSet.<br>
264
     *
265
     * Any {@link DisposableIterator} from this store that was still in use will
266
     * be
267
     * <i>unsafe</i>. Use {@link DisposableIterator#remove()} instead.
268
     *
269
     * @param feature the {@link Feature} to delete.
270
     *
271
     * @throws DataException
272
     */
273
    public void delete(Feature feature) throws DataException;
274

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

  
288
    /**
289
     * Returns a {@link DynObjectSet} of the contents of this set. Defaults to
290
     * fast iteration.
291
     *
298 292
     * @return a {@link DynObjectSet}
299 293
     */
300 294
    public DynObjectSet getDynObjectSet();
301 295

  
302 296
    /**
303 297
     * 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.
298
     *
299
     * @param fast if the set will be able to be iterated in a fast way, by
300
     * reusing the {@link DynObject} instance for each {@link Feature} instance.
309 301
     * @return a {@link DynObjectSet}
310 302
     */
311 303
    public DynObjectSet getDynObjectSet(boolean fast);
312 304

  
313 305
    /**
314 306
     * 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
     * 
307
     * beginning from the provided index position. The values received through
308
     * the {@link Visitor#visit(Object)} method may be transient, reused or
309
     * externally modifiable, so they can't be used to be stored in any external
310
     * form out of the visit method.
311
     *
320 312
     * If you need to store any of the values out of the
321 313
     * {@link Visitor#visit(Object)} method execution, create a copy or clone
322 314
     * 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
315
     *
316
     * @param visitor the visitor to apply to each value.
317
     * @param firstValueIndex index of first element to be visited by the
318
     * {@link Visitor}
319
     * @exception BaseException if there is an error while performing the visit
330 320
     */
331 321
    @Override
332 322
    void accept(Visitor visitor, long firstValueIndex) throws BaseException;
333 323

  
334 324
    void accept(Visitor visitor, long firstValueIndex, long elements) throws BaseException;
335
    
325

  
336 326
    public FeatureStore getFeatureStore();
337
    
327

  
338 328
    public JsonArray toJSON();
339
}
329
}
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/feature/impl/featureset/AbstractFeatureSet.java
91 91
        public long size64() {
92 92
            return this.fset.size64();
93 93
        }
94

  
95
        @Override
96
        public FeatureSet getFeatureSet() {
97
            return this.fset;
98
        }
94 99
        
100
        
95 101
    } 
96 102
    
97 103
    protected static final Logger LOG = LoggerFactory.getLogger(AbstractFeatureSet.class);

Also available in: Unified diff