root / branches / v2_0_0_prep / libraries / libFMap_dal / src / org / gvsig / fmap / dal / feature / impl / IndexFeatureSet.java @ 24496
History | View | Annotate | Download (4.24 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2008 {{Company}} {{Task}}
|
26 |
*/
|
27 |
|
28 |
|
29 |
package org.gvsig.fmap.dal.feature.impl; |
30 |
|
31 |
import java.util.Iterator; |
32 |
|
33 |
import org.gvsig.fmap.dal.exceptions.DataException; |
34 |
import org.gvsig.fmap.dal.exceptions.ReadRuntimeException; |
35 |
import org.gvsig.fmap.dal.feature.Feature; |
36 |
import org.gvsig.fmap.dal.feature.FeatureReference; |
37 |
import org.gvsig.fmap.dal.feature.spi.FeatureData; |
38 |
import org.gvsig.fmap.dal.feature.spi.FeatureReferenceProviderServices; |
39 |
import org.gvsig.fmap.dal.feature.spi.FeatureSetProvider; |
40 |
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider; |
41 |
import org.gvsig.fmap.dal.feature.spi.LongList; |
42 |
import org.gvsig.fmap.dal.feature.spi.index.FeatureIndexProviderServices; |
43 |
|
44 |
|
45 |
public class IndexFeatureSet implements FeatureSetProvider { |
46 |
|
47 |
LongList featureReferences = null;
|
48 |
FeatureStoreProvider store = null;
|
49 |
FeatureIndexProviderServices index = null;
|
50 |
|
51 |
public class IndexIterator implements Iterator { |
52 |
Iterator it = null; |
53 |
|
54 |
public IndexIterator(Iterator it) { |
55 |
this.it = it;
|
56 |
} |
57 |
|
58 |
public boolean hasNext() { |
59 |
return it.hasNext();
|
60 |
} |
61 |
|
62 |
public Object next() { |
63 |
Object oid = it.next();
|
64 |
Feature f = null;
|
65 |
try {
|
66 |
FeatureReference ref = new DefaultFeatureReference(store
|
67 |
.getStoreServices(), oid); |
68 |
f = index.getFeatureStore().getFeatureByReference(ref); |
69 |
} catch (DataException e) {
|
70 |
throw new ReadRuntimeException(index.getFeatureStore().getName(), e); |
71 |
} |
72 |
return f;
|
73 |
} |
74 |
|
75 |
public void remove() { |
76 |
throw new UnsupportedOperationException(); |
77 |
} |
78 |
} |
79 |
|
80 |
public class FastIndexIterator implements Iterator { |
81 |
Iterator it = null; |
82 |
FeatureData data = null;
|
83 |
Feature feat = null;
|
84 |
|
85 |
public FastIndexIterator(Iterator it) throws DataException { |
86 |
this.it = it;
|
87 |
data = store.createFeatureData(index.getFeatureType()); |
88 |
feat = index.getFeatureStore().createFeature(data); |
89 |
} |
90 |
|
91 |
public boolean hasNext() { |
92 |
return it.hasNext();
|
93 |
} |
94 |
|
95 |
public Object next() { |
96 |
Object oid = it.next();
|
97 |
try {
|
98 |
FeatureReference ref = new DefaultFeatureReference(store
|
99 |
.getStoreServices(), oid); |
100 |
data = store |
101 |
.getFeatureDataByReference((FeatureReferenceProviderServices) ref); |
102 |
} catch (DataException e) {
|
103 |
throw new ReadRuntimeException(index.getFeatureStore().getName(), e); |
104 |
} |
105 |
return data;
|
106 |
} |
107 |
|
108 |
public void remove() { |
109 |
throw new UnsupportedOperationException(); |
110 |
} |
111 |
} |
112 |
|
113 |
public IndexFeatureSet(FeatureIndexProviderServices index, LongList featureReferences) {
|
114 |
this.featureReferences = featureReferences;
|
115 |
this.store = index.getFeatureStore().getProvider();
|
116 |
this.index = index;
|
117 |
} |
118 |
|
119 |
public boolean canFilter() { |
120 |
return false; |
121 |
} |
122 |
|
123 |
public boolean canIterateFromIndex() { |
124 |
return true; |
125 |
} |
126 |
|
127 |
public boolean canOrder() { |
128 |
return false; |
129 |
} |
130 |
|
131 |
public Iterator fastIterator(long index) throws DataException { |
132 |
return new FastIndexIterator(this.featureReferences.iterator((int)index)); |
133 |
} |
134 |
|
135 |
public Iterator fastIterator() throws DataException { |
136 |
return new FastIndexIterator(this.featureReferences.iterator()); |
137 |
} |
138 |
|
139 |
public long getSize() throws DataException { |
140 |
return featureReferences.getSize();
|
141 |
} |
142 |
|
143 |
public boolean isEmpty() throws DataException { |
144 |
return featureReferences.isEmpty();
|
145 |
} |
146 |
|
147 |
public Iterator iterator() throws DataException { |
148 |
return new IndexIterator(this.featureReferences.iterator()); |
149 |
} |
150 |
|
151 |
public Iterator iterator(long index) throws DataException { |
152 |
return new FastIndexIterator(this.featureReferences.iterator((int)index)); |
153 |
} |
154 |
|
155 |
} |
156 |
|