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.visitor;
17:
18: import org.geotools.feature.Feature;
19: import org.geotools.feature.FeatureCollection;
20:
21: import java.util.Iterator;
22:
23: /**
24: * DOCUMENT ME!
25: *
26: * @author Cory Horner, Refractions
27: *
28: * @since 2.2.M2
29: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/main/src/main/java/org/geotools/feature/visitor/CollectionUtil.java $
30: */
31: public class CollectionUtil {
32: /**
33: * Navigate the collection and call vistor.visit( Feature ) for each
34: * element in the collection.
35: *
36: * @param collection the featureCollection containing the features we want to visit
37: * @param visitor the visitor which already knows which attributes it wants to meet
38: */
39: static void accept(FeatureCollection collection,
40: FeatureVisitor visitor) {
41: Iterator iterator;
42:
43: for (iterator = collection.iterator(); iterator.hasNext();) {
44: Feature feature = (Feature) iterator.next();
45: visitor.visit(feature);
46: }
47:
48: collection.close(iterator);
49: }
50:
51: static void accept(FeatureCollection collection,
52: FeatureVisitor[] visitors) {
53: Iterator iterator;
54:
55: for (iterator = collection.iterator(); iterator.hasNext();) {
56: Feature feature = (Feature) iterator.next();
57:
58: for (int i = 0; i < visitors.length; i++) {
59: FeatureVisitor visitor = visitors[i];
60: visitor.visit(feature);
61: }
62: }
63:
64: collection.close(iterator);
65: }
66:
67: public static Object calc(FeatureCollection collection,
68: FeatureCalc calculator) {
69: accept(collection, calculator);
70:
71: return calculator.getResult();
72: }
73: }
|