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 / FastDefaultIterator.java @ 46505

History | View | Annotate | Download (3.17 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.exception.DataException;
27
import org.gvsig.fmap.dal.feature.impl.DefaultFeature;
28
import org.gvsig.fmap.dal.feature.spi.FeatureProvider;
29
import org.gvsig.tools.dispose.DisposeUtils;
30
import org.gvsig.tools.exception.BaseException;
31

    
32
public class FastDefaultIterator extends DefaultIterator {
33

    
34
        DefaultFeature myFeature;
35

    
36
        public FastDefaultIterator(DefaultFeatureSet featureSet, long index, long elements)
37
                        throws DataException {
38
                super(featureSet);
39
                try{
40
                    this.initializeFeature();
41
                    if (index > 0 || elements>0 ) {
42
                            if (featureSet.provider.canIterateFromIndex()) {
43
                                    try {
44
                                            this.iterator = featureSet.provider.fastIterator(index,elements);
45
                                    } catch (UnsupportedOperationException e) {
46
                                            this.iterator = featureSet.provider.fastIterator();
47
                                            skypto(index);
48
                                    }
49
                            } else {
50
                                    this.iterator = featureSet.provider.fastIterator();
51
                                    skypto(index);
52
                            }
53
                    } else {
54
                            this.iterator = featureSet.provider.fastIterator();
55
                    }
56
                } catch (Throwable t) {
57
                    DisposeUtils.dispose(this.fset);
58
                    DisposeUtils.dispose(this);
59
                    throw t;
60
                }
61

    
62
        }
63

    
64
        protected DefaultFeature createFeature(FeatureProvider fData)
65
                        throws DataException {
66
                fData.setNew(false);
67
                this.myFeature.setData(fData);
68

    
69
                if (this.fset.transform.isEmpty()) {
70
                        return myFeature;
71
                } else {
72
                        return (DefaultFeature) this.fset.transform.applyTransform(
73
                                        myFeature, fset
74
                                                        .getDefaultFeatureType());
75
                }
76
        }
77

    
78
        protected void initializeFeature() {
79
                myFeature = new DefaultFeature(fset.store);
80
        }
81

    
82
        public void remove() {
83
                super.remove();
84
                this.initializeFeature();
85
        }
86

    
87
        protected void doDispose() throws BaseException {
88
                super.doDispose();
89
                myFeature = null;
90
        }
91

    
92
}