Revision 24017 branches/v2_0_0_prep/libraries/libFMap_data/src/org/gvsig/fmap/data/feature/impl/DefaultFeatureIndex.java
DefaultFeatureIndex.java | ||
---|---|---|
2 | 2 |
* |
3 | 3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
4 | 4 |
* of the Valencian Government (CIT) |
5 |
*
|
|
5 |
* |
|
6 | 6 |
* This program is free software; you can redistribute it and/or |
7 | 7 |
* modify it under the terms of the GNU General Public License |
8 | 8 |
* as published by the Free Software Foundation; either version 2 |
9 | 9 |
* of the License, or (at your option) any later version. |
10 |
*
|
|
10 |
* |
|
11 | 11 |
* This program is distributed in the hope that it will be useful, |
12 | 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | 14 |
* GNU General Public License for more details. |
15 |
*
|
|
15 |
* |
|
16 | 16 |
* You should have received a copy of the GNU General Public License |
17 | 17 |
* along with this program; if not, write to the Free Software |
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 | 19 |
* MA 02110-1301, USA. |
20 |
*
|
|
20 |
* |
|
21 | 21 |
*/ |
22 | 22 |
|
23 | 23 |
/* |
24 | 24 |
* AUTHORS (In addition to CIT): |
25 | 25 |
* 2008 {{Company}} {{Task}} |
26 | 26 |
*/ |
27 |
|
|
28 | 27 |
|
28 |
|
|
29 | 29 |
package org.gvsig.fmap.data.feature.impl; |
30 | 30 |
|
31 | 31 |
import java.util.Iterator; |
... | ... | |
44 | 44 |
import org.gvsig.fmap.data.feature.spi.FeatureStoreProviderServices; |
45 | 45 |
import org.gvsig.fmap.data.feature.spi.index.FeatureIndexProvider; |
46 | 46 |
import org.gvsig.fmap.data.feature.spi.index.FeatureIndexProviderServices; |
47 |
import org.gvsig.tools.exception.NotYetImplemented; |
|
47 | 48 |
|
48 | 49 |
/** |
49 |
* Abstract index provider.
|
|
50 |
*
|
|
50 |
* Abstract index provider. |
|
51 |
* |
|
51 | 52 |
* @author jyarza |
52 | 53 |
* |
53 | 54 |
*/ |
... | ... | |
61 | 62 |
private final FeatureIndexProvider indexProvider; |
62 | 63 |
|
63 | 64 |
public DefaultFeatureIndex(FeatureStoreProviderServices featureStore, FeatureType featureType, FeatureIndexProvider indexProvider, String attributeName, String indexName) { |
64 |
if (featureStore == null) throw new IllegalArgumentException("featureStore cannot be null."); |
|
65 |
if (featureType == null) throw new IllegalArgumentException("featureType cannot be null."); |
|
66 |
if (attributeName == null) throw new IllegalArgumentException("attributeName cannot be null."); |
|
67 |
if (indexName == null) throw new IllegalArgumentException("indexName cannot be null."); |
|
68 |
|
|
65 |
if (featureStore == null) { |
|
66 |
throw new IllegalArgumentException("featureStore cannot be null."); |
|
67 |
} |
|
68 |
if (featureType == null) { |
|
69 |
throw new IllegalArgumentException("featureType cannot be null."); |
|
70 |
} |
|
71 |
if (attributeName == null) { |
|
72 |
throw new IllegalArgumentException("attributeName cannot be null."); |
|
73 |
} |
|
74 |
if (indexName == null) { |
|
75 |
throw new IllegalArgumentException("indexName cannot be null."); |
|
76 |
} |
|
77 |
|
|
69 | 78 |
if (featureStore.getProvider().getFeatureReferenceIdType() != DataTypes.INT) { |
70 | 79 |
throw new IllegalArgumentException(); |
71 | 80 |
} |
72 |
|
|
81 |
|
|
73 | 82 |
FeatureAttributeDescriptor attr = featureType.getAttributeDescriptor(attributeName); |
74 |
if (attr == null) |
|
83 |
if (attr == null) {
|
|
75 | 84 |
throw new IllegalArgumentException("Attribute " + attributeName +" not found in FeatureType " + featureType.toString()); |
76 |
|
|
85 |
} |
|
86 |
|
|
77 | 87 |
this.featureStore = featureStore; |
78 | 88 |
this.featureType = featureType; |
79 | 89 |
this.attributeName = attributeName; |
... | ... | |
97 | 107 |
public final String getName() { |
98 | 108 |
return name; |
99 | 109 |
} |
100 |
|
|
110 |
|
|
101 | 111 |
public final String getAttributeName() { |
102 | 112 |
return attributeName; |
103 | 113 |
} |
104 |
|
|
114 |
|
|
105 | 115 |
public final int getDataType() { |
106 | 116 |
return dataType; |
107 | 117 |
} |
... | ... | |
135 | 145 |
} |
136 | 146 |
} |
137 | 147 |
|
138 |
/** Performs a search in the index. The type of search depends on the passed data |
|
139 |
* |
|
140 |
* TODO explain |
|
148 |
public FeatureSetProvider getMatchFeatureSet(Object value) |
|
149 |
throws DataIndexException { |
|
150 |
return new IndexFeatureSet(this, new DefaultLongList(indexProvider |
|
151 |
.match(value))); |
|
152 |
} |
|
153 |
|
|
154 |
public FeatureSetProvider getRangeFeatureSet(Object value1, Object value2) |
|
155 |
throws DataIndexException { |
|
156 |
return new IndexFeatureSet(this, new DefaultLongList(indexProvider |
|
157 |
.match(value1, value2))); |
|
158 |
} |
|
159 |
|
|
160 |
public FeatureSetProvider getNearestFeatureSet(int count, Object value) |
|
161 |
throws DataIndexException { |
|
162 |
return new IndexFeatureSet(this, new DefaultLongList(indexProvider |
|
163 |
.nearest(count, value))); |
|
164 |
} |
|
165 |
|
|
166 |
public FeatureSetProvider getNearestFeatureSet(int count, int tolerance, |
|
167 |
Object value) throws DataIndexException { |
|
168 |
throw new NotYetImplemented(); |
|
169 |
} |
|
170 |
|
|
171 |
/** |
|
172 |
* Performs a search in the index. The type of search depends on the passed |
|
173 |
* data |
|
174 |
* |
|
175 |
* @deprecated |
|
141 | 176 |
* */ |
142 | 177 |
public FeatureSetProvider getFeatureSet(String attrName, Object[] data) throws DataIndexException { |
143 | 178 |
return new IndexFeatureSet(this, new DefaultLongList(this.match(data))); |
144 | 179 |
} |
145 |
|
|
146 |
/** Performs a search in the index and returns a list with the elements that match the parameters */ |
|
180 |
|
|
181 |
/** |
|
182 |
* Performs a search in the index and returns a list with the elements that |
|
183 |
* match the parameters |
|
184 |
* |
|
185 |
* @deprecated |
|
186 |
*/ |
|
147 | 187 |
private List match(Object[] values) throws DataIndexException { |
148 |
|
|
149 |
if (values == null) throw new IllegalArgumentException("values can't be null."); |
|
150 |
if (values.length == 0) throw new IllegalArgumentException("values must contain at least 1 value."); |
|
151 |
|
|
188 |
|
|
189 |
if (values == null) { |
|
190 |
throw new IllegalArgumentException("values can't be null."); |
|
191 |
} |
|
192 |
if (values.length == 0) { |
|
193 |
throw new IllegalArgumentException("values must contain at least 1 value."); |
|
194 |
} |
|
195 |
|
|
152 | 196 |
List result = null; |
153 | 197 |
if (values.length == 1) { |
154 | 198 |
result = indexProvider.match(values[0]); |
... | ... | |
157 | 201 |
if (values[0] instanceof Integer && !(values[1] instanceof Integer)) { |
158 | 202 |
result = indexProvider.nearest(((Integer)values[0]).intValue(), values[1]); |
159 | 203 |
} else { |
160 |
result = indexProvider.match(values[0], values[1]);
|
|
161 |
}
|
|
204 |
result = indexProvider.match(values[0], values[1]); |
|
205 |
} |
|
162 | 206 |
} |
163 | 207 |
return result; |
164 | 208 |
} |
165 |
|
|
166 |
|
|
209 |
|
|
210 |
|
|
167 | 211 |
public void initialize() { |
168 | 212 |
indexProvider.initialize(); |
169 | 213 |
} |
170 |
|
|
171 | 214 |
|
172 |
|
|
173 | 215 |
public void delete(Object o, FeatureReference fref) { |
174 | 216 |
indexProvider.delete(o, fref); |
175 |
|
|
176 | 217 |
} |
177 | 218 |
|
178 | 219 |
public void delete(Feature feat) { |
179 | 220 |
// TODO Auto-generated method stub |
180 |
|
|
181 | 221 |
} |
182 | 222 |
|
183 | 223 |
public void delete(FeatureSet data) throws DataIndexException { |
184 | 224 |
// TODO Auto-generated method stub |
185 |
|
|
225 |
|
|
186 | 226 |
} |
187 | 227 |
|
188 | 228 |
public String[] getAttributeNames() { |
... | ... | |
190 | 230 |
return null; |
191 | 231 |
} |
192 | 232 |
|
193 |
|
|
194 | 233 |
/** |
195 | 234 |
* FIXME ver que hacemos con estas constantes |
196 |
* Convenience constants to identify sets of providers classified by supported data types.
|
|
235 |
* Convenience constants to identify sets of providers classified by supported data types. |
|
197 | 236 |
*/ |
198 | 237 |
public interface PROVIDERS { |
199 |
|
|
238 |
|
|
200 | 239 |
public interface GEOMETRY { |
201 | 240 |
public static final String GT2_QUADTREE = "QuadTreeGt2Factory"; |
202 | 241 |
public static final String JSI_RTREE = "RTreeJsiFactory"; |
... | ... | |
204 | 243 |
public static final String SPATIALINDEX_RTREE = "RTreeSptLibFactory"; |
205 | 244 |
public static final String DEFAULT = GT2_QUADTREE; |
206 | 245 |
} |
207 |
|
|
246 |
|
|
208 | 247 |
public interface DATE { |
209 | 248 |
// added as example |
210 | 249 |
} |
211 |
|
|
250 |
|
|
212 | 251 |
public interface INTEGER { |
213 | 252 |
// added as example |
214 |
} |
|
215 |
} |
|
216 |
|
|
253 |
} |
|
254 |
} |
|
255 |
|
|
256 |
|
|
217 | 257 |
} |
218 | 258 |
|
Also available in: Unified diff