root / branches / v2_0_0_prep / libraries / libDielmoOpenLiDAR / src / org / gvsig / fmap / dal / store / lidar / LiDARSetProvider.java @ 26288
History | View | Annotate | Download (2.9 KB)
1 |
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.DataException; |
7 |
import org.gvsig.fmap.dal.exception.ReadRuntimeException; |
8 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
9 |
import org.gvsig.fmap.dal.feature.FeatureType; |
10 |
import org.gvsig.fmap.dal.feature.spi.FeatureData; |
11 |
import org.gvsig.fmap.dal.feature.spi.FeatureSetProvider; |
12 |
|
13 |
public class LiDARSetProvider implements FeatureSetProvider { |
14 |
|
15 |
private LiDARStoreProvider store;
|
16 |
private FeatureQuery query;
|
17 |
|
18 |
public LiDARSetProvider(LiDARStoreProvider liDARStoreProvider,
|
19 |
FeatureQuery query) { |
20 |
this.store = liDARStoreProvider;
|
21 |
this.query = query;
|
22 |
} |
23 |
|
24 |
public boolean canFilter() { |
25 |
return false; |
26 |
} |
27 |
|
28 |
public boolean canIterateFromIndex() { |
29 |
return true; |
30 |
} |
31 |
|
32 |
public boolean canOrder() { |
33 |
return false; |
34 |
} |
35 |
|
36 |
public Iterator fastIterator(long index) throws DataException { |
37 |
return new FastLiDARIterator(this.store, this.query.getFeatureType(), |
38 |
index); |
39 |
} |
40 |
|
41 |
public Iterator fastIterator() throws DataException { |
42 |
return this.fastIterator(0); |
43 |
} |
44 |
|
45 |
public long getSize() throws DataException { |
46 |
return this.store.getFeatureCount(); |
47 |
} |
48 |
|
49 |
public boolean isEmpty() throws DataException { |
50 |
return this.store.getFeatureCount() > 0; |
51 |
} |
52 |
|
53 |
public Iterator iterator() throws DataException { |
54 |
return this.iterator(0); |
55 |
} |
56 |
|
57 |
public Iterator iterator(long index) throws DataException { |
58 |
return new LiDARIterator(this.store, this.query.getFeatureType(), index); |
59 |
} |
60 |
|
61 |
private class LiDARIterator implements Iterator { |
62 |
protected long curIndex; |
63 |
protected LiDARStoreProvider store;
|
64 |
protected FeatureType featureType;
|
65 |
private long count; |
66 |
|
67 |
|
68 |
|
69 |
public LiDARIterator(LiDARStoreProvider store, FeatureType featureType,
|
70 |
long index) throws DataException { |
71 |
|
72 |
this.store = store;
|
73 |
this.featureType = featureType;
|
74 |
this.curIndex = index;
|
75 |
this.count = this.store.getFeatureCount(); |
76 |
} |
77 |
|
78 |
public boolean hasNext() { |
79 |
return curIndex < count;
|
80 |
} |
81 |
|
82 |
public Object next() { |
83 |
if (!hasNext()){
|
84 |
throw new NoSuchElementException(); |
85 |
} |
86 |
try{
|
87 |
FeatureData data = this.createFeature();
|
88 |
curIndex++; |
89 |
return data;
|
90 |
} catch (DataException e){
|
91 |
throw new ReadRuntimeException(this.store.getName(), e); |
92 |
} |
93 |
} |
94 |
|
95 |
public void remove() { |
96 |
throw new UnsupportedOperationException(); |
97 |
|
98 |
} |
99 |
|
100 |
protected FeatureData createFeature() throws DataException { |
101 |
return this.store.getFeatureDataByIndex(curIndex, featureType); |
102 |
} |
103 |
|
104 |
} |
105 |
|
106 |
private class FastLiDARIterator extends LiDARIterator { |
107 |
public FastLiDARIterator(LiDARStoreProvider store,
|
108 |
FeatureType featureType, long index) throws DataException { |
109 |
super(store, featureType, index);
|
110 |
this.curData = this.store.createFeatureData(featureType); |
111 |
} |
112 |
|
113 |
|
114 |
private FeatureData curData;
|
115 |
|
116 |
|
117 |
protected FeatureData createFeature() throws DataException { |
118 |
this.store.loadFeatureDataByIndex(curData, curIndex, featureType);
|
119 |
return curData;
|
120 |
} |
121 |
} |
122 |
|
123 |
} |