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 @ 43628

History | View | Annotate | Download (4.3 KB)

1 43089 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
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 43358 jjdelcerro
import org.slf4j.Logger;
40
import org.slf4j.LoggerFactory;
41 43089 jjdelcerro
42
43
public abstract class AbstractFeatureSet
44
    extends AbstractIndexedVisitable
45
    implements FeatureSet {
46
47 43358 jjdelcerro
    protected static final Logger LOG = LoggerFactory.getLogger(AbstractFeatureSet.class);
48
49 43089 jjdelcerro
    public abstract FeatureStore getFeatureStore();
50
51
    @Override
52 43358 jjdelcerro
    public final void accept(Visitor visitor, long firstValueIndex, long elements) throws BaseException {
53
        try {
54
            doAccept(visitor, firstValueIndex, elements);
55
        } catch (VisitCanceledException ex) {
56
            // The visit has been cancelled by the visitor, so we finish here.
57
            LOG.debug(
58
                    "The visit, beggining on position {}, has been cancelled "
59
                    + "by the visitor: {}", new Long(firstValueIndex),
60
                    visitor);
61
        }
62
    }
63
64
    @Override
65 43089 jjdelcerro
    protected void doAccept(Visitor visitor, long firstValueIndex)
66
        throws VisitCanceledException, BaseException {
67 43358 jjdelcerro
        doAccept(visitor, firstValueIndex, 0);
68
    }
69
70
    protected void doAccept(Visitor visitor, long firstValueIndex, long elements)
71
        throws VisitCanceledException, BaseException {
72
        DisposableIterator iterator = fastIterator(firstValueIndex, elements);
73
74
        try {
75
            while (iterator.hasNext()) {
76
                Feature feature = (Feature) iterator.next();
77
                visitor.visit(feature);
78 43089 jjdelcerro
            }
79 43358 jjdelcerro
        } finally {
80
            iterator.dispose();
81 43089 jjdelcerro
        }
82
    }
83 43358 jjdelcerro
84 43089 jjdelcerro
    @Override
85
    public Feature first() {
86
        DisposableIterator it = null;
87
        try {
88
            it = this.iterator();
89
            if( it == null ) {
90
                return null;
91
            }
92
            Feature f = (Feature) it.next();
93
            return f;
94
        } finally {
95
            DisposeUtils.disposeQuietly(it);
96
        }
97
    }
98
99
    @Override
100
    public boolean isEmpty() throws DataException {
101
        return this.getSize() == 0;
102
    }
103
104
    @Override
105
    public DisposableIterator fastIterator() throws DataException {
106
        return this.fastIterator(0);
107
    }
108
109
    @Override
110
    public DisposableIterator iterator() {
111
        try {
112
            return this.fastIterator(0);
113
        } catch (DataException ex) {
114
            throw new RuntimeException("Can't obtain itertor.",ex);
115
        }
116
    }
117
118
    @Override
119
    public DynObjectSet getDynObjectSet() {
120
        return this.getDynObjectSet(true);
121
    }
122
123
    @Override
124
    public DynObjectSet getDynObjectSet(boolean fast) {
125
        return new DynObjectSetFeatureSetFacade(this, this.getFeatureStore(), fast);
126
    }
127
128
    @Override
129
    public boolean isFromStore(DataStore store) {
130
        return this.getFeatureStore().equals(store);
131
    }
132
}