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 @ 44158
History | View | Annotate | Download (3.77 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 |
|
34 |
public class MemoryBasicTypesIndexProvider<T> extends AbstractFeatureIndexProvider { |
35 |
|
36 |
private TreeMap<T,ListOfLong> index = null; |
37 |
|
38 |
public MemoryBasicTypesIndexProvider() {
|
39 |
|
40 |
} |
41 |
|
42 |
public void initialize() { |
43 |
try {
|
44 |
this.index = new TreeMap<>(); |
45 |
} catch (Exception e) { |
46 |
throw new RuntimeException(); |
47 |
} |
48 |
} |
49 |
|
50 |
public void delete(Object key_o, FeatureReferenceProviderServices fref) { |
51 |
T key_s = (T) key_o; |
52 |
long oid = (Long) fref.getOID(); |
53 |
ListOfLong items = this.index.get(key_s);
|
54 |
if( items == null ) { |
55 |
return;
|
56 |
} |
57 |
items.remove(oid); |
58 |
if( items.isEmpty() ) {
|
59 |
this.index.remove(key_s);
|
60 |
} |
61 |
} |
62 |
|
63 |
public void insert(Object key_o, FeatureReferenceProviderServices fref) { |
64 |
if (key_o == null) { |
65 |
return;
|
66 |
} |
67 |
T key_s = (T) key_o; |
68 |
long oid = (Long) fref.getOID(); |
69 |
ListOfLong items = this.index.get(key_s);
|
70 |
if( items == null ) { |
71 |
items = new ArrayListOfLong();
|
72 |
this.index.put(key_s, items);
|
73 |
} |
74 |
items.add(oid); |
75 |
} |
76 |
|
77 |
public List match(Object key_o) throws FeatureIndexException { |
78 |
T key_s = (T) key_o; |
79 |
if( !this.index.containsKey(key_s) ) { |
80 |
return null; |
81 |
} |
82 |
ListOfLong items = this.index.get(key_s);
|
83 |
if( items == null ) { |
84 |
return null; |
85 |
} |
86 |
return items;
|
87 |
} |
88 |
|
89 |
public List match(Object min, Object max) { |
90 |
throw new UnsupportedOperationException( |
91 |
"Can't perform this kind of search.");
|
92 |
} |
93 |
|
94 |
public List nearest(int count, Object value) throws FeatureIndexException { |
95 |
throw new UnsupportedOperationException( |
96 |
"Can't perform this kind of search.");
|
97 |
} |
98 |
|
99 |
public boolean isMatchSupported() { |
100 |
return true; |
101 |
} |
102 |
|
103 |
public boolean isNearestSupported() { |
104 |
return false; |
105 |
} |
106 |
|
107 |
public boolean isNearestToleranceSupported() { |
108 |
return false; |
109 |
} |
110 |
|
111 |
public boolean isRangeSupported() { |
112 |
return false; |
113 |
} |
114 |
|
115 |
public List nearest(int count, Object value, Object tolerance) |
116 |
throws FeatureIndexException {
|
117 |
throw new UnsupportedOperationException(); |
118 |
} |
119 |
|
120 |
public List range(Object value1, Object value2) |
121 |
throws FeatureIndexException {
|
122 |
throw new UnsupportedOperationException(); |
123 |
} |
124 |
|
125 |
public void clear() throws DataException { |
126 |
this.index.clear();
|
127 |
} |
128 |
} |