- creating a separate visitor package to organize the code a little

better.
PR:
Obtained from:
Submitted by:
Reviewed by:


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/sandbox/graph/trunk@144579 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
jvanzyl committed 2001-11-29 14:17:34 +00:00
1 parent bb5d76e618
commit 2a14dba733
15 files changed
+77 -27

No files matched your search

+2 -1
View File
@@ -55,6 +55,7 @@ package org.apache.commons.graph;
*/
import java.util.Vector;
import org.apache.commons.graph.visitor.Visitor;
/**
* Visit graph with breadth first search and compute the predecessor
@@ -62,7 +63,7 @@ import java.util.Vector;
* so that it performs Dijkstra's shortest-path algorithm, for
* instance, if you extend the VQueue class to a Priority Queue.
*
* @version $Id: BFS.java,v 1.1 2001/11/12 16:05:17 jvanzyl Exp $
* @version $Id: BFS.java,v 1.2 2001/11/29 14:17:33 jvanzyl Exp $
* @author <A HREF="http://www.inf.fu-berlin.de/~dahm">M. Dahm</A>
*/
public class BFS extends TraversalOrder {
+3 -1
View File
@@ -54,11 +54,13 @@ package org.apache.commons.graph;
* <http://www.apache.org/>.
*/
import org.apache.commons.graph.visitor.Visitor;
/**
* Visit graph with depth first search and mark discovery and finishing time in all
* vertices.
*
* @version $Id: DFS.java,v 1.1 2001/11/12 16:05:18 jvanzyl Exp $
* @version $Id: DFS.java,v 1.2 2001/11/29 14:17:33 jvanzyl Exp $
* @author <A HREF="http://www.inf.fu-berlin.de/~dahm">M. Dahm</A>
*/
public class DFS extends TraversalOrder {
+3 -1
View File
@@ -54,11 +54,13 @@ package org.apache.commons.graph;
* <http://www.apache.org/>.
*/
import org.apache.commons.graph.visitor.Visitor;
/**
* Describes an edge between two vertices of a graph, i.e. a relation between
* two arbitrary vertices.
*
* @version $Id: Edge.java,v 1.1 2001/11/12 16:05:18 jvanzyl Exp $
* @version $Id: Edge.java,v 1.2 2001/11/29 14:17:33 jvanzyl Exp $
* @author <A HREF="http://www.inf.fu-berlin.de/~dahm">M. Dahm</A>
*/
public class Edge implements Cloneable, Constants, java.io.Serializable {
+5 -1
View File
@@ -58,10 +58,14 @@ import java.util.*;
import java.util.zip.*;
import java.io.*;
import org.apache.commons.graph.visitor.Visitor;
import org.apache.commons.graph.visitor.DefaultVisitor;
import org.apache.commons.graph.visitor.PrintVisitor;
/**
* Describes a generic graph G = (V, E), i.e. a set of vertices and edges.
*
* @version $Id: Graph.java,v 1.1 2001/11/12 16:05:19 jvanzyl Exp $
* @version $Id: Graph.java,v 1.2 2001/11/29 14:17:33 jvanzyl Exp $
* @author <A HREF="http://www.inf.fu-berlin.de/~dahm">M. Dahm</A>
*/
public class Graph implements Cloneable, Constants, Serializable {
@@ -56,6 +56,8 @@ package org.apache.commons.graph;
import java.io.*;
import java.util.StringTokenizer;
import org.apache.commons.graph.visitor.Visitor;
/**
* Abstract super class for drivers that visualize graphs
* in different graph formats such as
@@ -67,7 +69,7 @@ import java.util.StringTokenizer;
* By default graphs are dumped in the native Java format, i.e. by using the
* Serialization feature.
*
* @version $Id: GraphVisualizer.java,v 1.1 2001/11/12 16:05:19 jvanzyl Exp $
* @version $Id: GraphVisualizer.java,v 1.2 2001/11/29 14:17:33 jvanzyl Exp $
* @author <A HREF="http://www.inf.fu-berlin.de/~dahm">M. Dahm</A>
* @see DaVinciVisualizer
* @see GMLVisualizer
@@ -54,10 +54,12 @@ package org.apache.commons.graph;
* <http://www.apache.org/>.
*/
import org.apache.commons.graph.visitor.Visitor;
/**
* Visit graph in sequential order, i.e. in the order returned by Graph.getVertices().
*
* @version $Id: Sequential.java,v 1.1 2001/11/12 16:05:20 jvanzyl Exp $
* @version $Id: Sequential.java,v 1.2 2001/11/29 14:17:33 jvanzyl Exp $
* @author <A HREF="http://www.inf.fu-berlin.de/~dahm">M. Dahm</A>
*/
public final class Sequential extends TraversalOrder {
@@ -54,6 +54,8 @@ package org.apache.commons.graph;
* <http://www.apache.org/>.
*/
import org.apache.commons.graph.visitor.Visitor;
/**
* Class takes a visitor "piggy-backed" and applies it to all nodes
* and edges. The traversal order implemented by children of this
@@ -61,7 +63,7 @@ package org.apache.commons.graph;
*
* This relates to the "Strategy" design pattern.
*
* @version $Id: TraversalOrder.java,v 1.1 2001/11/12 16:05:20 jvanzyl Exp $
* @version $Id: TraversalOrder.java,v 1.2 2001/11/29 14:17:33 jvanzyl Exp $
* @author <A HREF="http://www.inf.fu-berlin.de/~dahm">M. Dahm</A>
* @see DFS
* @see BFS
@@ -57,19 +57,19 @@ package org.apache.commons.graph;
/**
* Implements a simple first-in, last-out stack of vertices of fixed size.
*
* @version $Id: VStack.java,v 1.1 2001/11/12 16:05:20 jvanzyl Exp $
* @version $Id: VStack.java,v 1.2 2001/11/29 14:17:33 jvanzyl Exp $
* @author <A HREF="http://www.inf.fu-berlin.de/~dahm">M. Dahm</A>
*/
final class VStack {
public final class VStack {
private Vertex[] vertices;
private int top;
VStack(int s) {
public VStack(int s) {
vertices = new Vertex[s];
}
final void push(Vertex v) { vertices[top++] = v; }
final Vertex pop() { return vertices[--top]; }
final Vertex top() { return vertices[top - 1]; }
final boolean empty() { return top <= 0; }
public final void push(Vertex v) { vertices[top++] = v; }
public final Vertex pop() { return vertices[--top]; }
public final Vertex top() { return vertices[top - 1]; }
public final boolean empty() { return top <= 0; }
}
@@ -54,10 +54,12 @@ package org.apache.commons.graph;
* <http://www.apache.org/>.
*/
import org.apache.commons.graph.visitor.Visitor;
/**
* Describes a vertex of a graph.
*
* @version $Id: Vertex.java,v 1.1 2001/11/12 16:05:20 jvanzyl Exp $
* @version $Id: Vertex.java,v 1.2 2001/11/29 14:17:33 jvanzyl Exp $
* @author <A HREF="http://www.inf.fu-berlin.de/~dahm">M. Dahm</A>
*/
public class Vertex implements Cloneable, Constants, java.io.Serializable {
@@ -1,4 +1,4 @@
package org.apache.commons.graph;
package org.apache.commons.graph.visitor;
/* ====================================================================
* The Apache Software License, Version 1.1
@@ -54,11 +54,18 @@ package org.apache.commons.graph;
* <http://www.apache.org/>.
*/
import org.apache.commons.graph.BFS;
import org.apache.commons.graph.Constants;
import org.apache.commons.graph.Edge;
import org.apache.commons.graph.Graph;
import org.apache.commons.graph.Vertex;
import org.apache.commons.graph.VStack;
/**
* Visit graph with BFS and compute predecessors during traversal as
* well as the "distance" to the source node (number of edges in between).
*
* @version $Id: BFSVisitor.java,v 1.1 2001/11/12 16:05:17 jvanzyl Exp $
* @version $Id: BFSVisitor.java,v 1.1 2001/11/29 14:17:34 jvanzyl Exp $
* @author <A HREF="http://www.inf.fu-berlin.de/~dahm">M. Dahm</A>
* @see BFS
*/
@@ -1,4 +1,4 @@
package org.apache.commons.graph;
package org.apache.commons.graph.visitor;
/* ====================================================================
* The Apache Software License, Version 1.1
@@ -54,13 +54,18 @@ package org.apache.commons.graph;
* <http://www.apache.org/>.
*/
import org.apache.commons.graph.Edge;
import org.apache.commons.graph.Graph;
import org.apache.commons.graph.Vertex;
import org.apache.commons.graph.VStack;
/**
* Visit graph with DFS and compute predecessors during traversal as
* well as discovery and finishing time of all vertices. Instances of
* this class (and of course its descendants) may be passed to a DFS
* object.
*
* @version $Id: DFSVisitor.java,v 1.1 2001/11/12 16:05:18 jvanzyl Exp $
* @version $Id: DFSVisitor.java,v 1.1 2001/11/29 14:17:34 jvanzyl Exp $
* @author <A HREF="http://www.inf.fu-berlin.de/~dahm">M. Dahm</A>
* @see DFS
*/
@@ -1,4 +1,4 @@
package org.apache.commons.graph;
package org.apache.commons.graph.visitor;
/* ====================================================================
* The Apache Software License, Version 1.1
@@ -54,10 +54,15 @@ package org.apache.commons.graph;
* <http://www.apache.org/>.
*/
import org.apache.commons.graph.DFS;
import org.apache.commons.graph.Edge;
import org.apache.commons.graph.Graph;
import org.apache.commons.graph.Vertex;
/**
* Empty Visitor, i.e. all visit methods do nothing.
*
* @version $Id: DefaultVisitor.java,v 1.1 2001/11/12 16:05:18 jvanzyl Exp $
* @version $Id: DefaultVisitor.java,v 1.1 2001/11/29 14:17:34 jvanzyl Exp $
* @author <A HREF="http://www.inf.fu-berlin.de/~dahm">M. Dahm</A>
*/
public class DefaultVisitor implements Visitor {
@@ -1,4 +1,4 @@
package org.apache.commons.graph;
package org.apache.commons.graph.visitor;
/* ====================================================================
* The Apache Software License, Version 1.1
@@ -53,14 +53,20 @@ package org.apache.commons.graph;
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import java.io.PrintWriter;
import org.apache.commons.graph.DFS;
import org.apache.commons.graph.Edge;
import org.apache.commons.graph.Graph;
import org.apache.commons.graph.Vertex;
/**
* Visit graph with depth first search and simply prints the current
* vertices and edges as they are discovered. May be used with DFS, BFS,
* Sequential or any other visitor. Uses DFS by default.
*
* @version $Id: PrintVisitor.java,v 1.1 2001/11/12 16:05:19 jvanzyl Exp $
* @version $Id: PrintVisitor.java,v 1.1 2001/11/29 14:17:34 jvanzyl Exp $
* @author <A HREF="http://www.inf.fu-berlin.de/~dahm">M. Dahm</A>
*/
public class PrintVisitor implements Visitor {
@@ -1,4 +1,4 @@
package org.apache.commons.graph;
package org.apache.commons.graph.visitor;
/* ====================================================================
* The Apache Software License, Version 1.1
@@ -56,10 +56,16 @@ package org.apache.commons.graph;
import java.util.Vector;
import org.apache.commons.graph.DFS;
import org.apache.commons.graph.Edge;
import org.apache.commons.graph.Graph;
import org.apache.commons.graph.Vertex;
import org.apache.commons.graph.VStack;
/**
* Visit graph computing its "Strongly Connected Components" (SCC).
*
* @version $Id: SCCVisitor.java,v 1.1 2001/11/12 16:05:20 jvanzyl Exp $
* @version $Id: SCCVisitor.java,v 1.1 2001/11/29 14:17:34 jvanzyl Exp $
* @author <A HREF="http://www.inf.fu-berlin.de/~dahm">M. Dahm</A>
* @see DFS
*/
@@ -1,4 +1,4 @@
package org.apache.commons.graph;
package org.apache.commons.graph.visitor;
/* ====================================================================
* The Apache Software License, Version 1.1
@@ -54,10 +54,14 @@ package org.apache.commons.graph;
* <http://www.apache.org/>.
*/
import org.apache.commons.graph.Edge;
import org.apache.commons.graph.Graph;
import org.apache.commons.graph.Vertex;
/**
* Interface for visitor patterns.
*
* @version $Id: Visitor.java,v 1.1 2001/11/12 16:05:20 jvanzyl Exp $
* @version $Id: Visitor.java,v 1.1 2001/11/29 14:17:34 jvanzyl Exp $
* @author <A HREF="http://www.inf.fu-berlin.de/~dahm">M. Dahm</A>
*/
public interface Visitor {