svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.impl / src / main / java / org / gvsig / fmap / dal / feature / impl / featureset / OrderedIterator.java @ 43020
History | View | Annotate | Download (2.98 KB)
1 | 40559 | jjdelcerro | /**
|
---|---|---|---|
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 | 40435 | jjdelcerro | package org.gvsig.fmap.dal.feature.impl.featureset; |
25 | |||
26 | import java.util.ArrayList; |
||
27 | import java.util.Collections; |
||
28 | import java.util.Iterator; |
||
29 | import java.util.List; |
||
30 | |||
31 | import org.gvsig.fmap.dal.exception.DataException; |
||
32 | import org.gvsig.tools.dispose.DisposableIterator; |
||
33 | import org.gvsig.fmap.dal.feature.Feature; |
||
34 | import org.gvsig.fmap.dal.feature.impl.DefaultFeature; |
||
35 | import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
||
36 | import org.gvsig.tools.exception.BaseException; |
||
37 | |||
38 | public class OrderedIterator extends DefaultIterator { |
||
39 | |||
40 | protected Feature lastFeature = null; |
||
41 | |||
42 | OrderedIterator(DefaultFeatureSet featureSet, Iterator iterator, long index) { |
||
43 | super(featureSet);
|
||
44 | // FIXME QUE PASA CON SIZE > Integer.MAX_VALUE ?????
|
||
45 | if (featureSet.orderedData == null) { |
||
46 | List data = new ArrayList(); |
||
47 | Object item;
|
||
48 | while (iterator.hasNext()) {
|
||
49 | item = iterator.next(); |
||
50 | if (item instanceof DefaultFeature) { |
||
51 | data.add(((DefaultFeature) item).getData()); |
||
52 | } else {
|
||
53 | data.add(item); |
||
54 | } |
||
55 | } |
||
56 | Collections.sort(data, new FeatureProviderComparator(featureSet.store, |
||
57 | featureSet.query.getOrder())); |
||
58 | featureSet.orderedData = data; |
||
59 | } |
||
60 | if (iterator instanceof DisposableIterator) { |
||
61 | ((DisposableIterator) iterator).dispose(); |
||
62 | } |
||
63 | iterator = null;
|
||
64 | |||
65 | if (index < Integer.MAX_VALUE) { |
||
66 | this.iterator = featureSet.orderedData.listIterator((int) index); |
||
67 | } else {
|
||
68 | this.iterator = featureSet.orderedData.iterator();
|
||
69 | this.skypto(index);
|
||
70 | } |
||
71 | } |
||
72 | |||
73 | public OrderedIterator(DefaultFeatureSet featureSet, long index) { |
||
74 | super(featureSet);
|
||
75 | if (index < Integer.MAX_VALUE) { |
||
76 | this.iterator = featureSet.orderedData.listIterator((int) index); |
||
77 | } else {
|
||
78 | this.iterator = featureSet.orderedData.iterator();
|
||
79 | this.skypto(index);
|
||
80 | } |
||
81 | } |
||
82 | |||
83 | public void remove() { |
||
84 | super.remove();
|
||
85 | this.iterator.remove();
|
||
86 | } |
||
87 | |||
88 | protected DefaultFeature createFeature(FeatureProvider fData)
|
||
89 | throws DataException {
|
||
90 | fData.setNew(false);
|
||
91 | return new DefaultFeature(fset.store, fData); |
||
92 | |||
93 | } |
||
94 | |||
95 | protected void doDispose() throws BaseException { |
||
96 | super.doDispose();
|
||
97 | lastFeature = null;
|
||
98 | } |
||
99 | } |