01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
05: * (C) 2002, Refractions Reserach Inc.
06: *
07: * This library is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU Lesser General Public
09: * License as published by the Free Software Foundation;
10: * version 2.1 of the License.
11: *
12: * This library is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: */
17: package org.geotools.graph.traverse.basic;
18:
19: import org.geotools.graph.structure.Graphable;
20: import org.geotools.graph.traverse.GraphTraversal;
21: import org.geotools.graph.traverse.GraphWalker;
22:
23: /**
24: * An implementation of GraphWalker that counts the number of components
25: * visited. As each component is visited, the walker sets the count of the
26: * component to the value of its counter.
27: *
28: * @see Graphable#setCount(int)
29: *
30: * @author Justin Deoliveira, Refractions Research Inc, jdeolive@refractions.net
31: *
32: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/extension/graph/src/main/java/org/geotools/graph/traverse/basic/CountingWalker.java $
33: */
34: public class CountingWalker implements GraphWalker {
35:
36: /** counter of how many components have been visited **/
37: private int m_counter;
38:
39: /**
40: * Sets the count of the component and increments the counter.
41: *
42: * @see Graphable#setCount(int)
43: * @see GraphWalker#visit(Graphable, GraphTraversal)
44: */
45: public int visit(Graphable element, GraphTraversal traversal) {
46: element.setCount(m_counter++);
47: return GraphTraversal.CONTINUE;
48: }
49:
50: /**
51: * Does nothing.
52: *
53: * @see GraphWalker#finish()
54: */
55: public void finish() {
56: }
57:
58: /**
59: * Returns the value of the visitation counter.
60: *
61: * @return int Value of the counter.
62: */
63: public int getCount() {
64: return (m_counter);
65: }
66: }
|