[jboss-svn-commits] JBoss Common SVN: r2214 - in common-core/trunk/src/main/java/org/jboss/util: . graph
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Dec 12 19:05:57 EST 2006
Author: scott.stark at jboss.org
Date: 2006-12-12 19:05:53 -0500 (Tue, 12 Dec 2006)
New Revision: 2214
Added:
common-core/trunk/src/main/java/org/jboss/util/graph/
common-core/trunk/src/main/java/org/jboss/util/graph/DFSVisitor.java
common-core/trunk/src/main/java/org/jboss/util/graph/Edge.java
common-core/trunk/src/main/java/org/jboss/util/graph/Graph.java
common-core/trunk/src/main/java/org/jboss/util/graph/Vertex.java
common-core/trunk/src/main/java/org/jboss/util/graph/Visitor.java
common-core/trunk/src/main/java/org/jboss/util/graph/VisitorEX.java
Log:
Add the directed graph classes to common-core
Added: common-core/trunk/src/main/java/org/jboss/util/graph/DFSVisitor.java
===================================================================
--- common-core/trunk/src/main/java/org/jboss/util/graph/DFSVisitor.java 2006-12-11 16:17:21 UTC (rev 2213)
+++ common-core/trunk/src/main/java/org/jboss/util/graph/DFSVisitor.java 2006-12-13 00:05:53 UTC (rev 2214)
@@ -0,0 +1,48 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.util.graph;
+
+/**
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public interface DFSVisitor<T>
+{
+ /**
+ * Called by the graph traversal methods when a vertex is first visited.
+ *
+ * @param g - the graph
+ * @param v - the vertex being visited.
+ */
+ public void visit(Graph<T> g, Vertex<T> v);
+
+ /**
+ * Used dfsSpanningTree to notify the visitor of each outgoing edge to
+ * an unvisited vertex.
+ *
+ * @param g - the graph
+ * @param v - the vertex being visited
+ * @param e - the outgoing edge from v
+ */
+ public void visit(Graph<T> g, Vertex<T> v, Edge<T> e);
+}
Property changes on: common-core/trunk/src/main/java/org/jboss/util/graph/DFSVisitor.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: common-core/trunk/src/main/java/org/jboss/util/graph/Edge.java
===================================================================
--- common-core/trunk/src/main/java/org/jboss/util/graph/Edge.java 2006-12-11 16:17:21 UTC (rev 2213)
+++ common-core/trunk/src/main/java/org/jboss/util/graph/Edge.java 2006-12-13 00:05:53 UTC (rev 2214)
@@ -0,0 +1,99 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.util.graph;
+
+/**
+ * A directed, weighted edge in a graph
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class Edge<T>
+{
+ private Vertex<T> from;
+ private Vertex<T> to;
+ private int cost;
+ private boolean mark;
+
+ // Create an edge with 0 cost
+ public Edge(Vertex<T> one, Vertex<T> two)
+ {
+ from = one;
+ to = two;
+ cost = 0;
+ mark = false;
+ }
+
+ // Create an edge and define the cost
+ public Edge(Vertex<T> one, Vertex<T> two, int c)
+ {
+ from = one;
+ to = two;
+ cost = c;
+ mark = false;
+ }
+
+ public Vertex<T> getTo()
+ {
+ return to;
+ }
+
+ public Vertex<T> getFrom()
+ {
+ return from;
+ }
+
+ public int getCost()
+ {
+ return cost;
+ }
+
+ // Mark an edge
+ public void mark()
+ {
+ mark = true;
+ }
+
+ // Clear the mark
+ public void clearMark()
+ {
+ mark = false;
+ }
+
+ // Test the mark
+ public boolean isMarked()
+ {
+ return mark;
+ }
+
+ public String toString()
+ {
+ StringBuffer tmp = new StringBuffer("Edge[from: ");
+ tmp.append(from.getName());
+ tmp.append(",to: ");
+ tmp.append(to.getName());
+ tmp.append(", cost: ");
+ tmp.append(cost);
+ tmp.append("]");
+ return tmp.toString();
+ }
+}
Property changes on: common-core/trunk/src/main/java/org/jboss/util/graph/Edge.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: common-core/trunk/src/main/java/org/jboss/util/graph/Graph.java
===================================================================
--- common-core/trunk/src/main/java/org/jboss/util/graph/Graph.java 2006-12-11 16:17:21 UTC (rev 2213)
+++ common-core/trunk/src/main/java/org/jboss/util/graph/Graph.java 2006-12-13 00:05:53 UTC (rev 2214)
@@ -0,0 +1,353 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.util.graph;
+
+import java.util.LinkedList;
+import java.util.ArrayList;
+
+/**
+ * A directed graph data structure.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class Graph<T>
+{
+ /** Color used to mark unvisited nodes */
+ public static final int VISIT_COLOR_WHITE = 1;
+ /** Color used to mark nodes as they are first visited in DFS order */
+ public static final int VISIT_COLOR_GREY = 2;
+ /** Color used to mark nodes after descendants are completely visited */
+ public static final int VISIT_COLOR_BLACK = 3;
+ /** Vector<Vertex> of graph verticies */
+ private ArrayList<Vertex<T>> verticies;
+ /** Vector<Edge> of edges in the graph */
+ private ArrayList<Edge<T>> edges;
+
+ // Construct a new graph
+ public Graph()
+ {
+ verticies = new ArrayList<Vertex<T>>();
+ edges = new ArrayList<Edge<T>>();
+ }
+
+ /**
+ * Are there any verticies in the graph
+ * @return true if there are no verticies in the graph
+ */
+ public boolean isEmpty()
+ {
+ return verticies.size() == 0;
+ }
+
+ /**
+ * Add a vertex to the graph
+ * @param v the Vertex to add
+ * @return true if the vertex was added, false if it was already in the graph.
+ */
+ public boolean addVertex(Vertex<T> v)
+ {
+ return verticies.add(v);
+ }
+
+ /**
+ * Get the vertex count.
+ * @return the number of verticies in the graph.
+ */
+ public int size()
+ {
+ return verticies.size();
+ }
+
+ /**
+ * Get the given Vertex.
+ * @param n the index [0, size()-1] of the Vertex to access
+ * @return the nth Vertex
+ */
+ public Vertex<T> getVertex(int n)
+ {
+ Vertex<T> v = verticies.get(n);
+ return v;
+ }
+
+ /**
+ * Insert a directed, weighted Edge<T> into the graph
+ * @param from - the Edge<T> starting vertex
+ * @param to - the Edge<T> ending vertex
+ * @param cost - the Edge<T> weight/cost
+ * @return true if the Edge<T> was added, false if from already has this Edge<T>
+ */
+ public boolean addEdge(Vertex<T> from, Vertex<T> to, int cost)
+ {
+ Edge<T> e = new Edge<T>(from, to, cost);
+ if (from.findEdge(to) != null)
+ return false;
+ else
+ {
+ from.addEdge(e);
+ to.addEdge(e);
+ edges.add(e);
+ return true;
+ }
+ }
+
+ /**
+ * Insert a bidirectional Edge<T> in the graph
+ * @param from - the Edge<T> starting vertex
+ * @param to - the Edge<T> ending vertex
+ * @param cost - the Edge<T> weight/cost
+ * @return true if edges between both nodes were added, false otherwise
+ */
+ public boolean insertBiEdge(Vertex<T> from, Vertex<T> to, int cost)
+ {
+ return addEdge(from, to, cost) && addEdge(to, from, cost);
+ }
+
+ /**
+ * Remove a vertex from the graph
+ * @param from the Vertex to remove
+ * @return true if the Vertex was removed
+ */
+ public boolean removeVertex(Vertex<T> from)
+ {
+ if (!verticies.contains(from))
+ return false;
+
+ verticies.remove(from);
+ for(int n = 0; n < from.getOutgoingEdgeCount(); n ++)
+ {
+ Edge<T> e = from.getOutgoingEdge(n);
+ from.remove(e);
+ Vertex<T> to = e.getTo();
+ to.remove(e);
+ edges.remove(e);
+ }
+ for(int n = 0; n < from.getIncomingEdgeCount(); n ++)
+ {
+ Edge<T> e = from.getIncomingEdge(n);
+ from.remove(e);
+ Vertex<T> predecessor = e.getFrom();
+ predecessor.remove(e);
+ }
+ return true;
+ }
+
+ /**
+ * Remove an Edge<T> from the graph
+ * @param from - the Edge<T> starting vertex
+ * @param to - the Edge<T> ending vertex
+ * @return true if the Edge<T> exists, false otherwise
+ */
+ public boolean removeEdge(Vertex<T> from, Vertex<T> to)
+ {
+ Edge<T> e = from.findEdge(to);
+ if (e == null)
+ return false;
+ else
+ {
+ from.remove(e);
+ to.remove(e);
+ edges.remove(e);
+ return true;
+ }
+ }
+
+ /**
+ * Clear the mark state of all verticies in the graph by calling
+ * clearMark() on all verticies.
+ * @see Vertex#clearMark()
+ */
+ public void clearMark()
+ {
+ for (int i = 0; i < verticies.size(); i++)
+ {
+ Vertex<T> w = verticies.get(i);
+ w.clearMark();
+ }
+ }
+
+ /**
+ * Clear the mark state of all edges in the graph by calling
+ * clearMark() on all edges.
+ * @see Edge<T>#clearMark()
+ */
+ public void clearEdges()
+ {
+ for (int i = 0; i < edges.size(); i++)
+ {
+ Edge<T> e = (Edge<T>) edges.get(i);
+ e.clearMark();
+ }
+ }
+
+ /**
+ * Perform a depth first serach using recursion.
+ * @param v - the Vertex to start the search from
+ * @param visitor - the vistor to inform prior to
+ * @see Visitor#visit(Graph, Vertex)
+ */
+ public void depthFirstSearch(Vertex<T> v, final Visitor<T> visitor)
+ {
+ VisitorEX<T, RuntimeException> wrapper = new VisitorEX<T, RuntimeException>()
+ {
+ public void visit(Graph<T> g, Vertex<T> v) throws RuntimeException
+ {
+ visitor.visit(g, v);
+ }
+ };
+ this.depthFirstSearch(v, wrapper);
+ }
+ public <E extends Exception> void depthFirstSearch(Vertex<T> v, VisitorEX<T, E> visitor)
+ throws E
+ {
+ if( visitor != null )
+ visitor.visit(this, v);
+ v.visit();
+ for (int i = 0; i < v.getOutgoingEdgeCount(); i++)
+ {
+ Edge<T> e = v.getOutgoingEdge(i);
+ if (!e.getTo().visited())
+ {
+ depthFirstSearch(e.getTo(), visitor);
+ }
+ }
+ }
+
+ // Breadth First Search
+ public void breadthFirstSearch(Vertex<T> v, final Visitor<T> visitor)
+ {
+ VisitorEX<T, RuntimeException> wrapper = new VisitorEX<T, RuntimeException>()
+ {
+ public void visit(Graph<T> g, Vertex<T> v) throws RuntimeException
+ {
+ visitor.visit(g, v);
+ }
+ };
+ this.breadthFirstSearch(v, wrapper);
+ }
+ public <E extends Exception> void breadthFirstSearch(Vertex<T> v, VisitorEX<T, E> visitor)
+ throws E
+ {
+ LinkedList<Vertex<T>> q = new LinkedList<Vertex<T>>();
+
+ q.add(v);
+ if( visitor != null )
+ visitor.visit(this, v);
+ v.visit();
+ while (q.isEmpty() == false)
+ {
+ v = q.removeFirst();
+ for (int i = 0; i < v.getOutgoingEdgeCount(); i++)
+ {
+ Edge<T> e = v.getOutgoingEdge(i);
+ if (!e.getTo().visited())
+ {
+ q.add(e.getTo());
+ if( visitor != null )
+ visitor.visit(this, e.getTo());
+ e.getTo().visit();
+ }
+ }
+ }
+ }
+
+ // Find Spanning Tree
+ public void dfsSpanningTree(Vertex<T> v, DFSVisitor<T> visitor)
+ {
+ v.visit();
+ if( visitor != null )
+ visitor.visit(this, v);
+
+ for (int i = 0; i < v.getOutgoingEdgeCount(); i++)
+ {
+ Edge<T> e = v.getOutgoingEdge(i);
+ if (!e.getTo().visited())
+ {
+ if( visitor != null )
+ visitor.visit(this, v, e);
+ e.mark();
+ dfsSpanningTree(e.getTo(), visitor);
+ }
+ }
+ }
+
+
+ /*
+ In order to detect cycles, we use a modified depth first search called a
+ colored DFS. All nodes are initially marked white. When a node is
+ encountered, it is marked grey, and when its descendants are completely
+ visited, it is marked black. If a grey node is ever encountered, then there
+ is a cycle.
+ */
+ public Edge<T>[] findCycles()
+ {
+ ArrayList<Edge<T>> cycleEdges = new ArrayList<Edge<T>>();
+ // Mark all verticies as white
+ for(int n = 0; n < verticies.size(); n ++)
+ {
+ Vertex<T> v = getVertex(n);
+ v.setMarkState(VISIT_COLOR_WHITE);
+ }
+ for(int n = 0; n < verticies.size(); n ++)
+ {
+ Vertex<T> v = getVertex(n);
+ visit(v, cycleEdges);
+ }
+ Edge<T>[] cycles = new Edge[cycleEdges.size()];
+ cycleEdges.toArray(cycles);
+ return cycles;
+ }
+
+ private void visit(Vertex<T> v, ArrayList<Edge<T>> cycleEdges)
+ {
+ v.setMarkState(VISIT_COLOR_GREY);
+ int count = v.getOutgoingEdgeCount();
+ for(int n = 0; n < count; n ++)
+ {
+ Edge<T> e = v.getOutgoingEdge(n);
+ Vertex<T> u = e.getTo();
+ if( u.getMarkState() == VISIT_COLOR_GREY )
+ {
+ // A cycle Edge<T>
+ cycleEdges.add(e);
+ }
+ else if( u.getMarkState() == VISIT_COLOR_WHITE )
+ {
+ visit(u, cycleEdges);
+ }
+ }
+ v.setMarkState(VISIT_COLOR_BLACK);
+ }
+
+ public String toString()
+ {
+ StringBuffer tmp = new StringBuffer("Graph[");
+ for (int i = 0; i < verticies.size(); i++)
+ {
+ Vertex<T> v = verticies.get(i);
+ tmp.append(v);
+ }
+ tmp.append(']');
+ return tmp.toString();
+ }
+
+}
Property changes on: common-core/trunk/src/main/java/org/jboss/util/graph/Graph.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: common-core/trunk/src/main/java/org/jboss/util/graph/Vertex.java
===================================================================
--- common-core/trunk/src/main/java/org/jboss/util/graph/Vertex.java 2006-12-11 16:17:21 UTC (rev 2213)
+++ common-core/trunk/src/main/java/org/jboss/util/graph/Vertex.java 2006-12-13 00:05:53 UTC (rev 2214)
@@ -0,0 +1,253 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.util.graph;
+
+import java.util.ArrayList;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class Vertex<T>
+{
+ private ArrayList<Edge<T>> incomingEdges;
+ private ArrayList<Edge<T>> outgoingEdges;
+ private String name;
+ private boolean mark;
+ private int markState;
+ private T data;
+
+ /**
+ * Calls this(null, null).
+ */
+ public Vertex()
+ {
+ this(null, null);
+ }
+ /**
+ * Create a vertex with the given name
+ * @param n
+ */
+ public Vertex(String n)
+ {
+ this(null, null);
+ }
+ public Vertex(String n, T data)
+ {
+ incomingEdges = new ArrayList<Edge<T>>();
+ outgoingEdges = new ArrayList<Edge<T>>();
+ name = new String(n);
+ mark = false;
+ this.data = data;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ /**
+ * @return Returns the data.
+ */
+ public T getData()
+ {
+ return this.data;
+ }
+ /**
+ * @param data The data to set.
+ */
+ public void setData(T data)
+ {
+ this.data = data;
+ }
+
+ /**
+ *
+ * @param e
+ * @return true if the edge was added, false otherwise
+ */
+ public boolean addEdge(Edge<T> e)
+ {
+ if (e.getFrom() == this)
+ outgoingEdges.add(e);
+ else if (e.getTo() == this)
+ incomingEdges.add(e);
+ else
+ return false;
+ return true;
+ }
+
+ /**
+ *
+ * @param e
+ * @return
+ */
+ public boolean hasEdge(Edge<T> e)
+ {
+ if (e.getFrom() == this)
+ return incomingEdges.contains(e);
+ else if (e.getTo() == this)
+ return outgoingEdges.contains(e);
+ else
+ return false;
+ }
+
+ // Remove an edge from this vertex
+ public boolean remove(Edge<T> e)
+ {
+ if (e.getFrom() == this)
+ incomingEdges.remove(e);
+ else if (e.getTo() == this)
+ outgoingEdges.remove(e);
+ else
+ return false;
+ return true;
+ }
+
+ public int getIncomingEdgeCount()
+ {
+ return incomingEdges.size();
+ }
+
+ public Edge<T> getIncomingEdge(int i)
+ {
+ Edge<T> e = incomingEdges.get(i);
+ return e;
+ }
+
+ public int getOutgoingEdgeCount()
+ {
+ return outgoingEdges.size();
+ }
+ public Edge<T> getOutgoingEdge(int i)
+ {
+ Edge<T> e = outgoingEdges.get(i);
+ return e;
+ }
+
+ // Do we have an edge that goes to dest?
+ public Edge<T> findEdge(Vertex<T> dest)
+ {
+ for (int i = 0; i < incomingEdges.size(); i++)
+ {
+ Edge<T> e = incomingEdges.get(i);
+ if (e.getTo() == dest)
+ return e;
+ }
+ return null;
+ }
+
+ // Do we have the edge e? Only looks at sucessors
+ public Edge<T> findEdge(Edge<T> e)
+ {
+ if (incomingEdges.contains(e))
+ return e;
+ else
+ return null;
+ }
+
+ /**
+ * What is the cost to this vertex.
+ * Return Integer.MAX_VALUE if we have no edge to dest
+ * @param dest
+ * @return
+ */
+ public int cost(Vertex<T> dest)
+ {
+ if (dest == this)
+ return 0;
+
+ Edge<T> e = findEdge(dest);
+ if (e != null)
+ return e.getCost();
+ else
+ return Integer.MAX_VALUE;
+ }
+
+ // Do we have an edge to dest?
+ public boolean hasEdge(Vertex<T> dest)
+ {
+ return (findEdge(dest) != null);
+ }
+
+ // Have we been here before?
+ public boolean visited()
+ {
+ return mark;
+ }
+
+ public void mark()
+ {
+ mark = true;
+ }
+ public void setMarkState(int state)
+ {
+ markState = state;
+ }
+ public int getMarkState()
+ {
+ return markState;
+ }
+
+ public void visit()
+ {
+ mark();
+ }
+
+ // Clear the mark
+ public void clearMark()
+ {
+ mark = false;
+ }
+
+ public String toString()
+ {
+ StringBuffer tmp = new StringBuffer("Vertex(");
+ tmp.append(name);
+ tmp.append("), in:[");
+ for (int i = 0; i < incomingEdges.size(); i++)
+ {
+ Edge<T> e = incomingEdges.get(i);
+ if( i > 0 )
+ tmp.append(',');
+ tmp.append('{');
+ tmp.append(e.getFrom().name);
+ tmp.append(',');
+ tmp.append(e.getCost());
+ tmp.append('}');
+ }
+ tmp.append("], out:[");
+ for (int i = 0; i < outgoingEdges.size(); i++)
+ {
+ Edge<T> e = outgoingEdges.get(i);
+ if( i > 0 )
+ tmp.append(',');
+ tmp.append('{');
+ tmp.append(e.getTo().name);
+ tmp.append(',');
+ tmp.append(e.getCost());
+ tmp.append('}');
+ }
+ tmp.append(']');
+ return tmp.toString();
+ }
+}
Property changes on: common-core/trunk/src/main/java/org/jboss/util/graph/Vertex.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: common-core/trunk/src/main/java/org/jboss/util/graph/Visitor.java
===================================================================
--- common-core/trunk/src/main/java/org/jboss/util/graph/Visitor.java 2006-12-11 16:17:21 UTC (rev 2213)
+++ common-core/trunk/src/main/java/org/jboss/util/graph/Visitor.java 2006-12-13 00:05:53 UTC (rev 2214)
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.util.graph;
+
+/**
+ * A graph visitor interface.
+ * TODO, the spanning tree visitor method should really be a separate interface
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public interface Visitor<T>
+{
+ /**
+ * Called by the graph traversal methods when a vertex is first visited.
+ *
+ * @param g - the graph
+ * @param v - the vertex being visited.
+ */
+ public void visit(Graph<T> g, Vertex<T> v);
+}
Property changes on: common-core/trunk/src/main/java/org/jboss/util/graph/Visitor.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: common-core/trunk/src/main/java/org/jboss/util/graph/VisitorEX.java
===================================================================
--- common-core/trunk/src/main/java/org/jboss/util/graph/VisitorEX.java 2006-12-11 16:17:21 UTC (rev 2213)
+++ common-core/trunk/src/main/java/org/jboss/util/graph/VisitorEX.java 2006-12-13 00:05:53 UTC (rev 2214)
@@ -0,0 +1,41 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.util.graph;
+
+/**
+ * A graph visitor interface.
+ * TODO, the spanning tree visitor method should really be a separate interface
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public interface VisitorEX<T, E extends Exception>
+{
+
+ /**
+ * Called by the graph traversal methods when a vertex is first visited.
+ *
+ * @param g - the graph
+ * @param v - the vertex being visited.
+ */
+ public void visit(Graph<T> g, Vertex<T> v) throws E;
+}
Property changes on: common-core/trunk/src/main/java/org/jboss/util/graph/VisitorEX.java
___________________________________________________________________
Name: svn:eol-style
+ native
More information about the jboss-svn-commits
mailing list