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