01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2005-2006, GeoTools Project Managment Committee (PMC)
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation;
09: * version 2.1 of the License.
10: *
11: * This library 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 GNU
14: * Lesser General Public License for more details.
15: */
16: package org.geotools.feature.collection;
17:
18: import java.util.Iterator;
19: import java.util.NoSuchElementException;
20:
21: import org.geotools.feature.Feature;
22: import org.geotools.feature.FeatureCollection;
23: import org.geotools.feature.FeatureIterator;
24:
25: /**
26: * A feature iterator that completely delegates to a normal
27: * Iterator, simply allowing Java 1.4 code to escape the caste (sic)
28: * system.
29: * <p>
30: * This implementation is not suitable for use with collections
31: * that make use of system resources. As an alterantive please
32: * see ResourceFetaureIterator.
33: * </p>
34: * @author Jody Garnett, Refractions Research, Inc.
35: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/main/src/main/java/org/geotools/feature/collection/DelegateFeatureIterator.java $
36: */
37: public class DelegateFeatureIterator implements FeatureIterator {
38: Iterator delegate;
39: private FeatureCollection collection;
40:
41: /**
42: * Wrap the provided iterator up as a FeatureIterator.
43: *
44: * @param iterator Iterator to be used as a delegate.
45: */
46: public DelegateFeatureIterator(FeatureCollection collection,
47: Iterator iterator) {
48: delegate = iterator;
49: this .collection = collection;
50: }
51:
52: public boolean hasNext() {
53: return delegate != null && delegate.hasNext();
54: }
55:
56: public Feature next() throws NoSuchElementException {
57: if (delegate == null)
58: throw new NoSuchElementException();
59: return (Feature) delegate.next();
60: }
61:
62: public void close() {
63: if (collection != null && delegate != null)
64: collection.close(delegate);
65: collection = null;
66: delegate = null;
67:
68: }
69: }
|