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