root / branches / v2_0_0_prep / libraries / libFMap_dal / src / org / gvsig / fmap / dal / feature / spi / memory / MemoryFeatureSet.java @ 38608
History | View | Annotate | Download (4.62 KB)
1 | 29391 | jmvivo | /* 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 | * 2009 IVER T.I {{Task}}
|
||
26 | */
|
||
27 | 24496 | jmvivo | package org.gvsig.fmap.dal.feature.spi.memory; |
28 | 23875 | jjdelcerro | |
29 | 29326 | jmvivo | import java.util.Iterator; |
30 | import java.util.List; |
||
31 | |||
32 | 24505 | jmvivo | import org.gvsig.fmap.dal.exception.DataException; |
33 | 24496 | jmvivo | import org.gvsig.fmap.dal.feature.FeatureQuery; |
34 | 27274 | jmvivo | import org.gvsig.fmap.dal.feature.FeatureType; |
35 | 31022 | cordinyana | import org.gvsig.fmap.dal.feature.exception.IteratorIndexTooBigException; |
36 | import org.gvsig.fmap.dal.feature.spi.AbstractFeatureProviderIterator; |
||
37 | import org.gvsig.fmap.dal.feature.spi.AbstractFeatureSetProvider; |
||
38 | import org.gvsig.fmap.dal.feature.spi.AbstractFeatureStoreProvider; |
||
39 | 29326 | jmvivo | import org.gvsig.fmap.dal.feature.spi.DefaultFeatureProvider; |
40 | 24496 | jmvivo | import org.gvsig.fmap.dal.feature.spi.FeatureSetProvider; |
41 | 31284 | cordinyana | import org.gvsig.tools.dispose.Disposable; |
42 | import org.gvsig.tools.exception.BaseException; |
||
43 | 23875 | jjdelcerro | |
44 | 29391 | jmvivo | /**
|
45 | * Implementation of {@link FeatureSetProvider} used in
|
||
46 | * {@link AbstractMemoryStoreProvider}
|
||
47 | *
|
||
48 | */
|
||
49 | 31022 | cordinyana | public class MemoryFeatureSet extends AbstractFeatureSetProvider { |
50 | 23875 | jjdelcerro | |
51 | 29326 | jmvivo | protected List data; |
52 | 23875 | jjdelcerro | |
53 | 38608 | jjdelcerro | public MemoryFeatureSet(AbstractFeatureStoreProvider store,
|
54 | 29326 | jmvivo | FeatureQuery query, FeatureType featureType, List data) {
|
55 | 31022 | cordinyana | super(store, query,
|
56 | /*
|
||
57 | * Comprobar si los attributos solicitados son distintos a los
|
||
58 | * originales.
|
||
59 | */
|
||
60 | featureType.equals(store.getStoreServices() |
||
61 | .getProviderFeatureType(featureType.getId())) ? null
|
||
62 | : featureType); |
||
63 | 29326 | jmvivo | this.data = data;
|
64 | 23875 | jjdelcerro | /*
|
65 | * Nota: Como no sabe filtrar ni ordenar ignora el query.
|
||
66 | */
|
||
67 | } |
||
68 | |||
69 | public boolean canFilter() { |
||
70 | return false; |
||
71 | } |
||
72 | |||
73 | public boolean canOrder() { |
||
74 | return false; |
||
75 | } |
||
76 | |||
77 | public boolean canIterateFromIndex() { |
||
78 | return true; |
||
79 | } |
||
80 | |||
81 | public long getSize() throws DataException { |
||
82 | 29326 | jmvivo | return data.size();
|
83 | 23875 | jjdelcerro | } |
84 | |||
85 | public boolean isEmpty() throws DataException { |
||
86 | 29391 | jmvivo | return data.isEmpty();
|
87 | 23875 | jjdelcerro | } |
88 | |||
89 | 31284 | cordinyana | protected void doDispose() throws BaseException { |
90 | 31630 | jpiera | //data only has to be deleted when the store.dispose method is called
|
91 | //data.clear();
|
||
92 | 23875 | jjdelcerro | } |
93 | |||
94 | 31022 | cordinyana | protected AbstractFeatureProviderIterator createFastIterator(long index) |
95 | throws DataException {
|
||
96 | return createIterator(index);
|
||
97 | 23875 | jjdelcerro | } |
98 | 27672 | jmvivo | |
99 | 31022 | cordinyana | protected AbstractFeatureProviderIterator createIterator(long index) |
100 | throws DataException {
|
||
101 | if (index > 0 && index >= data.size()) { |
||
102 | throw new IteratorIndexTooBigException(index, data.size()); |
||
103 | } |
||
104 | Iterator iter =
|
||
105 | index <= 0 ? data.iterator() : data.listIterator((int) index); |
||
106 | if (getFeatureType() == null) { |
||
107 | return new DelegatedDisposableIterator(getStore(), iter); |
||
108 | } else {
|
||
109 | return new DelegatedDisposableWrappedIterator(getStore(), iter, |
||
110 | getFeatureType()); |
||
111 | } |
||
112 | 27672 | jmvivo | } |
113 | 29326 | jmvivo | |
114 | 31022 | cordinyana | protected class DelegatedDisposableIterator extends |
115 | AbstractFeatureProviderIterator { |
||
116 | 29326 | jmvivo | private Iterator delegated; |
117 | |||
118 | 31022 | cordinyana | public DelegatedDisposableIterator(AbstractFeatureStoreProvider store,
|
119 | Iterator it) {
|
||
120 | super(store);
|
||
121 | 29326 | jmvivo | this.delegated = it;
|
122 | } |
||
123 | |||
124 | 31022 | cordinyana | protected void internalDispose() { |
125 | 29326 | jmvivo | this.delegated = null; |
126 | } |
||
127 | |||
128 | 31022 | cordinyana | protected boolean internalHasNext() { |
129 | 29326 | jmvivo | return delegated.hasNext();
|
130 | } |
||
131 | |||
132 | 31022 | cordinyana | protected Object internalNext() { |
133 | 29391 | jmvivo | return delegated.next();
|
134 | } |
||
135 | |||
136 | public void remove() { |
||
137 | throw new UnsupportedOperationException(); |
||
138 | } |
||
139 | 31284 | cordinyana | |
140 | protected void doDispose() throws BaseException { |
||
141 | if (delegated instanceof Disposable) { |
||
142 | ((Disposable) delegated).dispose(); |
||
143 | } |
||
144 | } |
||
145 | 29391 | jmvivo | } |
146 | |||
147 | protected class DelegatedDisposableWrappedIterator extends |
||
148 | DelegatedDisposableIterator { |
||
149 | private FeatureType fType;
|
||
150 | |||
151 | 31022 | cordinyana | public DelegatedDisposableWrappedIterator(
|
152 | AbstractFeatureStoreProvider store, Iterator it,
|
||
153 | 29391 | jmvivo | FeatureType featureType) { |
154 | 31022 | cordinyana | super(store, it);
|
155 | 29391 | jmvivo | this.fType = featureType;
|
156 | } |
||
157 | |||
158 | 31022 | cordinyana | protected Object internalNext() { |
159 | DefaultFeatureProvider feature = |
||
160 | (DefaultFeatureProvider) super.internalNext();
|
||
161 | 29326 | jmvivo | if (fType == null) { |
162 | 29391 | jmvivo | return feature;
|
163 | 29326 | jmvivo | } else {
|
164 | 31022 | cordinyana | return new MemoryFeatureProviderAttributeMapper(feature, |
165 | 29326 | jmvivo | this.fType);
|
166 | } |
||
167 | |||
168 | } |
||
169 | } |
||
170 | 31022 | cordinyana | } |