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 org.geotools.feature.Feature;
19: import org.geotools.feature.FeatureIterator;
20: import org.geotools.feature.FeatureCollection;
21:
22: /**
23: * A convenience class for dealing with FeatureCollection Iterators. DOES NOT
24: * implement Iterator.
25: * <p>
26: * We are sorry but this does not implement Iteartor<Feature>, although it should
27: * be a drop in replacement when Geotools is able to upgrade to Java 5.
28: * </p>
29: * @author Ian Schneider
30: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/main/src/main/java/org/geotools/feature/collection/FeatureIteratorImpl.java $
31: */
32: public class FeatureIteratorImpl implements FeatureIterator {
33: /** The iterator from the FeatureCollection to return features from. */
34: java.util.Iterator iterator;
35: FeatureCollection collection;
36:
37: /**
38: * Create a new FeatureIterator using the Iterator from the given
39: * FeatureCollection.
40: *
41: * @param collection The FeatureCollection to perform the iteration on.
42: */
43: public FeatureIteratorImpl(FeatureCollection collection) {
44: this .collection = collection;
45: this .iterator = collection.iterator();
46: }
47:
48: /**
49: * Does another Feature exist in this Iteration.
50: * <p>
51: * Iterator defin: Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)
52: * </p>
53: * @return true if more Features exist, false otherwise.
54: */
55: public boolean hasNext() {
56: return iterator.hasNext();
57: }
58:
59: /**
60: * Get the next Feature in this iteration.
61: *
62: * @return The next Feature
63: *
64: * @throws java.util.NoSuchElementException If no more Features exist.
65: */
66: public Feature next() throws java.util.NoSuchElementException {
67: return (Feature) iterator.next();
68: }
69:
70: /**
71: * Required so FeatureCollection classes can implement close( FeatureIterator ).
72: */
73: public void close() {
74: if (iterator != null) {
75: collection.close(iterator);
76: iterator = null;
77: collection = null;
78: }
79: }
80: }
|