svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_dal / src / org / gvsig / fmap / dal / feature / spi / memory / MemoryFeatureSet.java @ 29326
History | View | Annotate | Download (2.81 KB)
1 |
package org.gvsig.fmap.dal.feature.spi.memory; |
---|---|
2 |
|
3 |
import java.util.Iterator; |
4 |
import java.util.List; |
5 |
|
6 |
import org.gvsig.fmap.dal.exception.DataException; |
7 |
import org.gvsig.fmap.dal.feature.DisposableIterator; |
8 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
9 |
import org.gvsig.fmap.dal.feature.FeatureType; |
10 |
import org.gvsig.fmap.dal.feature.spi.DefaultFeatureProvider; |
11 |
import org.gvsig.fmap.dal.feature.spi.FeatureSetProvider; |
12 |
|
13 |
public class MemoryFeatureSet implements FeatureSetProvider { |
14 |
|
15 |
AbstractMemoryStoreProvider store; |
16 |
FeatureType type; |
17 |
protected List data; |
18 |
|
19 |
public MemoryFeatureSet(AbstractMemoryStoreProvider store,
|
20 |
FeatureQuery query, FeatureType featureType, List data) {
|
21 |
this.store = store;
|
22 |
this.data = data;
|
23 |
/*
|
24 |
* Nota: Como no sabe filtrar ni ordenar ignora el query.
|
25 |
*/
|
26 |
|
27 |
/*
|
28 |
* Comproabar si los attributos solicitados son distintos
|
29 |
* a los originales.
|
30 |
*/
|
31 |
|
32 |
this.type = null; |
33 |
if (!featureType.equals(store.getStoreServices()
|
34 |
.getProviderFeatureType(featureType.getId()))) { |
35 |
this.type = featureType;
|
36 |
} |
37 |
} |
38 |
|
39 |
public boolean canFilter() { |
40 |
return false; |
41 |
} |
42 |
|
43 |
public boolean canOrder() { |
44 |
return false; |
45 |
} |
46 |
|
47 |
public boolean canIterateFromIndex() { |
48 |
return true; |
49 |
} |
50 |
|
51 |
public DisposableIterator fastIterator(long index) throws DataException { |
52 |
return iterator(0); |
53 |
} |
54 |
|
55 |
public DisposableIterator fastIterator() throws DataException { |
56 |
return iterator();
|
57 |
} |
58 |
|
59 |
public long getSize() throws DataException { |
60 |
return data.size();
|
61 |
} |
62 |
|
63 |
public boolean isEmpty() throws DataException { |
64 |
return data.size() < 1; |
65 |
} |
66 |
|
67 |
public DisposableIterator iterator() throws DataException { |
68 |
if (type == null) { |
69 |
return new DelegatedDisposableIterator(this.data.iterator()); |
70 |
} |
71 |
return new DelegatedDisposableIterator(this.data.iterator(), type); |
72 |
} |
73 |
|
74 |
public DisposableIterator iterator(long index) throws DataException { |
75 |
if (type == null) { |
76 |
return new DelegatedDisposableIterator(this.data |
77 |
.listIterator((int) index));
|
78 |
} |
79 |
return new DelegatedDisposableIterator(this.data |
80 |
.listIterator((int) index), type);
|
81 |
} |
82 |
|
83 |
public void dispose() { |
84 |
store = null;
|
85 |
} |
86 |
|
87 |
|
88 |
|
89 |
|
90 |
protected class DelegatedDisposableIterator implements DisposableIterator { |
91 |
private Iterator delegated; |
92 |
private FeatureType fType;
|
93 |
|
94 |
public DelegatedDisposableIterator(Iterator it) { |
95 |
this(it, null); |
96 |
} |
97 |
|
98 |
public DelegatedDisposableIterator(Iterator it, FeatureType featureType) { |
99 |
this.delegated = it;
|
100 |
this.fType = featureType;
|
101 |
|
102 |
} |
103 |
|
104 |
public void dispose() { |
105 |
this.delegated = null; |
106 |
} |
107 |
|
108 |
public boolean hasNext() { |
109 |
return delegated.hasNext();
|
110 |
} |
111 |
|
112 |
public Object next() { |
113 |
if (fType == null) { |
114 |
return delegated.next();
|
115 |
} else {
|
116 |
return new MemoryFeatureProviderAttributeMapper( |
117 |
(DefaultFeatureProvider) delegated.next(), |
118 |
this.fType);
|
119 |
} |
120 |
|
121 |
} |
122 |
|
123 |
public void remove() { |
124 |
throw new UnsupportedOperationException(); |
125 |
} |
126 |
|
127 |
} |
128 |
|
129 |
} |