Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.spi / src / main / java / org / gvsig / fmap / dal / feature / spi / AbstractFeatureSetProvider.java @ 40767

History | View | Annotate | Download (4.07 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.spi;
25

    
26
import java.util.Iterator;
27

    
28
import org.gvsig.fmap.dal.exception.DataException;
29
import org.gvsig.fmap.dal.feature.FeatureQuery;
30
import org.gvsig.fmap.dal.feature.FeatureType;
31
import org.gvsig.tools.dispose.DisposableIterator;
32
import org.gvsig.tools.dispose.impl.AbstractDisposable;
33

    
34
/**
35
 * Base implementation for {@link FeatureSetProvider}s, adding some utility
36
 * methods.
37
 * 
38
 * @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
39
 */
40
public abstract class AbstractFeatureSetProvider extends AbstractDisposable
41
                implements FeatureSetProvider {
42

    
43
        private final AbstractFeatureStoreProvider store;
44
        private final FeatureQuery query;
45
        private final FeatureType featureType;
46

    
47
        /**
48
         * Creates a new {@link FeatureSetProvider}.
49
         * 
50
         * @param store
51
         *            the underlying {@link FeatureStoreProvider} to get the data
52
         *            from
53
         * @param query
54
         *            used to create the {@link FeatureSetProvider}
55
         * @param featureType
56
         *            the type of feature to get
57
         */
58
        public AbstractFeatureSetProvider(AbstractFeatureStoreProvider store,
59
                        FeatureQuery query, FeatureType featureType) {
60
                this.store = store;
61
                this.query = query;
62
                this.featureType = featureType;
63
        }
64

    
65
        /**
66
         * Return the {@link AbstractFeatureStoreProvider}.
67
         * 
68
         * @return the store
69
         */
70
        protected AbstractFeatureStoreProvider getStore() {
71
                return store;
72
        }
73

    
74
        /**
75
         * Returns the {@link FeatureQuery} used to create this set.
76
         * 
77
         * @return the query
78
         */
79
        protected FeatureQuery getQuery() {
80
                return query;
81
        }
82

    
83
        /**
84
         * Returns the type of features to load.
85
         * 
86
         * @return the featureType
87
         */
88
        protected FeatureType getFeatureType() {
89
                return featureType;
90
        }
91

    
92
        public final DisposableIterator fastIterator() throws DataException {
93
                return fastIterator(0);
94
        }
95

    
96
        public final DisposableIterator fastIterator(long index)
97
                        throws DataException {
98
                return createFastIterator(index);
99
        }
100

    
101
        public final DisposableIterator iterator() throws DataException {
102
                return iterator(0);
103
        }
104

    
105
        public final DisposableIterator iterator(long index) throws DataException {
106
                return createIterator(index);
107
        }
108

    
109
        /**
110
         * Creates a new {@link Iterator}, begginning at the specified data index.
111
         * 
112
         * @param index
113
         *            the first element position to be returned by the
114
         *            {@link Iterator}
115
         * @return a new {@link Iterator}
116
         * @throws DataException
117
         *             if there is an error creating the {@link Iterator}
118
         */
119
        protected abstract AbstractFeatureProviderIterator createIterator(long index)
120
                        throws DataException;
121

    
122
        /**
123
         * Creates a new fast {@link Iterator}, begginning at the specified data
124
         * index. By fast this means the object instances of data (
125
         * {@link FeatureProvider}) may be reused between the
126
         * {@link Iterator#next()} method invocations.
127
         * 
128
         * @param index
129
         *            the first element position to be returned by the
130
         *            {@link Iterator}
131
         * @return a new {@link Iterator}
132
         * @throws DataException
133
         *             if there is an error creating the {@link Iterator}
134
         */
135
        protected abstract AbstractFeatureProviderIterator createFastIterator(
136
                        long index) throws DataException;
137
}