root / branches / v2_0_0_prep / libraries / libFMap_data / src / org / gvsig / fmap / data / feature / impl / AbstractFeatureCollection.java @ 23754
History | View | Annotate | Download (2.36 KB)
1 |
package org.gvsig.fmap.data.feature.impl; |
---|---|
2 |
|
3 |
import java.util.ConcurrentModificationException; |
4 |
import java.util.Iterator; |
5 |
|
6 |
import org.gvsig.fmap.data.exceptions.ReadException; |
7 |
import org.gvsig.fmap.data.feature.Feature; |
8 |
import org.gvsig.fmap.data.feature.FeatureCollection; |
9 |
import org.gvsig.fmap.data.feature.FeatureStoreNotification; |
10 |
import org.gvsig.tools.exception.BaseException; |
11 |
import org.gvsig.tools.observer.Observable; |
12 |
import org.gvsig.tools.observer.Observer; |
13 |
import org.gvsig.tools.visitor.Visitor; |
14 |
|
15 |
public abstract class AbstractFeatureCollection implements FeatureCollection, Observer{ |
16 |
|
17 |
protected boolean modified=false; |
18 |
public void update(Observable obsevable, Object notification) { |
19 |
if (modified){
|
20 |
return;
|
21 |
} |
22 |
String type = ((FeatureStoreNotification)notification).getType();
|
23 |
if (type.equalsIgnoreCase(FeatureStoreNotification.AFTER_INSERT) ||
|
24 |
type.equalsIgnoreCase(FeatureStoreNotification.AFTER_DELETE) || |
25 |
type.equalsIgnoreCase(FeatureStoreNotification.RESOURCE_CHANGED)){ |
26 |
modified=true;
|
27 |
} |
28 |
} |
29 |
|
30 |
/*
|
31 |
* (non-Javadoc)
|
32 |
* @see org.gvsig.fmap.data.feature.visitor.FeaturesVisitable#accept(org.gvsig.fmap.data.feature.visitor.FeaturesVisitor)
|
33 |
*/
|
34 |
public void accept(Visitor visitor) throws BaseException { |
35 |
Iterator iterator=iterator();
|
36 |
|
37 |
while (iterator.hasNext()) {
|
38 |
Feature feature = (Feature) iterator.next(); |
39 |
visitor.visit(feature); |
40 |
} |
41 |
} |
42 |
|
43 |
protected void checkModified() { |
44 |
if (modified) {
|
45 |
throw new ConcurrentModificationException("FeatureCollection modified"); |
46 |
} |
47 |
} |
48 |
|
49 |
public boolean isEmpty() { |
50 |
checkModified(); |
51 |
return (size()==0); |
52 |
} |
53 |
|
54 |
public Feature getFeature(int index) throws ReadException { |
55 |
// TODO
|
56 |
throw new UnsupportedOperationException(); |
57 |
// return null;
|
58 |
} |
59 |
|
60 |
|
61 |
public Iterator iterator() { |
62 |
return internalIterator(0); |
63 |
} |
64 |
|
65 |
public Iterator iterator(int index) { |
66 |
if (index < 0 || index > getSize()) { |
67 |
throw new IndexOutOfBoundsException("The index (" + index |
68 |
+ ") is less than 0 or bigger than "
|
69 |
+ "the size of the collection: " + size());
|
70 |
} |
71 |
|
72 |
return internalIterator(index);
|
73 |
} |
74 |
|
75 |
/**
|
76 |
* Child classes must implement the method to return an iterator starting at
|
77 |
* the given index, but without the validation of the index.
|
78 |
*
|
79 |
* @see DataCollection#iterator(int).
|
80 |
*/
|
81 |
protected abstract Iterator internalIterator(int index); |
82 |
|
83 |
|
84 |
|
85 |
} |