Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libDielmoOpenLiDAR / src / org / gvsig / fmap / dal / store / lidar / LiDARSetProvider.java @ 29289

History | View | Annotate | Download (5.63 KB)

1
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
import org.gvsig.fmap.dal.feature.DisposableIterator;
8
import org.gvsig.fmap.dal.feature.Feature;
9
import org.gvsig.fmap.dal.feature.FeatureQuery;
10
import org.gvsig.fmap.dal.feature.FeatureType;
11
import org.gvsig.fmap.dal.feature.spi.FeatureProvider;
12
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
        private FeatureType featureType;
22

    
23
        public LiDARSetProvider(LiDARStoreProvider liDARStoreProvider,
24
                        FeatureQuery query, FeatureType featureType) throws DataException {
25
                this.store = liDARStoreProvider;
26
                this.query = query;
27
                this.featureType = featureType;
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 DisposableIterator fastIterator(long index) throws DataException {
43
                return new FastLiDARIterator(this.store, this.featureType,
44
                                index);
45
        }
46

    
47
        public DisposableIterator 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 DisposableIterator iterator() throws DataException {
60
                return this.iterator(0);
61
        }
62

    
63
        public DisposableIterator iterator(long index) throws DataException {
64
                return new LiDARIteratorScale(this.store, this.query,
65
                                this.featureType,
66
                                index);
67
        }
68

    
69

    
70
        private class LiDARIteratorScale implements DisposableIterator {
71
                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
                private FeatureProvider current;
79

    
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

    
94
                        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

    
107
                protected void doNext() throws DataException {
108
                        nextChecked = true;
109

    
110
                        FeatureProvider featureData;
111
                        Feature feature;
112
                        long i=this.curIndex;
113
                        while (i<count) {
114
                                featureData=this.createFeature();
115
                                feature =store.getStoreServices().createFeature(featureData);
116

    
117
                                if (this.filter==null) {
118
                                        this.current = featureData;
119
                                        return;
120
                                } else{
121
                                        try {
122
                                                if(((Boolean) this.filter.evaluate((EvaluatorData)feature)).booleanValue()){
123
                                                        this.current = featureData;
124
                                                        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

    
134

    
135
                        this.current = null;
136
                }
137

    
138

    
139
                public Object next() {
140
                        if (!hasNext()){
141
                                throw new NoSuchElementException();
142
                        }
143
                        try{
144
                                FeatureProvider data = this.createFeature();
145
                                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
                protected FeatureProvider createFeature() throws DataException {
158
                        return this.store.getFeatureDataByIndex(curIndex, featureType);
159
                }
160

    
161
                public void dispose() {
162
                        // TODO Auto-generated method stub
163

    
164
                }
165

    
166
        }
167

    
168

    
169

    
170
        private class LiDARIterator implements DisposableIterator {
171
                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
                                FeatureProvider data = this.createFeature();
197
                                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
                protected FeatureProvider createFeature() throws DataException {
210
                        return this.store.getFeatureDataByIndex(curIndex, featureType);
211
                }
212

    
213
                public void dispose() {
214
                        // TODO Auto-generated method stub
215

    
216
                }
217

    
218
        }
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
                        this.curData = this.store.createFeatureData(featureType);
225
                }
226

    
227

    
228
                private FeatureProvider curData;
229

    
230

    
231
                protected FeatureProvider createFeature() throws DataException {
232
                        this.store.loadFeatureDataByIndex(curData, curIndex, featureType);
233
                        return curData;
234
                }
235
        }
236

    
237
        public void dispose() {
238
                // TODO Auto-generated method stub
239

    
240
        }
241

    
242
}