Statistics
| Revision:

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 / AbstractFeatureSet.java @ 43089

History | View | Annotate | Download (3.52 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.impl.featureset;
25

    
26
import org.gvsig.fmap.dal.DataStore;
27
import org.gvsig.fmap.dal.exception.DataException;
28
import org.gvsig.fmap.dal.feature.Feature;
29
import org.gvsig.fmap.dal.feature.FeatureSet;
30
import org.gvsig.fmap.dal.feature.FeatureStore;
31
import org.gvsig.fmap.dal.feature.impl.dynobjectutils.DynObjectSetFeatureSetFacade;
32
import org.gvsig.tools.dispose.DisposableIterator;
33
import org.gvsig.tools.dispose.DisposeUtils;
34
import org.gvsig.tools.dynobject.DynObjectSet;
35
import org.gvsig.tools.exception.BaseException;
36
import org.gvsig.tools.visitor.VisitCanceledException;
37
import org.gvsig.tools.visitor.Visitor;
38
import org.gvsig.tools.visitor.impl.AbstractIndexedVisitable;
39

    
40

    
41
public abstract class AbstractFeatureSet 
42
    extends AbstractIndexedVisitable 
43
    implements FeatureSet {
44

    
45
    public abstract FeatureStore getFeatureStore();
46
    
47

    
48
    @Override
49
    protected void doAccept(Visitor visitor, long firstValueIndex)
50
        throws VisitCanceledException, BaseException {
51
        DisposableIterator iterator = fastIterator(firstValueIndex);
52
        if( iterator != null ) {
53
            try {
54
                while (iterator.hasNext()) {
55
                    Feature feature = (Feature) iterator.next();
56
                    visitor.visit(feature);
57
                }
58
            } finally {
59
                DisposeUtils.disposeQuietly(iterator);
60
            }
61
        }
62
    }
63
    
64
    @Override
65
    public Feature first() {
66
        DisposableIterator it = null;
67
        try {
68
            it = this.iterator();
69
            if( it == null ) {
70
                return null;
71
            }
72
            Feature f = (Feature) it.next();
73
            return f;
74
        } finally {
75
            DisposeUtils.disposeQuietly(it);
76
        }
77
    }
78

    
79
    @Override
80
    public boolean isEmpty() throws DataException {
81
        return this.getSize() == 0;
82
    }
83

    
84
    @Override
85
    public DisposableIterator fastIterator() throws DataException {
86
        return this.fastIterator(0);
87
    }   
88

    
89
    @Override
90
    public DisposableIterator iterator() {
91
        try {
92
            return this.fastIterator(0);
93
        } catch (DataException ex) {
94
            throw new RuntimeException("Can't obtain itertor.",ex);
95
        }
96
    }
97
    
98
    @Override
99
    public DynObjectSet getDynObjectSet() {
100
        return this.getDynObjectSet(true);
101
    }
102

    
103
    @Override
104
    public DynObjectSet getDynObjectSet(boolean fast) {
105
        return new DynObjectSetFeatureSetFacade(this, this.getFeatureStore(), fast);
106
    }
107

    
108
    @Override
109
    public boolean isFromStore(DataStore store) {
110
        return this.getFeatureStore().equals(store);
111
    }    
112
}