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