gvsig-geoprocess / org.gvsig.geoprocess / branches / refactor-2018 / org.gvsig.geoprocess / org.gvsig.geoprocess.lib / org.gvsig.geoprocess.lib.sextante / src / main / java / org / gvsig / geoprocess / lib / sextante / dataObjects / FeatureSetIRecordsetIterator.java @ 1055
History | View | Annotate | Download (2.92 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2012 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 2
|
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.geoprocess.lib.sextante.dataObjects; |
25 |
|
26 |
import java.util.ArrayList; |
27 |
import java.util.Iterator; |
28 |
|
29 |
import es.unex.sextante.dataObjects.IRecord; |
30 |
import es.unex.sextante.dataObjects.IRecordsetIterator; |
31 |
import es.unex.sextante.dataObjects.RecordImpl; |
32 |
|
33 |
import org.gvsig.fmap.dal.exception.DataException; |
34 |
import org.gvsig.fmap.dal.feature.Feature; |
35 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
36 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
37 |
import org.gvsig.fmap.dal.feature.FeatureType; |
38 |
import org.gvsig.tools.dispose.DisposableIterator; |
39 |
|
40 |
public class FeatureSetIRecordsetIterator implements IRecordsetIterator { |
41 |
|
42 |
private final FeatureSet featureSet; |
43 |
private DisposableIterator featureIterator;
|
44 |
|
45 |
FeatureSetIRecordsetIterator(final FeatureSet obj) throws DataException { |
46 |
|
47 |
featureSet = obj; |
48 |
try {
|
49 |
featureIterator = featureSet.fastIterator(); |
50 |
} catch (final DataException e) { |
51 |
throw e;
|
52 |
} |
53 |
|
54 |
} |
55 |
|
56 |
@Override
|
57 |
public boolean hasNext() { |
58 |
return featureIterator.hasNext();
|
59 |
} |
60 |
|
61 |
@Override
|
62 |
public IRecord next() {
|
63 |
final Feature feature = (Feature) featureIterator.next();
|
64 |
final FeatureType fType = feature.getType();
|
65 |
@SuppressWarnings("unchecked") |
66 |
final Iterator<FeatureAttributeDescriptor> descriptors = |
67 |
fType.iterator(); |
68 |
final ArrayList<Object> objects = new ArrayList<Object>(); |
69 |
while (descriptors.hasNext()) {
|
70 |
final FeatureAttributeDescriptor descriptor = descriptors.next();
|
71 |
objects.add(feature.get(descriptor.getName())); |
72 |
} |
73 |
|
74 |
final IRecord record = new RecordImpl(objects.toArray(new Object[0])); |
75 |
|
76 |
return record;
|
77 |
} |
78 |
|
79 |
@Override
|
80 |
public void close() { |
81 |
if (featureIterator != null) { |
82 |
featureIterator.dispose(); |
83 |
featureIterator = null;
|
84 |
} |
85 |
featureSet.dispose(); |
86 |
} |
87 |
|
88 |
} |