Revision 47199 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.file/org.gvsig.fmap.dal.file.csv/src/main/java/org/gvsig/fmap/dal/store/csv/CSVSetProvider.java

View differences:

CSVSetProvider.java
23 23
 */
24 24
package org.gvsig.fmap.dal.store.csv;
25 25

  
26
import java.util.Iterator;
26 27
import java.util.List;
27 28
import java.util.NoSuchElementException;
28 29

  
......
85 86
        protected long index;
86 87
        protected FeatureType type;
87 88
        protected long count;
89
        protected final FeatureQuery query;
90
        protected Iterator spatialIndexIt;
88 91

  
89
        public CSVIterator(CSVStoreProvider store, FeatureType type,
92
        public CSVIterator(CSVStoreProvider store, FeatureQuery query, FeatureType type,
90 93
                long startOn) throws DataException {
91 94
            super(store);
92 95
            this.index = startOn;
93 96
            this.type = type;
97
            this.query = query;
94 98
            this.count = store.getFeatureCount();
99
            if( this.query!=null ) {
100
                this.spatialIndexIt = createSpatialIterator(
101
                        store.getFeatureStore().getDefaultFeatureTypeQuietly(), 
102
                        query, 
103
                        store.getSpatialIndex()
104
                );
105
            }
95 106
        }
96 107

  
97 108
        @Override
109
        protected CSVStoreProvider getFeatureStoreProvider() {
110
            return (CSVStoreProvider) super.getFeatureStoreProvider(); 
111
        }
112

  
113
        @Override
98 114
        protected boolean internalHasNext() {
115
            if( this.spatialIndexIt != null ) {
116
                return this.spatialIndexIt.hasNext();
117
            }
99 118
            return this.count > index;
100 119
        }
101 120

  
102 121
        @Override
103 122
        protected FeatureProvider internalNext() {
104
            if (index >= this.count) {
105
                throw new NoSuchElementException();
106
            }
107 123
            CSVFeatureProvider data = new CSVFeatureProvider(getStore(), type);
108
            data.setOID(index++);
124
            if( this.spatialIndexIt != null ) {
125
                Object oid = this.spatialIndexIt.next();                
126
                data.setOID(oid);
127
            } else {
128
                if (index >= this.count) {
129
                    throw new NoSuchElementException();
130
                }
131
                data.setOID(index++);
132
            }   
109 133
            return data;
110 134
        }
111 135

  
......
128 152

  
129 153
        protected FeatureProvider data;
130 154

  
131
        public FastCSVIterator(CSVStoreProvider store, FeatureType type,
155
        public FastCSVIterator(CSVStoreProvider store, FeatureQuery query, FeatureType type,
132 156
                long startOn) throws DataException {
133
            super(store, type, startOn);
157
            super(store, query, type, startOn);
134 158
            this.data = new CSVFeatureProvider(store, type);
135 159
        }
136 160

  
137 161
        @Override
138 162
        protected FeatureProvider internalNext() {
139
            if (index >= this.count) {
140
                throw new NoSuchElementException();
141
            }
142
            data.setOID(index++);
143
            return this.data;
163
            if( this.spatialIndexIt != null ) {
164
                Object oid = this.spatialIndexIt.next();                
165
                data.setOID(oid);
166
            } else {
167
                if (index >= this.count) {
168
                    throw new NoSuchElementException();
169
                }
170
                data.setOID(index++);
171
            }   
172
            return data;            
144 173
        }
145 174

  
146 175
        @Override
......
203 232
            throws DataException {
204 233
        return new CSVIterator(
205 234
                getStore(),
235
                getQuery(),
206 236
                getFeatureType(),
207 237
                index
208 238
        );
......
213 243
            throws DataException {
214 244
        return new FastCSVIterator(
215 245
                getStore(),
246
                getQuery(),
216 247
                getFeatureType(),
217 248
                index
218 249
        );

Also available in: Unified diff