svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libDielmoOpenLiDAR / src / org / gvsig / fmap / dal / store / lidar / LiDARSetProvider.java @ 26737
History | View | Annotate | Download (5.35 KB)
1 | 26737 | ogarcia | package org.gvsig.fmap.dal.store.lidar; |
---|---|---|---|
2 | |||
3 | import java.util.Iterator; |
||
4 | import java.util.NoSuchElementException; |
||
5 | |||
6 | import org.gvsig.fmap.dal.exception.DataEvaluatorException; |
||
7 | import org.gvsig.fmap.dal.exception.DataException; |
||
8 | import org.gvsig.fmap.dal.exception.ReadRuntimeException; |
||
9 | import org.gvsig.fmap.dal.feature.Feature; |
||
10 | import org.gvsig.fmap.dal.feature.FeatureQuery; |
||
11 | import org.gvsig.fmap.dal.feature.FeatureType; |
||
12 | import org.gvsig.fmap.dal.feature.impl.DefaultFeature; |
||
13 | import org.gvsig.fmap.dal.feature.spi.FeatureData; |
||
14 | import org.gvsig.fmap.dal.feature.spi.FeatureSetProvider; |
||
15 | import org.gvsig.tools.evaluator.Evaluator; |
||
16 | import org.gvsig.tools.evaluator.EvaluatorData; |
||
17 | import org.gvsig.tools.evaluator.EvaluatorException; |
||
18 | |||
19 | public class LiDARSetProvider implements FeatureSetProvider { |
||
20 | |||
21 | private LiDARStoreProvider store;
|
||
22 | private FeatureQuery query;
|
||
23 | |||
24 | public LiDARSetProvider(LiDARStoreProvider liDARStoreProvider,
|
||
25 | FeatureQuery query) { |
||
26 | this.store = liDARStoreProvider;
|
||
27 | this.query = query;
|
||
28 | } |
||
29 | |||
30 | public boolean canFilter() { |
||
31 | return false; |
||
32 | } |
||
33 | |||
34 | public boolean canIterateFromIndex() { |
||
35 | return true; |
||
36 | } |
||
37 | |||
38 | public boolean canOrder() { |
||
39 | return false; |
||
40 | } |
||
41 | |||
42 | public Iterator fastIterator(long index) throws DataException { |
||
43 | return new FastLiDARIterator(this.store, this.query.getFeatureType(), |
||
44 | index); |
||
45 | } |
||
46 | |||
47 | public Iterator fastIterator() throws DataException { |
||
48 | return this.fastIterator(0); |
||
49 | } |
||
50 | |||
51 | public long getSize() throws DataException { |
||
52 | return this.store.getFeatureCount(); |
||
53 | } |
||
54 | |||
55 | public boolean isEmpty() throws DataException { |
||
56 | return this.store.getFeatureCount() > 0; |
||
57 | } |
||
58 | |||
59 | public Iterator iterator() throws DataException { |
||
60 | return this.iterator(0); |
||
61 | } |
||
62 | |||
63 | public Iterator iterator(long index) throws DataException { |
||
64 | return new LiDARIteratorScale(this.store, this.query, this.query.getFeatureType(), index); |
||
65 | } |
||
66 | |||
67 | |||
68 | private class LiDARIteratorScale implements Iterator { |
||
69 | protected long curIndex; |
||
70 | protected LiDARStoreProvider store;
|
||
71 | protected FeatureType featureType;
|
||
72 | private long count; |
||
73 | private Evaluator filter;
|
||
74 | FeatureQuery query; |
||
75 | protected boolean nextChecked; |
||
76 | private FeatureData current;
|
||
77 | |||
78 | public LiDARIteratorScale(LiDARStoreProvider store, FeatureQuery query,FeatureType featureType,
|
||
79 | long index) throws DataException { |
||
80 | |||
81 | this.store = store;
|
||
82 | this.featureType = featureType;
|
||
83 | this.curIndex = index;
|
||
84 | this.count = this.store.getFeatureCount(); |
||
85 | this.query = query;
|
||
86 | this.filter = query.getFilter();
|
||
87 | nextChecked=false;
|
||
88 | } |
||
89 | |||
90 | public boolean hasNext() { |
||
91 | |||
92 | if (nextChecked) {
|
||
93 | return curIndex < count;
|
||
94 | } |
||
95 | try {
|
||
96 | doNext(); |
||
97 | } catch( DataException e) {
|
||
98 | NullPointerException ex = new NullPointerException(); |
||
99 | ex.initCause(e); |
||
100 | throw ex;
|
||
101 | } |
||
102 | return curIndex < count;
|
||
103 | } |
||
104 | |||
105 | protected void doNext() throws DataException { |
||
106 | nextChecked = true;
|
||
107 | |||
108 | FeatureData featureData; |
||
109 | Feature feature; |
||
110 | long i=this.curIndex; |
||
111 | while (i<count) {
|
||
112 | featureData=this.createFeature();
|
||
113 | feature =store.getStoreServices().createFeature(featureData); |
||
114 | |||
115 | if (this.filter==null) { |
||
116 | this.current = featureData;
|
||
117 | return;
|
||
118 | } else{
|
||
119 | try {
|
||
120 | if(((Boolean) this.filter.evaluate((EvaluatorData)feature)).booleanValue()){ |
||
121 | this.current = featureData;
|
||
122 | return;
|
||
123 | } |
||
124 | } catch (EvaluatorException e) {
|
||
125 | // TODO Auto-generated catch block
|
||
126 | e.printStackTrace(); |
||
127 | } |
||
128 | } |
||
129 | i++; // este indice debe indicar el salto de puntos para implemetar la estrategia
|
||
130 | } |
||
131 | |||
132 | |||
133 | this.current = null; |
||
134 | } |
||
135 | |||
136 | |||
137 | public Object next() { |
||
138 | if (!hasNext()){
|
||
139 | throw new NoSuchElementException(); |
||
140 | } |
||
141 | try{
|
||
142 | FeatureData data = this.createFeature();
|
||
143 | curIndex++; |
||
144 | return data;
|
||
145 | } catch (DataException e){
|
||
146 | throw new ReadRuntimeException(this.store.getName(), e); |
||
147 | } |
||
148 | } |
||
149 | |||
150 | public void remove() { |
||
151 | throw new UnsupportedOperationException(); |
||
152 | |||
153 | } |
||
154 | |||
155 | protected FeatureData createFeature() throws DataException { |
||
156 | return this.store.getFeatureDataByIndex(curIndex, featureType); |
||
157 | } |
||
158 | |||
159 | } |
||
160 | |||
161 | |||
162 | |||
163 | private class LiDARIterator implements Iterator { |
||
164 | protected long curIndex; |
||
165 | protected LiDARStoreProvider store;
|
||
166 | protected FeatureType featureType;
|
||
167 | private long count; |
||
168 | |||
169 | |||
170 | |||
171 | public LiDARIterator(LiDARStoreProvider store, FeatureType featureType,
|
||
172 | long index) throws DataException { |
||
173 | |||
174 | this.store = store;
|
||
175 | this.featureType = featureType;
|
||
176 | this.curIndex = index;
|
||
177 | this.count = this.store.getFeatureCount(); |
||
178 | } |
||
179 | |||
180 | public boolean hasNext() { |
||
181 | return curIndex < count;
|
||
182 | } |
||
183 | |||
184 | public Object next() { |
||
185 | if (!hasNext()){
|
||
186 | throw new NoSuchElementException(); |
||
187 | } |
||
188 | try{
|
||
189 | FeatureData data = this.createFeature();
|
||
190 | curIndex++; |
||
191 | return data;
|
||
192 | } catch (DataException e){
|
||
193 | throw new ReadRuntimeException(this.store.getName(), e); |
||
194 | } |
||
195 | } |
||
196 | |||
197 | public void remove() { |
||
198 | throw new UnsupportedOperationException(); |
||
199 | |||
200 | } |
||
201 | |||
202 | protected FeatureData createFeature() throws DataException { |
||
203 | return this.store.getFeatureDataByIndex(curIndex, featureType); |
||
204 | } |
||
205 | |||
206 | } |
||
207 | |||
208 | private class FastLiDARIterator extends LiDARIterator { |
||
209 | public FastLiDARIterator(LiDARStoreProvider store,
|
||
210 | FeatureType featureType, long index) throws DataException { |
||
211 | super(store, featureType, index);
|
||
212 | this.curData = this.store.createFeatureData(featureType); |
||
213 | } |
||
214 | |||
215 | |||
216 | private FeatureData curData;
|
||
217 | |||
218 | |||
219 | protected FeatureData createFeature() throws DataException { |
||
220 | this.store.loadFeatureDataByIndex(curData, curIndex, featureType);
|
||
221 | return curData;
|
||
222 | } |
||
223 | } |
||
224 | |||
225 | } |