svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.impl / src / main / java / org / gvsig / fmap / dal / feature / impl / indexes / memorybasictypes / MemoryBasicTypesIndexProvider.java @ 44927
History | View | Annotate | Download (4.39 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
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 3
|
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 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.fmap.dal.feature.impl.indexes.memorybasictypes; |
25 |
|
26 |
import java.util.List; |
27 |
import java.util.TreeMap; |
28 |
|
29 |
import org.gvsig.fmap.dal.exception.DataException; |
30 |
import org.gvsig.fmap.dal.feature.exception.FeatureIndexException; |
31 |
import org.gvsig.fmap.dal.feature.spi.FeatureReferenceProviderServices; |
32 |
import org.gvsig.fmap.dal.feature.spi.index.AbstractFeatureIndexProvider; |
33 |
import org.gvsig.tools.ToolsLocator; |
34 |
import org.gvsig.tools.dataTypes.Coercion; |
35 |
import org.gvsig.tools.dataTypes.CoercionException; |
36 |
|
37 |
public class MemoryBasicTypesIndexProvider<T> extends AbstractFeatureIndexProvider { |
38 |
|
39 |
private TreeMap<T,ListOfLong> index = null; |
40 |
private final Class<T> classt; |
41 |
private final Coercion coercion; |
42 |
|
43 |
public MemoryBasicTypesIndexProvider(Class<T> classt) { |
44 |
this.classt = classt;
|
45 |
this.coercion = ToolsLocator.getDataTypesManager().getDataType(classt).getCoercion();
|
46 |
} |
47 |
|
48 |
@Override
|
49 |
public void initialize() { |
50 |
try {
|
51 |
this.index = new TreeMap<>(); |
52 |
} catch (Exception e) { |
53 |
throw new RuntimeException(); |
54 |
} |
55 |
} |
56 |
|
57 |
@Override
|
58 |
public void delete(Object key_o, FeatureReferenceProviderServices fref) { |
59 |
T key_s = (T) key_o; |
60 |
long oid = (Long) fref.getOID(); |
61 |
ListOfLong items = this.index.get(key_s);
|
62 |
if( items == null ) { |
63 |
return;
|
64 |
} |
65 |
items.remove(oid); |
66 |
if( items.isEmpty() ) {
|
67 |
this.index.remove(key_s);
|
68 |
} |
69 |
} |
70 |
|
71 |
@Override
|
72 |
public void insert(Object key_o, FeatureReferenceProviderServices fref) { |
73 |
if (key_o == null) { |
74 |
return;
|
75 |
} |
76 |
T key_s = (T) key_o; |
77 |
long oid = (Long) fref.getOID(); |
78 |
ListOfLong items = this.index.get(key_s);
|
79 |
if( items == null ) { |
80 |
items = new ArrayListOfLong();
|
81 |
this.index.put(key_s, items);
|
82 |
} |
83 |
items.add(oid); |
84 |
} |
85 |
|
86 |
@Override
|
87 |
public List match(Object key_o) throws FeatureIndexException { |
88 |
T key_s; |
89 |
try {
|
90 |
key_s = (T) this.coercion.coerce(key_o);
|
91 |
} catch (CoercionException ex) {
|
92 |
return null; |
93 |
} |
94 |
if( !this.index.containsKey(key_s) ) { |
95 |
return null; |
96 |
} |
97 |
ListOfLong items = this.index.get(key_s);
|
98 |
if( items == null ) { |
99 |
return null; |
100 |
} |
101 |
return items;
|
102 |
} |
103 |
|
104 |
public List match(Object min, Object max) { |
105 |
throw new UnsupportedOperationException( |
106 |
"Can't perform this kind of search.");
|
107 |
} |
108 |
|
109 |
@Override
|
110 |
public List nearest(int count, Object value) throws FeatureIndexException { |
111 |
throw new UnsupportedOperationException( |
112 |
"Can't perform this kind of search.");
|
113 |
} |
114 |
|
115 |
@Override
|
116 |
public boolean isMatchSupported() { |
117 |
return true; |
118 |
} |
119 |
|
120 |
@Override
|
121 |
public boolean isNearestSupported() { |
122 |
return false; |
123 |
} |
124 |
|
125 |
@Override
|
126 |
public boolean isNearestToleranceSupported() { |
127 |
return false; |
128 |
} |
129 |
|
130 |
@Override
|
131 |
public boolean isRangeSupported() { |
132 |
return false; |
133 |
} |
134 |
|
135 |
@Override
|
136 |
public List nearest(int count, Object value, Object tolerance) |
137 |
throws FeatureIndexException {
|
138 |
throw new UnsupportedOperationException(); |
139 |
} |
140 |
|
141 |
@Override
|
142 |
public List range(Object value1, Object value2) |
143 |
throws FeatureIndexException {
|
144 |
throw new UnsupportedOperationException(); |
145 |
} |
146 |
|
147 |
@Override
|
148 |
public void clear() throws DataException { |
149 |
this.index.clear();
|
150 |
} |
151 |
} |