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