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

History | View | Annotate | Download (4.75 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
    @Override
93
        public final DisposableIterator fastIterator() throws DataException {
94
                return fastIterator(0);
95
        }
96

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

    
102
    @Override
103
    public final DisposableIterator fastIterator(long index, long elements) throws DataException {
104
                return createFastIterator(index, elements);
105
        }
106

    
107
    @Override
108
        public final DisposableIterator iterator() throws DataException {
109
                return iterator(0);
110
        }
111

    
112
        public final DisposableIterator iterator(long index) throws DataException {
113
                return createIterator(index);
114
        }
115

    
116
    @Override
117
        public final DisposableIterator iterator(long index, long elements) throws DataException {
118
                return createIterator(index, elements);
119
        }
120

    
121
        /**
122
         * Creates a new {@link Iterator}, begginning at the specified data index.
123
         * 
124
         * @param index
125
         *            the first element position to be returned by the
126
         *            {@link Iterator}
127
         * @return a new {@link Iterator}
128
         * @throws DataException
129
         *             if there is an error creating the {@link Iterator}
130
         */
131
        protected abstract AbstractFeatureProviderIterator createIterator(long index)
132
                        throws DataException;
133

    
134
        protected AbstractFeatureProviderIterator createIterator(long index, long elements)
135
                        throws DataException {
136
            return createIterator(index);
137
    }
138

    
139
    /**
140
         * Creates a new fast {@link Iterator}, begginning at the specified data
141
         * index. By fast this means the object instances of data (
142
         * {@link FeatureProvider}) may be reused between the
143
         * {@link Iterator#next()} method invocations.
144
         * 
145
         * @param index
146
         *            the first element position to be returned by the
147
         *            {@link Iterator}
148
         * @return a new {@link Iterator}
149
         * @throws DataException
150
         *             if there is an error creating the {@link Iterator}
151
         */
152
        protected abstract AbstractFeatureProviderIterator createFastIterator(
153
                        long index) throws DataException;
154
        
155
        protected AbstractFeatureProviderIterator createFastIterator(
156
                        long index, long elements) throws DataException {
157
            return createFastIterator(index);
158
        }
159
}