svn-gvsig-desktop / trunk / libraries / libDataSourceBaseDrivers / src / org / gvsig / data / datastores / vectorial / file / dbf / DBFFeatureCollectionWithFeatureID.java @ 20414
History | View | Annotate | Download (4.38 KB)
1 | 19844 | vcaballero | package org.gvsig.data.datastores.vectorial.file.dbf; |
---|---|---|---|
2 | 19401 | vcaballero | |
3 | import java.util.ArrayList; |
||
4 | import java.util.Collection; |
||
5 | 19448 | jmvivo | import java.util.Comparator; |
6 | 19401 | vcaballero | import java.util.Iterator; |
7 | 19448 | jmvivo | import java.util.TreeSet; |
8 | 19401 | vcaballero | |
9 | import org.gvsig.data.ComplexObservable; |
||
10 | 19609 | jmvivo | import org.gvsig.data.exception.ReadException; |
11 | 19466 | vcaballero | import org.gvsig.data.vectorial.AbstractFeatureCollection; |
12 | 19401 | vcaballero | import org.gvsig.data.vectorial.IFeature; |
13 | import org.gvsig.data.vectorial.IFeatureCollection; |
||
14 | import org.gvsig.data.vectorial.IFeatureID; |
||
15 | import org.gvsig.data.vectorial.IFeatureType; |
||
16 | 20414 | vcaballero | import org.gvsig.data.vectorial.IsNotFeatureSettingException; |
17 | 19448 | jmvivo | import org.gvsig.data.vectorial.expansionadapter.FeatureManager; |
18 | import org.gvsig.data.vectorial.order.FeatureComparator; |
||
19 | 19401 | vcaballero | |
20 | 19448 | jmvivo | |
21 | //FIXME: OJO Excepciones
|
||
22 | 19466 | vcaballero | public class DBFFeatureCollectionWithFeatureID extends AbstractFeatureCollection { |
23 | 19401 | vcaballero | protected ComplexObservable observable = new ComplexObservable(); |
24 | 19448 | jmvivo | protected Collection featureIDs;//<IFeatureID> |
25 | 19401 | vcaballero | protected IFeatureType featureType;
|
26 | |||
27 | 19736 | vcaballero | public DBFFeatureCollectionWithFeatureID(FeatureManager fm,DBFStore store,IFeatureType type, String filter,String Order) throws ReadException { |
28 | 19401 | vcaballero | this.featureType=type;
|
29 | 19736 | vcaballero | intilizeFeatureIDs(fm, store, filter, Order); |
30 | 19401 | vcaballero | } |
31 | 19448 | jmvivo | |
32 | 19736 | vcaballero | protected void intilizeFeatureIDs(FeatureManager fm,DBFStore store, String filter,String order) throws ReadException { |
33 | 19658 | vcaballero | try{
|
34 | 19448 | jmvivo | if (order == null){ |
35 | if (filter == null){ |
||
36 | featureIDs = new ArrayList(); // Si queremos optimizar deberiamos inicializar |
||
37 | // el tama?o
|
||
38 | } else {
|
||
39 | featureIDs = new ArrayList(); |
||
40 | } |
||
41 | } else {
|
||
42 | Comparator comparator = new FeatureComparator(this.featureType,order); |
||
43 | featureIDs = new TreeSet(comparator); |
||
44 | } |
||
45 | 19736 | vcaballero | IFeatureCollection coll = new DBFFeatureCollection(fm,store,this.featureType,filter); |
46 | 19448 | jmvivo | Iterator iter = coll.iterator();
|
47 | while (iter.hasNext()){
|
||
48 | IFeature feature =(IFeature)iter.next(); |
||
49 | featureIDs.add(feature.getID()); |
||
50 | } |
||
51 | 19658 | vcaballero | }catch (Exception e) { |
52 | throw new ReadException("DBFFeatureCollection",e); |
||
53 | } |
||
54 | 19448 | jmvivo | } |
55 | |||
56 | 19401 | vcaballero | public int size() { |
57 | return featureIDs.size();
|
||
58 | } |
||
59 | |||
60 | public boolean isEmpty() { |
||
61 | return featureIDs.isEmpty();
|
||
62 | } |
||
63 | |||
64 | public boolean contains(Object o) { |
||
65 | 19448 | jmvivo | if (o instanceof IFeature){ |
66 | featureIDs.contains(((IFeature)o).getID()); |
||
67 | } |
||
68 | 19401 | vcaballero | return featureIDs.contains(o);
|
69 | } |
||
70 | |||
71 | public Iterator iterator() { |
||
72 | 19448 | jmvivo | DBFFIDIterator dbfIter=new DBFFIDIterator(featureIDs.iterator());
|
73 | 19401 | vcaballero | return dbfIter;
|
74 | } |
||
75 | |||
76 | public Object[] toArray() { |
||
77 | 19448 | jmvivo | ArrayList features= new ArrayList(); |
78 | Iterator iterator= this.iterator(); |
||
79 | while(iterator.hasNext()){
|
||
80 | IFeature feature=(IFeature)iterator.next(); |
||
81 | features.add(feature); |
||
82 | } |
||
83 | return features.toArray();
|
||
84 | 19401 | vcaballero | } |
85 | |||
86 | public Object[] toArray(Object[] a) { |
||
87 | 19448 | jmvivo | ArrayList features= new ArrayList(); |
88 | Iterator iterator= this.iterator(); |
||
89 | while(iterator.hasNext()){
|
||
90 | IFeature feature=(IFeature)iterator.next(); |
||
91 | features.add(feature); |
||
92 | } |
||
93 | return features.toArray(a);
|
||
94 | 19401 | vcaballero | } |
95 | |||
96 | public boolean add(Object o) { |
||
97 | 19448 | jmvivo | throw new UnsupportedOperationException(); |
98 | 19401 | vcaballero | } |
99 | |||
100 | public boolean remove(Object o) { |
||
101 | 19448 | jmvivo | throw new UnsupportedOperationException(); |
102 | 19401 | vcaballero | } |
103 | |||
104 | public boolean containsAll(Collection c) { |
||
105 | 19448 | jmvivo | Iterator iter = c.iterator();
|
106 | while (iter.hasNext()){
|
||
107 | if (!this.contains(iter.next())){ |
||
108 | return false; |
||
109 | } |
||
110 | } |
||
111 | return true; |
||
112 | 19401 | vcaballero | } |
113 | |||
114 | public boolean addAll(Collection c) { |
||
115 | 19448 | jmvivo | throw new UnsupportedOperationException(); |
116 | 19401 | vcaballero | } |
117 | |||
118 | public boolean removeAll(Collection c) { |
||
119 | 19448 | jmvivo | throw new UnsupportedOperationException(); |
120 | 19401 | vcaballero | } |
121 | |||
122 | public boolean retainAll(Collection c) { |
||
123 | 19448 | jmvivo | throw new UnsupportedOperationException(); |
124 | 19401 | vcaballero | } |
125 | |||
126 | public void clear() { |
||
127 | 19448 | jmvivo | throw new UnsupportedOperationException(); |
128 | 19401 | vcaballero | } |
129 | |||
130 | 19448 | jmvivo | private class DBFFIDIterator implements Iterator{ |
131 | private Iterator iter; |
||
132 | |||
133 | public DBFFIDIterator(Iterator iter){ |
||
134 | this.iter=iter;
|
||
135 | 19401 | vcaballero | } |
136 | public boolean hasNext() { |
||
137 | 19448 | jmvivo | return iter.hasNext();
|
138 | 19401 | vcaballero | } |
139 | |||
140 | public Object next() { |
||
141 | 19448 | jmvivo | IFeatureID fid= (IFeatureID)iter.next(); |
142 | 19609 | jmvivo | IFeature feature; |
143 | try {
|
||
144 | feature = fid.getFeature(featureType); |
||
145 | } catch (ReadException e) {
|
||
146 | throw new RuntimeException(e); |
||
147 | 20414 | vcaballero | } catch (IsNotFeatureSettingException e) {
|
148 | throw new RuntimeException(e); |
||
149 | 19609 | jmvivo | } |
150 | 19401 | vcaballero | return feature;
|
151 | } |
||
152 | |||
153 | public void remove() { |
||
154 | 19448 | jmvivo | throw new UnsupportedOperationException(); |
155 | 19401 | vcaballero | } |
156 | |||
157 | } |
||
158 | |||
159 | 19966 | jmvivo | public void dispose() { |
160 | observable.deleteObservers(); |
||
161 | this.observable = null; |
||
162 | this.featureIDs.clear();
|
||
163 | this.featureIDs= null; |
||
164 | this.featureType = null; |
||
165 | |||
166 | } |
||
167 | |||
168 | 19401 | vcaballero | } |