Statistics
| Revision:

gvsig-geoprocess / org.gvsig.geoprocess / trunk / org.gvsig.geoprocess / org.gvsig.geoprocess.lib / org.gvsig.geoprocess.lib.sextante / src / main / java / org / gvsig / geoprocess / lib / sextante / dataObjects / FeatureSetIRecordsetIterator.java @ 237

History | View | Annotate | Download (2.75 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
package org.gvsig.geoprocess.lib.sextante.dataObjects;
22

    
23
import java.util.ArrayList;
24
import java.util.Iterator;
25

    
26
import es.unex.sextante.dataObjects.IRecord;
27
import es.unex.sextante.dataObjects.IRecordsetIterator;
28
import es.unex.sextante.dataObjects.RecordImpl;
29

    
30
import org.gvsig.fmap.dal.exception.DataException;
31
import org.gvsig.fmap.dal.feature.Feature;
32
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
33
import org.gvsig.fmap.dal.feature.FeatureSet;
34
import org.gvsig.fmap.dal.feature.FeatureType;
35
import org.gvsig.tools.dispose.DisposableIterator;
36

    
37
public class FeatureSetIRecordsetIterator implements IRecordsetIterator {
38

    
39
    private final FeatureSet featureSet;
40
    private DisposableIterator featureIterator;
41

    
42
    FeatureSetIRecordsetIterator(final FeatureSet obj) throws DataException {
43

    
44
        featureSet = obj;
45
        try {
46
            featureIterator = featureSet.fastIterator();
47
        } catch (final DataException e) {
48
            throw e;
49
        }
50

    
51
    }
52

    
53
    public boolean hasNext() {
54
        return featureIterator.hasNext();
55
    }
56

    
57
    public IRecord next() {
58
        final Feature feature = (Feature) featureIterator.next();
59
        final FeatureType fType = feature.getType();
60
        @SuppressWarnings("unchecked")
61
        final Iterator<FeatureAttributeDescriptor> descriptors =
62
            fType.iterator();
63
        final ArrayList<Object> objects = new ArrayList<Object>();
64
        while (descriptors.hasNext()) {
65
            final FeatureAttributeDescriptor descriptor = descriptors.next();
66
            objects.add(feature.get(descriptor.getName()));
67
        }
68

    
69
        final IRecord record = new RecordImpl(objects.toArray(new Object[0]));
70

    
71
        return record;
72
    }
73

    
74
    public void close() {
75
        if (featureIterator != null) {
76
            featureIterator.dispose();
77
            featureIterator = null;
78
        }
79
        featureSet.dispose();
80
    }
81

    
82
}