Revision 33378 branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/feature/impl/DefaultFeatureSelection.java
DefaultFeatureSelection.java | ||
---|---|---|
49 | 49 |
import org.gvsig.tools.persistence.PersistenceManager; |
50 | 50 |
import org.gvsig.tools.persistence.PersistentState; |
51 | 51 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
52 |
import org.gvsig.tools.visitor.VisitCanceledException; |
|
52 | 53 |
import org.gvsig.tools.visitor.Visitor; |
53 | 54 |
import org.slf4j.Logger; |
54 | 55 |
import org.slf4j.LoggerFactory; |
... | ... | |
56 | 57 |
/** |
57 | 58 |
* Default implementation of the FeatureSelection interface. Internally, only |
58 | 59 |
* FeatureReference values are stored. |
59 |
* |
|
60 |
*
|
|
60 | 61 |
* This implementation performs better if used with the selection related |
61 | 62 |
* methods: select, deselect and isSelected ones. |
62 |
* |
|
63 |
*
|
|
63 | 64 |
* @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a> |
64 | 65 |
*/ |
65 | 66 |
public class DefaultFeatureSelection extends DefaultFeatureReferenceSelection |
66 |
implements FeatureSelection {
|
|
67 |
implements FeatureSelection {
|
|
67 | 68 |
|
68 |
private static final Logger LOGGER = LoggerFactory
|
|
69 |
.getLogger(DefaultFeatureSelection.class);
|
|
69 |
private static final Logger LOG = LoggerFactory
|
|
70 |
.getLogger(DefaultFeatureSelection.class);
|
|
70 | 71 |
|
71 |
private Map featureTypeCounts = new HashMap(1);
|
|
72 |
private Map featureTypeCounts = new HashMap(1);
|
|
72 | 73 |
|
73 |
/**
|
|
74 |
* Creates a DefaultFeatureSelection, with a FeatureStore.
|
|
75 |
*
|
|
76 |
* @param featureStore
|
|
77 |
* the FeatureStore to load Features from
|
|
78 |
* @throws DataException
|
|
79 |
* if there is an error while getting the total number of
|
|
80 |
* Features of the Store.
|
|
81 |
* @see AbstractSetBasedDataSelection#DefaultSelection(int)
|
|
82 |
*/
|
|
83 |
public DefaultFeatureSelection(DefaultFeatureStore featureStore)
|
|
84 |
throws DataException {
|
|
85 |
super(featureStore);
|
|
86 |
}
|
|
74 |
/**
|
|
75 |
* Creates a DefaultFeatureSelection, with a FeatureStore.
|
|
76 |
*
|
|
77 |
* @param featureStore
|
|
78 |
* the FeatureStore to load Features from
|
|
79 |
* @throws DataException
|
|
80 |
* if there is an error while getting the total number of
|
|
81 |
* Features of the Store.
|
|
82 |
* @see AbstractSetBasedDataSelection#DefaultSelection(int)
|
|
83 |
*/
|
|
84 |
public DefaultFeatureSelection(DefaultFeatureStore featureStore)
|
|
85 |
throws DataException {
|
|
86 |
super(featureStore);
|
|
87 |
}
|
|
87 | 88 |
|
88 |
/**
|
|
89 |
* Creates a new Selection with the total size of Features from which the
|
|
90 |
* selection will be performed.
|
|
91 |
*
|
|
92 |
* @param featureStore
|
|
93 |
* the FeatureStore of the selected FeatureReferences
|
|
94 |
* @param helper
|
|
95 |
* to get some information of the Store
|
|
96 |
* @throws DataException
|
|
97 |
* if there is an error while getting the total number of
|
|
98 |
* Features of the Store.
|
|
99 |
*/
|
|
100 |
public DefaultFeatureSelection(FeatureStore featureStore,
|
|
101 |
FeatureSelectionHelper helper) throws DataException {
|
|
102 |
super(featureStore, helper);
|
|
103 |
}
|
|
89 |
/**
|
|
90 |
* Creates a new Selection with the total size of Features from which the
|
|
91 |
* selection will be performed.
|
|
92 |
*
|
|
93 |
* @param featureStore
|
|
94 |
* the FeatureStore of the selected FeatureReferences
|
|
95 |
* @param helper
|
|
96 |
* to get some information of the Store
|
|
97 |
* @throws DataException
|
|
98 |
* if there is an error while getting the total number of
|
|
99 |
* Features of the Store.
|
|
100 |
*/
|
|
101 |
public DefaultFeatureSelection(FeatureStore featureStore,
|
|
102 |
FeatureSelectionHelper helper) throws DataException {
|
|
103 |
super(featureStore, helper);
|
|
104 |
}
|
|
104 | 105 |
|
105 | 106 |
/** |
106 | 107 |
* Constructor used by the persistence manager. Don't use directly. After to |
... | ... | |
112 | 113 |
super(); |
113 | 114 |
} |
114 | 115 |
|
115 |
public boolean select(Feature feature) {
|
|
116 |
return select(feature, true);
|
|
117 |
}
|
|
116 |
public boolean select(Feature feature) {
|
|
117 |
return select(feature, true);
|
|
118 |
}
|
|
118 | 119 |
|
119 |
/**
|
|
120 |
* @see #select(Feature)
|
|
121 |
* @param undoable
|
|
122 |
* if the action must be undoable
|
|
123 |
*/
|
|
124 |
public boolean select(Feature feature, boolean undoable) {
|
|
125 |
// TODO: should we check if the feature is from the same FeatureStore??
|
|
126 |
if (feature == null) {
|
|
127 |
return false;
|
|
128 |
}
|
|
120 |
/**
|
|
121 |
* @see #select(Feature)
|
|
122 |
* @param undoable
|
|
123 |
* if the action must be undoable
|
|
124 |
*/
|
|
125 |
public boolean select(Feature feature, boolean undoable) {
|
|
126 |
// TODO: should we check if the feature is from the same FeatureStore??
|
|
127 |
if (feature == null) {
|
|
128 |
return false;
|
|
129 |
}
|
|
129 | 130 |
|
130 |
// LOGGER.debug("Selected feature: {}", feature);
|
|
131 |
// LOGGER.debug("Selected feature: {}", feature);
|
|
131 | 132 |
|
132 |
if (isReversed()) {
|
|
133 |
removeFeatureTypeCount(feature.getType());
|
|
134 |
} else {
|
|
135 |
addFeatureTypeCount(feature.getType());
|
|
136 |
}
|
|
137 |
return select(feature.getReference(), undoable);
|
|
138 |
}
|
|
133 |
if (isReversed()) {
|
|
134 |
removeFeatureTypeCount(feature.getType());
|
|
135 |
} else {
|
|
136 |
addFeatureTypeCount(feature.getType());
|
|
137 |
}
|
|
138 |
return select(feature.getReference(), undoable);
|
|
139 |
}
|
|
139 | 140 |
|
140 |
public boolean select(FeatureSet features) throws DataException {
|
|
141 |
return select(features, true);
|
|
142 |
}
|
|
141 |
public boolean select(FeatureSet features) throws DataException {
|
|
142 |
return select(features, true);
|
|
143 |
}
|
|
143 | 144 |
|
144 |
/**
|
|
145 |
* @see #select(FeatureSet)
|
|
146 |
* @param undoable
|
|
147 |
* if the action must be undoable
|
|
148 |
*/
|
|
149 |
public boolean select(FeatureSet features, boolean undoable)
|
|
150 |
throws DataException {
|
|
151 |
boolean change = false;
|
|
152 |
boolean inComplex = false;
|
|
153 |
if (undoable && getFeatureStore().isEditing()
|
|
145 |
/**
|
|
146 |
* @see #select(FeatureSet)
|
|
147 |
* @param undoable
|
|
148 |
* if the action must be undoable
|
|
149 |
*/
|
|
150 |
public boolean select(FeatureSet features, boolean undoable)
|
|
151 |
throws DataException {
|
|
152 |
boolean change = false;
|
|
153 |
boolean inComplex = false;
|
|
154 |
if (undoable && getFeatureStore().isEditing()
|
|
154 | 155 |
&& !getCommands().inComplex()) { |
155 | 156 |
inComplex = getCommands().inComplex(); |
156 | 157 |
getCommands().startComplex("_selectionSelectFeatureSet"); |
157 |
}
|
|
158 |
}
|
|
158 | 159 |
|
159 |
disableNotifications();
|
|
160 |
disableNotifications();
|
|
160 | 161 |
DisposableIterator iter = null; |
161 | 162 |
try { |
162 | 163 |
for (iter = features.fastIterator(); iter.hasNext();) { |
... | ... | |
164 | 165 |
} |
165 | 166 |
} finally { |
166 | 167 |
dispose(iter); |
167 |
}
|
|
168 |
enableNotifications();
|
|
169 |
if (undoable && getFeatureStore().isEditing() && !inComplex) {
|
|
170 |
getCommands().endComplex();
|
|
171 |
}
|
|
172 |
if (change) {
|
|
173 |
notifyObservers(DataStoreNotification.SELECTION_CHANGE);
|
|
174 |
}
|
|
175 |
return change;
|
|
176 |
}
|
|
168 |
}
|
|
169 |
enableNotifications();
|
|
170 |
if (undoable && getFeatureStore().isEditing() && !inComplex) {
|
|
171 |
getCommands().endComplex();
|
|
172 |
}
|
|
173 |
if (change) {
|
|
174 |
notifyObservers(DataStoreNotification.SELECTION_CHANGE);
|
|
175 |
}
|
|
176 |
return change;
|
|
177 |
}
|
|
177 | 178 |
|
178 |
public boolean deselect(Feature feature) {
|
|
179 |
return deselect(feature, true);
|
|
180 |
}
|
|
179 |
public boolean deselect(Feature feature) {
|
|
180 |
return deselect(feature, true);
|
|
181 |
}
|
|
181 | 182 |
|
182 |
/**
|
|
183 |
* @see #deselect(Feature)
|
|
184 |
* @param undoable
|
|
185 |
* if the action must be undoable
|
|
186 |
*/
|
|
187 |
public boolean deselect(Feature feature, boolean undoable) {
|
|
188 |
if (feature == null) {
|
|
189 |
return false;
|
|
190 |
}
|
|
183 |
/**
|
|
184 |
* @see #deselect(Feature)
|
|
185 |
* @param undoable
|
|
186 |
* if the action must be undoable
|
|
187 |
*/
|
|
188 |
public boolean deselect(Feature feature, boolean undoable) {
|
|
189 |
if (feature == null) {
|
|
190 |
return false;
|
|
191 |
}
|
|
191 | 192 |
|
192 |
LOGGER.debug("Deselected feature: {}", feature);
|
|
193 |
LOG.debug("Deselected feature: {}", feature);
|
|
193 | 194 |
|
194 |
if (isReversed()) {
|
|
195 |
addFeatureTypeCount(feature.getType());
|
|
196 |
} else {
|
|
197 |
removeFeatureTypeCount(feature.getType());
|
|
198 |
}
|
|
199 |
return deselect(feature.getReference(), undoable);
|
|
200 |
}
|
|
195 |
if (isReversed()) {
|
|
196 |
addFeatureTypeCount(feature.getType());
|
|
197 |
} else {
|
|
198 |
removeFeatureTypeCount(feature.getType());
|
|
199 |
}
|
|
200 |
return deselect(feature.getReference(), undoable);
|
|
201 |
}
|
|
201 | 202 |
|
202 |
public boolean deselect(FeatureSet features) throws DataException {
|
|
203 |
return deselect(features, true);
|
|
204 |
}
|
|
203 |
public boolean deselect(FeatureSet features) throws DataException {
|
|
204 |
return deselect(features, true);
|
|
205 |
}
|
|
205 | 206 |
|
206 |
/**
|
|
207 |
* @see #deselect(FeatureSet)
|
|
208 |
* @param undoable
|
|
209 |
* if the action must be undoable
|
|
210 |
*/
|
|
211 |
public boolean deselect(FeatureSet features, boolean undoable)
|
|
212 |
throws DataException {
|
|
213 |
boolean change = false;
|
|
214 |
if (undoable && getFeatureStore().isEditing()) {
|
|
215 |
getCommands().startComplex("_selectionDeselectFeatureSet");
|
|
216 |
}
|
|
217 |
disableNotifications();
|
|
207 |
/**
|
|
208 |
* @see #deselect(FeatureSet)
|
|
209 |
* @param undoable
|
|
210 |
* if the action must be undoable
|
|
211 |
*/
|
|
212 |
public boolean deselect(FeatureSet features, boolean undoable)
|
|
213 |
throws DataException {
|
|
214 |
boolean change = false;
|
|
215 |
if (undoable && getFeatureStore().isEditing()) {
|
|
216 |
getCommands().startComplex("_selectionDeselectFeatureSet");
|
|
217 |
}
|
|
218 |
disableNotifications();
|
|
218 | 219 |
DisposableIterator iter = null; |
219 | 220 |
try { |
220 | 221 |
for (iter = features.fastIterator(); iter.hasNext();) { |
... | ... | |
222 | 223 |
} |
223 | 224 |
} finally { |
224 | 225 |
dispose(iter); |
225 |
}
|
|
226 |
enableNotifications();
|
|
227 |
if (undoable && getFeatureStore().isEditing()) {
|
|
228 |
getCommands().endComplex();
|
|
229 |
}
|
|
230 |
if (change) {
|
|
231 |
notifyObservers(DataStoreNotification.SELECTION_CHANGE);
|
|
232 |
}
|
|
233 |
return change;
|
|
234 |
}
|
|
226 |
}
|
|
227 |
enableNotifications();
|
|
228 |
if (undoable && getFeatureStore().isEditing()) {
|
|
229 |
getCommands().endComplex();
|
|
230 |
}
|
|
231 |
if (change) {
|
|
232 |
notifyObservers(DataStoreNotification.SELECTION_CHANGE);
|
|
233 |
}
|
|
234 |
return change;
|
|
235 |
}
|
|
235 | 236 |
|
236 |
public boolean isSelected(Feature feature) {
|
|
237 |
if (feature == null) {
|
|
238 |
return false;
|
|
239 |
}
|
|
240 |
return isSelected(feature.getReference());
|
|
241 |
}
|
|
237 |
public boolean isSelected(Feature feature) {
|
|
238 |
if (feature == null) {
|
|
239 |
return false;
|
|
240 |
}
|
|
241 |
return isSelected(feature.getReference());
|
|
242 |
}
|
|
242 | 243 |
|
243 |
public FeatureType getDefaultFeatureType() {
|
|
244 |
try {
|
|
245 |
return getFeatureStore().getDefaultFeatureType();
|
|
246 |
} catch (DataException ex) {
|
|
247 |
LOGGER.error("Error getting the default feature type "
|
|
248 |
+ "of the FeatureStore: " + getFeatureStore(), ex);
|
|
249 |
}
|
|
250 |
return null;
|
|
251 |
}
|
|
244 |
public FeatureType getDefaultFeatureType() {
|
|
245 |
try {
|
|
246 |
return getFeatureStore().getDefaultFeatureType();
|
|
247 |
} catch (DataException ex) {
|
|
248 |
LOG.error("Error getting the default feature type "
|
|
249 |
+ "of the FeatureStore: " + getFeatureStore(), ex);
|
|
250 |
}
|
|
251 |
return null;
|
|
252 |
}
|
|
252 | 253 |
|
253 |
public List getFeatureTypes() { |
|
254 |
// Go through the map of FeatureTypes, and return only the ones that |
|
255 |
// have at least a Feature. |
|
256 |
List types = new ArrayList(); |
|
257 |
for (java.util.Iterator iterator = featureTypeCounts.entrySet() |
|
258 |
.iterator(); iterator |
|
259 |
.hasNext();) { |
|
260 |
Map.Entry entry = (Entry) iterator.next(); |
|
261 |
FeatureType type = (FeatureType) entry.getKey(); |
|
262 |
Long count = (Long) entry.getValue(); |
|
254 |
public List getFeatureTypes() { |
|
255 |
// Go through the map of FeatureTypes, and return only the ones that |
|
256 |
// have at least a Feature. |
|
257 |
List types = new ArrayList(); |
|
258 |
for (java.util.Iterator iterator = featureTypeCounts.entrySet() |
|
259 |
.iterator(); iterator.hasNext();) { |
|
260 |
Map.Entry entry = (Entry) iterator.next(); |
|
261 |
FeatureType type = (FeatureType) entry.getKey(); |
|
262 |
Long count = (Long) entry.getValue(); |
|
263 | 263 |
|
264 |
if (count.longValue() > 0) {
|
|
265 |
types.add(type);
|
|
266 |
}
|
|
267 |
}
|
|
264 |
if (count.longValue() > 0) {
|
|
265 |
types.add(type);
|
|
266 |
}
|
|
267 |
}
|
|
268 | 268 |
|
269 |
return types;
|
|
270 |
}
|
|
269 |
return types;
|
|
270 |
}
|
|
271 | 271 |
|
272 |
public long getSize() throws DataException {
|
|
273 |
return getSelectedCount();
|
|
274 |
}
|
|
272 |
public long getSize() throws DataException {
|
|
273 |
return getSelectedCount();
|
|
274 |
}
|
|
275 | 275 |
|
276 |
public boolean isEmpty() throws DataException {
|
|
277 |
return getSelectedCount() == 0;
|
|
278 |
}
|
|
276 |
public boolean isEmpty() throws DataException {
|
|
277 |
return getSelectedCount() == 0;
|
|
278 |
}
|
|
279 | 279 |
|
280 |
/**
|
|
281 |
* Returns the list of selected values, or the deselected ones if the
|
|
282 |
* selection has been reversed.
|
|
283 |
*/
|
|
284 |
public DisposableIterator iterator() {
|
|
285 |
return iterator(0);
|
|
286 |
}
|
|
280 |
/**
|
|
281 |
* Returns the list of selected values, or the deselected ones if the
|
|
282 |
* selection has been reversed.
|
|
283 |
*/
|
|
284 |
public DisposableIterator iterator() {
|
|
285 |
return iterator(0);
|
|
286 |
}
|
|
287 | 287 |
|
288 |
/**
|
|
289 |
* Returns the list of selected values, or the deselected ones if the
|
|
290 |
* selection has been reversed.
|
|
291 |
*
|
|
292 |
* WARN: not very good performance implementation.
|
|
293 |
*/
|
|
294 |
public DisposableIterator iterator(long index) {
|
|
295 |
return iterator(index, false);
|
|
296 |
}
|
|
288 |
/**
|
|
289 |
* Returns the list of selected values, or the deselected ones if the
|
|
290 |
* selection has been reversed.
|
|
291 |
*
|
|
292 |
* WARN: not very good performance implementation.
|
|
293 |
*/
|
|
294 |
public DisposableIterator iterator(long index) {
|
|
295 |
return iterator(index, false);
|
|
296 |
}
|
|
297 | 297 |
|
298 |
/**
|
|
299 |
* Returns the list of selected values, or the deselected ones if the
|
|
300 |
* selection has been reversed.
|
|
301 |
*
|
|
302 |
* WARN: not really a fast implementation.
|
|
303 |
*/
|
|
304 |
public DisposableIterator fastIterator() {
|
|
305 |
return fastIterator(0);
|
|
306 |
}
|
|
298 |
/**
|
|
299 |
* Returns the list of selected values, or the deselected ones if the
|
|
300 |
* selection has been reversed.
|
|
301 |
*
|
|
302 |
* WARN: not really a fast implementation.
|
|
303 |
*/
|
|
304 |
public DisposableIterator fastIterator() {
|
|
305 |
return fastIterator(0);
|
|
306 |
}
|
|
307 | 307 |
|
308 |
/**
|
|
309 |
* Returns the list of selected values, or the deselected ones if the
|
|
310 |
* selection has been reversed.
|
|
311 |
*
|
|
312 |
* WARN: not really a fast implementation.
|
|
313 |
*/
|
|
314 |
public DisposableIterator fastIterator(long index) {
|
|
315 |
return iterator(index, true);
|
|
316 |
}
|
|
308 |
/**
|
|
309 |
* Returns the list of selected values, or the deselected ones if the
|
|
310 |
* selection has been reversed.
|
|
311 |
*
|
|
312 |
* WARN: not really a fast implementation.
|
|
313 |
*/
|
|
314 |
public DisposableIterator fastIterator(long index) {
|
|
315 |
return iterator(index, true);
|
|
316 |
}
|
|
317 | 317 |
|
318 |
protected void clearFeatureReferences() { |
|
319 |
super.clearFeatureReferences(); |
|
320 |
featureTypeCounts.clear(); |
|
321 |
} |
|
318 | 322 |
|
319 |
protected void clearFeatureReferences() { |
|
320 |
super.clearFeatureReferences(); |
|
321 |
featureTypeCounts.clear(); |
|
322 |
} |
|
323 |
/** |
|
324 |
* Creates an iterator for the Selection. |
|
325 |
*/ |
|
326 |
private DisposableIterator iterator(long index, boolean fastIterator) { |
|
327 |
if (isReversed()) { |
|
328 |
DisposableIterator iter = new ReversedFeatureIteratorFacade( |
|
329 |
getData(), getFeatureStore(), fastIterator); |
|
330 |
for (long l = 0; l < index && iter.hasNext(); l++) { |
|
331 |
iter.next(); |
|
332 |
} |
|
333 |
return iter; |
|
323 | 334 |
|
324 |
/** |
|
325 |
* Creates an iterator for the Selection. |
|
326 |
*/ |
|
327 |
private DisposableIterator iterator(long index, boolean fastIterator) { |
|
328 |
if (isReversed()) { |
|
329 |
DisposableIterator iter = new ReversedFeatureIteratorFacade(getData(), |
|
330 |
getFeatureStore(), fastIterator); |
|
331 |
for (long l = 0; l < index && iter.hasNext(); l++) { |
|
332 |
iter.next(); |
|
333 |
} |
|
334 |
return iter; |
|
335 |
} else { |
|
336 |
// TODO: maybe we could add a new referenceIterator(int index) |
|
337 |
// method that could be implemented in a more performant way |
|
335 | 338 |
|
336 |
} else { |
|
337 |
// TODO: maybe we could add a new referenceIterator(int index) |
|
338 |
// method that could be implemented in a more performant way |
|
339 |
java.util.Iterator iter = referenceIterator(); |
|
340 |
for (long l = 0; l < index && iter.hasNext(); l++) { |
|
341 |
iter.next(); |
|
342 |
} |
|
343 |
return new FeatureIteratorFacade(iter, getFeatureStore()); |
|
344 |
} |
|
345 |
} |
|
339 | 346 |
|
340 |
java.util.Iterator iter = referenceIterator(); |
|
341 |
for (long l = 0; l < index && iter.hasNext(); l++) { |
|
342 |
iter.next(); |
|
343 |
} |
|
344 |
return new FeatureIteratorFacade(iter, getFeatureStore()); |
|
345 |
} |
|
346 |
} |
|
347 |
|
|
348 |
private Long removeFeatureTypeCount(FeatureType featureType) { |
|
347 |
private Long removeFeatureTypeCount(FeatureType featureType) { |
|
349 | 348 |
Long count = (Long) featureTypeCounts.get(featureType); |
350 | 349 |
if (count == null) { |
351 | 350 |
count = new Long(-1); |
... | ... | |
365 | 364 |
} |
366 | 365 |
featureTypeCounts.put(featureType, count); |
367 | 366 |
return count; |
368 |
}
|
|
367 |
}
|
|
369 | 368 |
|
370 |
/**
|
|
371 |
* Facade over a Iterator of FeatureReferences, to return Features instead.
|
|
372 |
*
|
|
373 |
* @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
|
|
374 |
*/
|
|
375 |
private class FeatureIteratorFacade implements DisposableIterator {
|
|
369 |
/**
|
|
370 |
* Facade over a Iterator of FeatureReferences, to return Features instead.
|
|
371 |
*
|
|
372 |
* @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
|
|
373 |
*/
|
|
374 |
private class FeatureIteratorFacade implements DisposableIterator {
|
|
376 | 375 |
|
377 |
final Logger logger = LoggerFactory
|
|
378 |
.getLogger(FeatureIteratorFacade.class);
|
|
376 |
private final Logger LOGGER = LoggerFactory
|
|
377 |
.getLogger(FeatureIteratorFacade.class);
|
|
379 | 378 |
|
380 |
private java.util.Iterator refIterator;
|
|
379 |
private java.util.Iterator refIterator;
|
|
381 | 380 |
|
382 |
private FeatureStore featureStore;
|
|
381 |
private FeatureStore featureStore;
|
|
383 | 382 |
|
384 |
public FeatureIteratorFacade(java.util.Iterator iter,
|
|
385 |
FeatureStore featureStore) {
|
|
386 |
this.refIterator = iter;
|
|
387 |
this.featureStore = featureStore;
|
|
388 |
}
|
|
383 |
public FeatureIteratorFacade(java.util.Iterator iter,
|
|
384 |
FeatureStore featureStore) {
|
|
385 |
this.refIterator = iter;
|
|
386 |
this.featureStore = featureStore;
|
|
387 |
}
|
|
389 | 388 |
|
390 |
public boolean hasNext() {
|
|
391 |
return refIterator.hasNext();
|
|
392 |
}
|
|
389 |
public boolean hasNext() {
|
|
390 |
return refIterator.hasNext();
|
|
391 |
}
|
|
393 | 392 |
|
394 |
public Object next() {
|
|
395 |
FeatureReference ref = nextFeatureReference();
|
|
396 |
try {
|
|
397 |
return featureStore.getFeatureByReference(ref);
|
|
398 |
} catch (DataException ex) {
|
|
399 |
logger.error(
|
|
400 |
"Error loading the Feature with FeatureReference: "
|
|
401 |
+ ref, ex);
|
|
402 |
return null;
|
|
403 |
}
|
|
404 |
}
|
|
393 |
public Object next() {
|
|
394 |
FeatureReference ref = nextFeatureReference();
|
|
395 |
try {
|
|
396 |
return featureStore.getFeatureByReference(ref);
|
|
397 |
} catch (DataException ex) {
|
|
398 |
LOGGER.error(
|
|
399 |
"Error loading the Feature with FeatureReference: "
|
|
400 |
+ ref, ex);
|
|
401 |
return null;
|
|
402 |
}
|
|
403 |
}
|
|
405 | 404 |
|
406 |
/**
|
|
407 |
* Returns the next FeatureReference.
|
|
408 |
*
|
|
409 |
* @return the next FeatureReference
|
|
410 |
*/
|
|
411 |
public FeatureReference nextFeatureReference() {
|
|
412 |
return (FeatureReference) refIterator.next();
|
|
413 |
}
|
|
405 |
/**
|
|
406 |
* Returns the next FeatureReference.
|
|
407 |
*
|
|
408 |
* @return the next FeatureReference
|
|
409 |
*/
|
|
410 |
public FeatureReference nextFeatureReference() {
|
|
411 |
return (FeatureReference) refIterator.next();
|
|
412 |
}
|
|
414 | 413 |
|
415 |
public void remove() {
|
|
416 |
refIterator.remove();
|
|
417 |
}
|
|
414 |
public void remove() {
|
|
415 |
refIterator.remove();
|
|
416 |
}
|
|
418 | 417 |
|
419 |
public void dispose() {
|
|
418 |
public void dispose() {
|
|
420 | 419 |
if (refIterator instanceof DisposableIterator) { |
421 | 420 |
((DisposableIterator) refIterator).dispose(); |
422 | 421 |
} |
423 | 422 |
refIterator = null; |
424 | 423 |
featureStore = null; |
425 | 424 |
} |
426 |
}
|
|
425 |
}
|
|
427 | 426 |
|
428 |
/**
|
|
429 |
* Facade over a Iterator of FeatureReferences, to return Features instead,
|
|
430 |
* when the Selection is reversed
|
|
431 |
*
|
|
432 |
* @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
|
|
433 |
*/
|
|
434 |
private class ReversedFeatureIteratorFacade implements DisposableIterator {
|
|
427 |
/**
|
|
428 |
* Facade over a Iterator of FeatureReferences, to return Features instead,
|
|
429 |
* when the Selection is reversed
|
|
430 |
*
|
|
431 |
* @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
|
|
432 |
*/
|
|
433 |
private class ReversedFeatureIteratorFacade implements DisposableIterator {
|
|
435 | 434 |
|
436 |
private SelectionData selectionData;
|
|
435 |
private SelectionData selectionData;
|
|
437 | 436 |
|
438 |
private DisposableIterator iterator;
|
|
437 |
private DisposableIterator iterator;
|
|
439 | 438 |
|
440 |
private Feature nextFeature = null;
|
|
439 |
private Feature nextFeature = null;
|
|
441 | 440 |
|
442 | 441 |
private FeatureSet featureSet; |
443 | 442 |
|
444 |
public ReversedFeatureIteratorFacade(SelectionData selectionData,
|
|
445 |
FeatureStore featureStore, boolean fastIterator) {
|
|
446 |
this.selectionData = selectionData;
|
|
443 |
public ReversedFeatureIteratorFacade(SelectionData selectionData,
|
|
444 |
FeatureStore featureStore, boolean fastIterator) {
|
|
445 |
this.selectionData = selectionData;
|
|
447 | 446 |
|
448 |
// Load a Set with all the store features
|
|
449 |
try {
|
|
450 |
featureSet = featureStore.getFeatureSet();
|
|
451 |
if (fastIterator) {
|
|
452 |
iterator = featureSet.fastIterator();
|
|
453 |
} else {
|
|
454 |
iterator = featureSet.iterator();
|
|
455 |
}
|
|
456 |
} catch (DataException ex) {
|
|
457 |
throw new ReversedSelectionIteratorException(ex);
|
|
458 |
}
|
|
447 |
// Load a Set with all the store features
|
|
448 |
try {
|
|
449 |
featureSet = featureStore.getFeatureSet();
|
|
450 |
if (fastIterator) {
|
|
451 |
iterator = featureSet.fastIterator();
|
|
452 |
} else {
|
|
453 |
iterator = featureSet.iterator();
|
|
454 |
}
|
|
455 |
} catch (DataException ex) {
|
|
456 |
throw new ReversedSelectionIteratorException(ex);
|
|
457 |
}
|
|
459 | 458 |
|
460 |
// Filter the features not selected and position in the next
|
|
461 |
// selected feature
|
|
462 |
positionInNextElement();
|
|
463 |
}
|
|
459 |
// Filter the features not selected and position in the next
|
|
460 |
// selected feature
|
|
461 |
positionInNextElement();
|
|
462 |
}
|
|
464 | 463 |
|
465 |
public boolean hasNext() {
|
|
466 |
return nextFeature != null;
|
|
467 |
}
|
|
464 |
public boolean hasNext() {
|
|
465 |
return nextFeature != null;
|
|
466 |
}
|
|
468 | 467 |
|
469 |
public Object next() {
|
|
470 |
Feature tmp = nextFeature;
|
|
471 |
positionInNextElement();
|
|
472 |
return tmp;
|
|
473 |
}
|
|
468 |
public Object next() {
|
|
469 |
Feature tmp = nextFeature.getCopy();
|
|
470 |
positionInNextElement();
|
|
471 |
return tmp;
|
|
472 |
}
|
|
474 | 473 |
|
475 |
public void remove() {
|
|
476 |
iterator.remove();
|
|
477 |
}
|
|
474 |
public void remove() {
|
|
475 |
iterator.remove();
|
|
476 |
}
|
|
478 | 477 |
|
479 |
private void positionInNextElement() {
|
|
480 |
nextFeature = null;
|
|
481 |
while (iterator.hasNext()) {
|
|
482 |
nextFeature = (Feature) iterator.next();
|
|
483 |
if (selectionData.contains(nextFeature.getReference())) {
|
|
484 |
nextFeature = null;
|
|
485 |
} else {
|
|
486 |
break;
|
|
487 |
}
|
|
488 |
}
|
|
489 |
}
|
|
478 |
private void positionInNextElement() {
|
|
479 |
nextFeature = null;
|
|
480 |
while (iterator.hasNext()) {
|
|
481 |
nextFeature = (Feature) iterator.next();
|
|
482 |
if (selectionData.contains(nextFeature.getReference())) {
|
|
483 |
nextFeature = null;
|
|
484 |
} else {
|
|
485 |
break;
|
|
486 |
}
|
|
487 |
}
|
|
488 |
}
|
|
490 | 489 |
|
491 | 490 |
public void dispose() { |
492 | 491 |
this.featureSet.dispose(); |
... | ... | |
494 | 493 |
this.selectionData = null; |
495 | 494 |
this.nextFeature = null; |
496 | 495 |
} |
497 |
}
|
|
496 |
}
|
|
498 | 497 |
|
499 |
public void delete(Feature feature) throws DataException {
|
|
500 |
throw new UnsupportedOperationException();
|
|
501 |
}
|
|
498 |
public void delete(Feature feature) throws DataException {
|
|
499 |
throw new UnsupportedOperationException();
|
|
500 |
}
|
|
502 | 501 |
|
503 |
public void insert(EditableFeature feature) throws DataException {
|
|
504 |
throw new UnsupportedOperationException();
|
|
505 |
}
|
|
502 |
public void insert(EditableFeature feature) throws DataException {
|
|
503 |
throw new UnsupportedOperationException();
|
|
504 |
}
|
|
506 | 505 |
|
507 |
public void update(EditableFeature feature) throws DataException {
|
|
508 |
throw new UnsupportedOperationException();
|
|
509 |
}
|
|
506 |
public void update(EditableFeature feature) throws DataException {
|
|
507 |
throw new UnsupportedOperationException();
|
|
508 |
}
|
|
510 | 509 |
|
511 | 510 |
/* |
512 | 511 |
* (non-Javadoc) |
513 |
* |
|
512 |
*
|
|
514 | 513 |
* @seeorg.gvsig.fmap.dal.feature.impl.DefaultFeatureReferenceSelection# |
515 | 514 |
* loadFromState(org.gvsig.tools.persistence.PersistentState) |
516 | 515 |
*/ |
... | ... | |
518 | 517 |
throws PersistenceException { |
519 | 518 |
super.loadFromState(state); |
520 | 519 |
|
521 |
|
|
522 | 520 |
} |
523 | 521 |
|
524 | 522 |
public void accept(Visitor visitor) throws BaseException { |
525 | 523 |
accept(visitor, 0); |
526 | 524 |
} |
527 | 525 |
|
528 |
public void accept(Visitor visitor, long firstValueIndex) |
|
526 |
public final void accept(Visitor visitor, long firstValueIndex)
|
|
529 | 527 |
throws BaseException { |
528 |
try { |
|
529 |
doAccept(visitor, firstValueIndex); |
|
530 |
} catch (VisitCanceledException ex) { |
|
531 |
// The visit has been cancelled by the visitor, so we finish here. |
|
532 |
LOG.debug( |
|
533 |
"The visit, beggining on position {}, has been cancelled " |
|
534 |
+ "by the visitor: {}", new Long(firstValueIndex), |
|
535 |
visitor); |
|
536 |
} |
|
537 |
} |
|
538 |
|
|
539 |
private void doAccept(Visitor visitor, long firstValueIndex) |
|
540 |
throws BaseException { |
|
530 | 541 |
DisposableIterator iterator = fastIterator(firstValueIndex); |
531 | 542 |
|
532 | 543 |
if (iterator != null) { |
... | ... | |
549 | 560 |
public static void registerPersistent() { |
550 | 561 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
551 | 562 |
DynStruct definition = manager.addDefinition( |
552 |
DefaultFeatureSelection.class, |
|
553 |
"DefaultFeatureSelection", |
|
554 |
"DefaultFeatureSelection Persistent definition", |
|
555 |
null, |
|
556 |
null |
|
557 |
); |
|
563 |
DefaultFeatureSelection.class, "DefaultFeatureSelection", |
|
564 |
"DefaultFeatureSelection Persistent definition", null, null); |
|
558 | 565 |
|
559 |
definition.extend( |
|
560 |
manager.getDefinition(DefaultFeatureReferenceSelection.DYNCLASS_PERSISTENT_NAME) |
|
561 |
); |
|
562 |
definition.addDynFieldMap("featureTypeCounts").setClassOfItems(Long.class).setMandatory(true); |
|
566 |
definition |
|
567 |
.extend(manager |
|
568 |
.getDefinition(DefaultFeatureReferenceSelection.DYNCLASS_PERSISTENT_NAME)); |
|
569 |
definition.addDynFieldMap("featureTypeCounts") |
|
570 |
.setClassOfItems(Long.class).setMandatory(true); |
|
563 | 571 |
|
564 | 572 |
} |
573 |
|
|
574 |
public Object clone() throws CloneNotSupportedException { |
|
575 |
DefaultFeatureSelection clone = (DefaultFeatureSelection) super.clone(); |
|
576 |
clone.featureTypeCounts = new HashMap(featureTypeCounts); |
|
577 |
return clone; |
|
578 |
} |
|
565 | 579 |
} |
Also available in: Unified diff