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