<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2FCollections_Data_Structure%2FGraph</id>
		<title>Java/Collections Data Structure/Graph - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2FCollections_Data_Structure%2FGraph"/>
		<link rel="alternate" type="text/html" href="http://jexp.ru/index.php?title=Java/Collections_Data_Structure/Graph&amp;action=history"/>
		<updated>2026-06-10T02:33:14Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://jexp.ru/index.php?title=Java/Collections_Data_Structure/Graph&amp;diff=9155&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://jexp.ru/index.php?title=Java/Collections_Data_Structure/Graph&amp;diff=9155&amp;oldid=prev"/>
				<updated>2010-06-01T07:26:52Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 07:26, 1 июня 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	<entry>
		<id>http://jexp.ru/index.php?title=Java/Collections_Data_Structure/Graph&amp;diff=9154&amp;oldid=prev</id>
		<title> в 18:01, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://jexp.ru/index.php?title=Java/Collections_Data_Structure/Graph&amp;diff=9154&amp;oldid=prev"/>
				<updated>2010-05-31T18:01:50Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== A directed graph data structure ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
/*&lt;br /&gt;
 * JBoss, Home of Professional Open Source&lt;br /&gt;
 * Copyright 2006, Red Hat Middleware LLC, and individual contributors&lt;br /&gt;
 * by the @authors tag. See the copyright.txt in the distribution for a&lt;br /&gt;
 * full listing of individual contributors.&lt;br /&gt;
 *&lt;br /&gt;
 * This is free software; you can redistribute it and/or modify it&lt;br /&gt;
 * under the terms of the GNU Lesser General Public License as&lt;br /&gt;
 * published by the Free Software Foundation; either version 2.1 of&lt;br /&gt;
 * the License, or (at your option) any later version.&lt;br /&gt;
 *&lt;br /&gt;
 * This software is distributed in the hope that it will be useful,&lt;br /&gt;
 * but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU&lt;br /&gt;
 * Lesser General Public License for more details.&lt;br /&gt;
 *&lt;br /&gt;
 * You should have received a copy of the GNU Lesser General Public&lt;br /&gt;
 * License along with this software; if not, write to the Free&lt;br /&gt;
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA&lt;br /&gt;
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.&lt;br /&gt;
 */&lt;br /&gt;
import java.util.ArrayList;&lt;br /&gt;
import java.util.ruparator;&lt;br /&gt;
import java.util.LinkedList;&lt;br /&gt;
import java.util.List;&lt;br /&gt;
/**&lt;br /&gt;
 * A directed graph data structure.&lt;br /&gt;
 * &lt;br /&gt;
 * @author Scott.Stark@jboss.org&lt;br /&gt;
 * @version $Revision$&lt;br /&gt;
 * @param &amp;lt;T&amp;gt;&lt;br /&gt;
 */&lt;br /&gt;
@SuppressWarnings(&amp;quot;unchecked&amp;quot;)&lt;br /&gt;
public class Graph&amp;lt;T&amp;gt; {&lt;br /&gt;
  /** Color used to mark unvisited nodes */&lt;br /&gt;
  public static final int VISIT_COLOR_WHITE = 1;&lt;br /&gt;
  /** Color used to mark nodes as they are first visited in DFS order */&lt;br /&gt;
  public static final int VISIT_COLOR_GREY = 2;&lt;br /&gt;
  /** Color used to mark nodes after descendants are completely visited */&lt;br /&gt;
  public static final int VISIT_COLOR_BLACK = 3;&lt;br /&gt;
  /** Vector&amp;lt;Vertex&amp;gt; of graph verticies */&lt;br /&gt;
  private List&amp;lt;Vertex&amp;lt;T&amp;gt;&amp;gt; verticies;&lt;br /&gt;
  /** Vector&amp;lt;Edge&amp;gt; of edges in the graph */&lt;br /&gt;
  private List&amp;lt;Edge&amp;lt;T&amp;gt;&amp;gt; edges;&lt;br /&gt;
  /** The vertex identified as the root of the graph */&lt;br /&gt;
  private Vertex&amp;lt;T&amp;gt; rootVertex;&lt;br /&gt;
  /**&lt;br /&gt;
   * Construct a new graph without any vertices or edges&lt;br /&gt;
   */&lt;br /&gt;
  public Graph() {&lt;br /&gt;
    verticies = new ArrayList&amp;lt;Vertex&amp;lt;T&amp;gt;&amp;gt;();&lt;br /&gt;
    edges = new ArrayList&amp;lt;Edge&amp;lt;T&amp;gt;&amp;gt;();&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Are there any verticies in the graph&lt;br /&gt;
   * &lt;br /&gt;
   * @return true if there are no verticies in the graph&lt;br /&gt;
   */&lt;br /&gt;
  public boolean isEmpty() {&lt;br /&gt;
    return verticies.size() == 0;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Add a vertex to the graph&lt;br /&gt;
   * &lt;br /&gt;
   * @param v&lt;br /&gt;
   *          the Vertex to add&lt;br /&gt;
   * @return true if the vertex was added, false if it was already in the graph.&lt;br /&gt;
   */&lt;br /&gt;
  public boolean addVertex(Vertex&amp;lt;T&amp;gt; v) {&lt;br /&gt;
    boolean added = false;&lt;br /&gt;
    if (verticies.contains(v) == false) {&lt;br /&gt;
      added = verticies.add(v);&lt;br /&gt;
    }&lt;br /&gt;
    return added;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Get the vertex count.&lt;br /&gt;
   * &lt;br /&gt;
   * @return the number of verticies in the graph.&lt;br /&gt;
   */&lt;br /&gt;
  public int size() {&lt;br /&gt;
    return verticies.size();&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Get the root vertex&lt;br /&gt;
   * &lt;br /&gt;
   * @return the root vertex if one is set, null if no vertex has been set as&lt;br /&gt;
   *         the root.&lt;br /&gt;
   */&lt;br /&gt;
  public Vertex&amp;lt;T&amp;gt; getRootVertex() {&lt;br /&gt;
    return rootVertex;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Set a root vertex. If root does no exist in the graph it is added.&lt;br /&gt;
   * &lt;br /&gt;
   * @param root -&lt;br /&gt;
   *          the vertex to set as the root and optionally add if it does not&lt;br /&gt;
   *          exist in the graph.&lt;br /&gt;
   */&lt;br /&gt;
  public void setRootVertex(Vertex&amp;lt;T&amp;gt; root) {&lt;br /&gt;
    this.rootVertex = root;&lt;br /&gt;
    if (verticies.contains(root) == false)&lt;br /&gt;
      this.addVertex(root);&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Get the given Vertex.&lt;br /&gt;
   * &lt;br /&gt;
   * @param n&lt;br /&gt;
   *          the index [0, size()-1] of the Vertex to access&lt;br /&gt;
   * @return the nth Vertex&lt;br /&gt;
   */&lt;br /&gt;
  public Vertex&amp;lt;T&amp;gt; getVertex(int n) {&lt;br /&gt;
    return verticies.get(n);&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Get the graph verticies&lt;br /&gt;
   * &lt;br /&gt;
   * @return the graph verticies&lt;br /&gt;
   */&lt;br /&gt;
  public List&amp;lt;Vertex&amp;lt;T&amp;gt;&amp;gt; getVerticies() {&lt;br /&gt;
    return this.verticies;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Insert a directed, weighted Edge&amp;lt;T&amp;gt; into the graph.&lt;br /&gt;
   * &lt;br /&gt;
   * @param from -&lt;br /&gt;
   *          the Edge&amp;lt;T&amp;gt; starting vertex&lt;br /&gt;
   * @param to -&lt;br /&gt;
   *          the Edge&amp;lt;T&amp;gt; ending vertex&lt;br /&gt;
   * @param cost -&lt;br /&gt;
   *          the Edge&amp;lt;T&amp;gt; weight/cost&lt;br /&gt;
   * @return true if the Edge&amp;lt;T&amp;gt; was added, false if from already has this Edge&amp;lt;T&amp;gt;&lt;br /&gt;
   * @throws IllegalArgumentException&lt;br /&gt;
   *           if from/to are not verticies in the graph&lt;br /&gt;
   */&lt;br /&gt;
  public boolean addEdge(Vertex&amp;lt;T&amp;gt; from, Vertex&amp;lt;T&amp;gt; to, int cost) throws IllegalArgumentException {&lt;br /&gt;
    if (verticies.contains(from) == false)&lt;br /&gt;
      throw new IllegalArgumentException(&amp;quot;from is not in graph&amp;quot;);&lt;br /&gt;
    if (verticies.contains(to) == false)&lt;br /&gt;
      throw new IllegalArgumentException(&amp;quot;to is not in graph&amp;quot;);&lt;br /&gt;
    Edge&amp;lt;T&amp;gt; e = new Edge&amp;lt;T&amp;gt;(from, to, cost);&lt;br /&gt;
    if (from.findEdge(to) != null)&lt;br /&gt;
      return false;&lt;br /&gt;
    else {&lt;br /&gt;
      from.addEdge(e);&lt;br /&gt;
      to.addEdge(e);&lt;br /&gt;
      edges.add(e);&lt;br /&gt;
      return true;&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Insert a bidirectional Edge&amp;lt;T&amp;gt; in the graph&lt;br /&gt;
   * &lt;br /&gt;
   * @param from -&lt;br /&gt;
   *          the Edge&amp;lt;T&amp;gt; starting vertex&lt;br /&gt;
   * @param to -&lt;br /&gt;
   *          the Edge&amp;lt;T&amp;gt; ending vertex&lt;br /&gt;
   * @param cost -&lt;br /&gt;
   *          the Edge&amp;lt;T&amp;gt; weight/cost&lt;br /&gt;
   * @return true if edges between both nodes were added, false otherwise&lt;br /&gt;
   * @throws IllegalArgumentException&lt;br /&gt;
   *           if from/to are not verticies in the graph&lt;br /&gt;
   */&lt;br /&gt;
  public boolean insertBiEdge(Vertex&amp;lt;T&amp;gt; from, Vertex&amp;lt;T&amp;gt; to, int cost)&lt;br /&gt;
      throws IllegalArgumentException {&lt;br /&gt;
    return addEdge(from, to, cost) &amp;amp;&amp;amp; addEdge(to, from, cost);&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Get the graph edges&lt;br /&gt;
   * &lt;br /&gt;
   * @return the graph edges&lt;br /&gt;
   */&lt;br /&gt;
  public List&amp;lt;Edge&amp;lt;T&amp;gt;&amp;gt; getEdges() {&lt;br /&gt;
    return this.edges;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Remove a vertex from the graph&lt;br /&gt;
   * &lt;br /&gt;
   * @param v&lt;br /&gt;
   *          the Vertex to remove&lt;br /&gt;
   * @return true if the Vertex was removed&lt;br /&gt;
   */&lt;br /&gt;
  public boolean removeVertex(Vertex&amp;lt;T&amp;gt; v) {&lt;br /&gt;
    if (!verticies.contains(v))&lt;br /&gt;
      return false;&lt;br /&gt;
    verticies.remove(v);&lt;br /&gt;
    if (v == rootVertex)&lt;br /&gt;
      rootVertex = null;&lt;br /&gt;
    // Remove the edges associated with v&lt;br /&gt;
    for (int n = 0; n &amp;lt; v.getOutgoingEdgeCount(); n++) {&lt;br /&gt;
      Edge&amp;lt;T&amp;gt; e = v.getOutgoingEdge(n);&lt;br /&gt;
      v.remove(e);&lt;br /&gt;
      Vertex&amp;lt;T&amp;gt; to = e.getTo();&lt;br /&gt;
      to.remove(e);&lt;br /&gt;
      edges.remove(e);&lt;br /&gt;
    }&lt;br /&gt;
    for (int n = 0; n &amp;lt; v.getIncomingEdgeCount(); n++) {&lt;br /&gt;
      Edge&amp;lt;T&amp;gt; e = v.getIncomingEdge(n);&lt;br /&gt;
      v.remove(e);&lt;br /&gt;
      Vertex&amp;lt;T&amp;gt; predecessor = e.getFrom();&lt;br /&gt;
      predecessor.remove(e);&lt;br /&gt;
    }&lt;br /&gt;
    return true;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Remove an Edge&amp;lt;T&amp;gt; from the graph&lt;br /&gt;
   * &lt;br /&gt;
   * @param from -&lt;br /&gt;
   *          the Edge&amp;lt;T&amp;gt; starting vertex&lt;br /&gt;
   * @param to -&lt;br /&gt;
   *          the Edge&amp;lt;T&amp;gt; ending vertex&lt;br /&gt;
   * @return true if the Edge&amp;lt;T&amp;gt; exists, false otherwise&lt;br /&gt;
   */&lt;br /&gt;
  public boolean removeEdge(Vertex&amp;lt;T&amp;gt; from, Vertex&amp;lt;T&amp;gt; to) {&lt;br /&gt;
    Edge&amp;lt;T&amp;gt; e = from.findEdge(to);&lt;br /&gt;
    if (e == null)&lt;br /&gt;
      return false;&lt;br /&gt;
    else {&lt;br /&gt;
      from.remove(e);&lt;br /&gt;
      to.remove(e);&lt;br /&gt;
      edges.remove(e);&lt;br /&gt;
      return true;&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Clear the mark state of all verticies in the graph by calling clearMark()&lt;br /&gt;
   * on all verticies.&lt;br /&gt;
   * &lt;br /&gt;
   * @see Vertex#clearMark()&lt;br /&gt;
   */&lt;br /&gt;
  public void clearMark() {&lt;br /&gt;
    for (Vertex&amp;lt;T&amp;gt; w : verticies)&lt;br /&gt;
      w.clearMark();&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Clear the mark state of all edges in the graph by calling clearMark() on&lt;br /&gt;
   * all edges.&lt;br /&gt;
   */&lt;br /&gt;
  public void clearEdges() {&lt;br /&gt;
    for (Edge&amp;lt;T&amp;gt; e : edges)&lt;br /&gt;
      e.clearMark();&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Perform a depth first serach using recursion.&lt;br /&gt;
   * &lt;br /&gt;
   * @param v -&lt;br /&gt;
   *          the Vertex to start the search from&lt;br /&gt;
   * @param visitor -&lt;br /&gt;
   *          the vistor to inform prior to&lt;br /&gt;
   * @see Visitor#visit(Graph, Vertex)&lt;br /&gt;
   */&lt;br /&gt;
  public void depthFirstSearch(Vertex&amp;lt;T&amp;gt; v, final Visitor&amp;lt;T&amp;gt; visitor) {&lt;br /&gt;
    VisitorEX&amp;lt;T, RuntimeException&amp;gt; wrapper = new VisitorEX&amp;lt;T, RuntimeException&amp;gt;() {&lt;br /&gt;
      public void visit(Graph&amp;lt;T&amp;gt; g, Vertex&amp;lt;T&amp;gt; v) throws RuntimeException {&lt;br /&gt;
        if (visitor != null)&lt;br /&gt;
          visitor.visit(g, v);&lt;br /&gt;
      }&lt;br /&gt;
    };&lt;br /&gt;
    this.depthFirstSearch(v, wrapper);&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Perform a depth first serach using recursion. The search may be cut short&lt;br /&gt;
   * if the visitor throws an exception.&lt;br /&gt;
   * &lt;br /&gt;
   * @param &amp;lt;E&amp;gt;&lt;br /&gt;
   * &lt;br /&gt;
   * @param v -&lt;br /&gt;
   *          the Vertex to start the search from&lt;br /&gt;
   * @param visitor -&lt;br /&gt;
   *          the vistor to inform prior to&lt;br /&gt;
   * @see Visitor#visit(Graph, Vertex)&lt;br /&gt;
   * @throws E&lt;br /&gt;
   *           if visitor.visit throws an exception&lt;br /&gt;
   */&lt;br /&gt;
  public &amp;lt;E extends Exception&amp;gt; void depthFirstSearch(Vertex&amp;lt;T&amp;gt; v, VisitorEX&amp;lt;T, E&amp;gt; visitor) throws E {&lt;br /&gt;
    if (visitor != null)&lt;br /&gt;
      visitor.visit(this, v);&lt;br /&gt;
    v.visit();&lt;br /&gt;
    for (int i = 0; i &amp;lt; v.getOutgoingEdgeCount(); i++) {&lt;br /&gt;
      Edge&amp;lt;T&amp;gt; e = v.getOutgoingEdge(i);&lt;br /&gt;
      if (!e.getTo().visited()) {&lt;br /&gt;
        depthFirstSearch(e.getTo(), visitor);&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Perform a breadth first search of this graph, starting at v.&lt;br /&gt;
   * &lt;br /&gt;
   * @param v -&lt;br /&gt;
   *          the search starting point&lt;br /&gt;
   * @param visitor -&lt;br /&gt;
   *          the vistor whose vist method is called prior to visting a vertex.&lt;br /&gt;
   */&lt;br /&gt;
  public void breadthFirstSearch(Vertex&amp;lt;T&amp;gt; v, final Visitor&amp;lt;T&amp;gt; visitor) {&lt;br /&gt;
    VisitorEX&amp;lt;T, RuntimeException&amp;gt; wrapper = new VisitorEX&amp;lt;T, RuntimeException&amp;gt;() {&lt;br /&gt;
      public void visit(Graph&amp;lt;T&amp;gt; g, Vertex&amp;lt;T&amp;gt; v) throws RuntimeException {&lt;br /&gt;
        if (visitor != null)&lt;br /&gt;
          visitor.visit(g, v);&lt;br /&gt;
      }&lt;br /&gt;
    };&lt;br /&gt;
    this.breadthFirstSearch(v, wrapper);&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Perform a breadth first search of this graph, starting at v. The vist may&lt;br /&gt;
   * be cut short if visitor throws an exception during a vist callback.&lt;br /&gt;
   * &lt;br /&gt;
   * @param &amp;lt;E&amp;gt;&lt;br /&gt;
   * &lt;br /&gt;
   * @param v -&lt;br /&gt;
   *          the search starting point&lt;br /&gt;
   * @param visitor -&lt;br /&gt;
   *          the vistor whose vist method is called prior to visting a vertex.&lt;br /&gt;
   * @throws E&lt;br /&gt;
   *           if vistor.visit throws an exception&lt;br /&gt;
   */&lt;br /&gt;
  public &amp;lt;E extends Exception&amp;gt; void breadthFirstSearch(Vertex&amp;lt;T&amp;gt; v, VisitorEX&amp;lt;T, E&amp;gt; visitor)&lt;br /&gt;
      throws E {&lt;br /&gt;
    LinkedList&amp;lt;Vertex&amp;lt;T&amp;gt;&amp;gt; q = new LinkedList&amp;lt;Vertex&amp;lt;T&amp;gt;&amp;gt;();&lt;br /&gt;
    q.add(v);&lt;br /&gt;
    if (visitor != null)&lt;br /&gt;
      visitor.visit(this, v);&lt;br /&gt;
    v.visit();&lt;br /&gt;
    while (q.isEmpty() == false) {&lt;br /&gt;
      v = q.removeFirst();&lt;br /&gt;
      for (int i = 0; i &amp;lt; v.getOutgoingEdgeCount(); i++) {&lt;br /&gt;
        Edge&amp;lt;T&amp;gt; e = v.getOutgoingEdge(i);&lt;br /&gt;
        Vertex&amp;lt;T&amp;gt; to = e.getTo();&lt;br /&gt;
        if (!to.visited()) {&lt;br /&gt;
          q.add(to);&lt;br /&gt;
          if (visitor != null)&lt;br /&gt;
            visitor.visit(this, to);&lt;br /&gt;
          to.visit();&lt;br /&gt;
        }&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Find the spanning tree using a DFS starting from v.&lt;br /&gt;
   * &lt;br /&gt;
   * @param v -&lt;br /&gt;
   *          the vertex to start the search from&lt;br /&gt;
   * @param visitor -&lt;br /&gt;
   *          visitor invoked after each vertex is visited and an edge is added&lt;br /&gt;
   *          to the tree.&lt;br /&gt;
   */&lt;br /&gt;
  public void dfsSpanningTree(Vertex&amp;lt;T&amp;gt; v, DFSVisitor&amp;lt;T&amp;gt; visitor) {&lt;br /&gt;
    v.visit();&lt;br /&gt;
    if (visitor != null)&lt;br /&gt;
      visitor.visit(this, v);&lt;br /&gt;
    for (int i = 0; i &amp;lt; v.getOutgoingEdgeCount(); i++) {&lt;br /&gt;
      Edge&amp;lt;T&amp;gt; e = v.getOutgoingEdge(i);&lt;br /&gt;
      if (!e.getTo().visited()) {&lt;br /&gt;
        if (visitor != null)&lt;br /&gt;
          visitor.visit(this, v, e);&lt;br /&gt;
        e.mark();&lt;br /&gt;
        dfsSpanningTree(e.getTo(), visitor);&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Search the verticies for one with name.&lt;br /&gt;
   * &lt;br /&gt;
   * @param name -&lt;br /&gt;
   *          the vertex name&lt;br /&gt;
   * @return the first vertex with a matching name, null if no matches are found&lt;br /&gt;
   */&lt;br /&gt;
  public Vertex&amp;lt;T&amp;gt; findVertexByName(String name) {&lt;br /&gt;
    Vertex&amp;lt;T&amp;gt; match = null;&lt;br /&gt;
    for (Vertex&amp;lt;T&amp;gt; v : verticies) {&lt;br /&gt;
      if (name.equals(v.getName())) {&lt;br /&gt;
        match = v;&lt;br /&gt;
        break;&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    return match;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Search the verticies for one with data.&lt;br /&gt;
   * &lt;br /&gt;
   * @param data -&lt;br /&gt;
   *          the vertex data to match&lt;br /&gt;
   * @param compare -&lt;br /&gt;
   *          the comparator to perform the match&lt;br /&gt;
   * @return the first vertex with a matching data, null if no matches are found&lt;br /&gt;
   */&lt;br /&gt;
  public Vertex&amp;lt;T&amp;gt; findVertexByData(T data, Comparator&amp;lt;T&amp;gt; compare) {&lt;br /&gt;
    Vertex&amp;lt;T&amp;gt; match = null;&lt;br /&gt;
    for (Vertex&amp;lt;T&amp;gt; v : verticies) {&lt;br /&gt;
      if (compare.rupare(data, v.getData()) == 0) {&lt;br /&gt;
        match = v;&lt;br /&gt;
        break;&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    return match;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Search the graph for cycles. In order to detect cycles, we use a modified&lt;br /&gt;
   * depth first search called a colored DFS. All nodes are initially marked&lt;br /&gt;
   * white. When a node is encountered, it is marked grey, and when its&lt;br /&gt;
   * descendants are completely visited, it is marked black. If a grey node is&lt;br /&gt;
   * ever encountered, then there is a cycle.&lt;br /&gt;
   * &lt;br /&gt;
   * @return the edges that form cycles in the graph. The array will be empty if&lt;br /&gt;
   *         there are no cycles.&lt;br /&gt;
   */&lt;br /&gt;
  public Edge&amp;lt;T&amp;gt;[] findCycles() {&lt;br /&gt;
    ArrayList&amp;lt;Edge&amp;lt;T&amp;gt;&amp;gt; cycleEdges = new ArrayList&amp;lt;Edge&amp;lt;T&amp;gt;&amp;gt;();&lt;br /&gt;
    // Mark all verticies as white&lt;br /&gt;
    for (int n = 0; n &amp;lt; verticies.size(); n++) {&lt;br /&gt;
      Vertex&amp;lt;T&amp;gt; v = getVertex(n);&lt;br /&gt;
      v.setMarkState(VISIT_COLOR_WHITE);&lt;br /&gt;
    }&lt;br /&gt;
    for (int n = 0; n &amp;lt; verticies.size(); n++) {&lt;br /&gt;
      Vertex&amp;lt;T&amp;gt; v = getVertex(n);&lt;br /&gt;
      visit(v, cycleEdges);&lt;br /&gt;
    }&lt;br /&gt;
    Edge&amp;lt;T&amp;gt;[] cycles = new Edge[cycleEdges.size()];&lt;br /&gt;
    cycleEdges.toArray(cycles);&lt;br /&gt;
    return cycles;&lt;br /&gt;
  }&lt;br /&gt;
  private void visit(Vertex&amp;lt;T&amp;gt; v, ArrayList&amp;lt;Edge&amp;lt;T&amp;gt;&amp;gt; cycleEdges) {&lt;br /&gt;
    v.setMarkState(VISIT_COLOR_GREY);&lt;br /&gt;
    int count = v.getOutgoingEdgeCount();&lt;br /&gt;
    for (int n = 0; n &amp;lt; count; n++) {&lt;br /&gt;
      Edge&amp;lt;T&amp;gt; e = v.getOutgoingEdge(n);&lt;br /&gt;
      Vertex&amp;lt;T&amp;gt; u = e.getTo();&lt;br /&gt;
      if (u.getMarkState() == VISIT_COLOR_GREY) {&lt;br /&gt;
        // A cycle Edge&amp;lt;T&amp;gt;&lt;br /&gt;
        cycleEdges.add(e);&lt;br /&gt;
      } else if (u.getMarkState() == VISIT_COLOR_WHITE) {&lt;br /&gt;
        visit(u, cycleEdges);&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    v.setMarkState(VISIT_COLOR_BLACK);&lt;br /&gt;
  }&lt;br /&gt;
  public String toString() {&lt;br /&gt;
    StringBuffer tmp = new StringBuffer(&amp;quot;Graph[&amp;quot;);&lt;br /&gt;
    for (Vertex&amp;lt;T&amp;gt; v : verticies)&lt;br /&gt;
      tmp.append(v);&lt;br /&gt;
    tmp.append(&amp;quot;]&amp;quot;);&lt;br /&gt;
    return tmp.toString();&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
/*&lt;br /&gt;
 * JBoss, Home of Professional Open Source Copyright 2006, Red Hat Middleware&lt;br /&gt;
 * LLC, and individual contributors by the @authors tag. See the copyright.txt&lt;br /&gt;
 * in the distribution for a full listing of individual contributors.&lt;br /&gt;
 * &lt;br /&gt;
 * This is free software; you can redistribute it and/or modify it under the&lt;br /&gt;
 * terms of the GNU Lesser General Public License as published by the Free&lt;br /&gt;
 * Software Foundation; either version 2.1 of the License, or (at your option)&lt;br /&gt;
 * any later version.&lt;br /&gt;
 * &lt;br /&gt;
 * This software is distributed in the hope that it will be useful, but WITHOUT&lt;br /&gt;
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS&lt;br /&gt;
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more&lt;br /&gt;
 * details.&lt;br /&gt;
 * &lt;br /&gt;
 * You should have received a copy of the GNU Lesser General Public License&lt;br /&gt;
 * along with this software; if not, write to the Free Software Foundation,&lt;br /&gt;
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF&lt;br /&gt;
 * site: http://www.fsf.org.&lt;br /&gt;
 */&lt;br /&gt;
/**&lt;br /&gt;
 * A directed, weighted edge in a graph&lt;br /&gt;
 * &lt;br /&gt;
 * @author Scott.Stark@jboss.org&lt;br /&gt;
 * @version $Revision$&lt;br /&gt;
 * @param &amp;lt;T&amp;gt;&lt;br /&gt;
 */&lt;br /&gt;
class Edge&amp;lt;T&amp;gt; {&lt;br /&gt;
  private Vertex&amp;lt;T&amp;gt; from;&lt;br /&gt;
  private Vertex&amp;lt;T&amp;gt; to;&lt;br /&gt;
  private int cost;&lt;br /&gt;
  private boolean mark;&lt;br /&gt;
  /**&lt;br /&gt;
   * Create a zero cost edge between from and to&lt;br /&gt;
   * &lt;br /&gt;
   * @param from&lt;br /&gt;
   *          the starting vertex&lt;br /&gt;
   * @param to&lt;br /&gt;
   *          the ending vertex&lt;br /&gt;
   */&lt;br /&gt;
  public Edge(Vertex&amp;lt;T&amp;gt; from, Vertex&amp;lt;T&amp;gt; to) {&lt;br /&gt;
    this(from, to, 0);&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Create an edge between from and to with the given cost.&lt;br /&gt;
   * &lt;br /&gt;
   * @param from&lt;br /&gt;
   *          the starting vertex&lt;br /&gt;
   * @param to&lt;br /&gt;
   *          the ending vertex&lt;br /&gt;
   * @param cost&lt;br /&gt;
   *          the cost of the edge&lt;br /&gt;
   */&lt;br /&gt;
  public Edge(Vertex&amp;lt;T&amp;gt; from, Vertex&amp;lt;T&amp;gt; to, int cost) {&lt;br /&gt;
    this.from = from;&lt;br /&gt;
    this.to = to;&lt;br /&gt;
    this.cost = cost;&lt;br /&gt;
    mark = false;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Get the ending vertex&lt;br /&gt;
   * &lt;br /&gt;
   * @return ending vertex&lt;br /&gt;
   */&lt;br /&gt;
  public Vertex&amp;lt;T&amp;gt; getTo() {&lt;br /&gt;
    return to;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Get the starting vertex&lt;br /&gt;
   * &lt;br /&gt;
   * @return starting vertex&lt;br /&gt;
   */&lt;br /&gt;
  public Vertex&amp;lt;T&amp;gt; getFrom() {&lt;br /&gt;
    return from;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Get the cost of the edge&lt;br /&gt;
   * &lt;br /&gt;
   * @return cost of the edge&lt;br /&gt;
   */&lt;br /&gt;
  public int getCost() {&lt;br /&gt;
    return cost;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Set the mark flag of the edge&lt;br /&gt;
   * &lt;br /&gt;
   */&lt;br /&gt;
  public void mark() {&lt;br /&gt;
    mark = true;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Clear the edge mark flag&lt;br /&gt;
   * &lt;br /&gt;
   */&lt;br /&gt;
  public void clearMark() {&lt;br /&gt;
    mark = false;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Get the edge mark flag&lt;br /&gt;
   * &lt;br /&gt;
   * @return edge mark flag&lt;br /&gt;
   */&lt;br /&gt;
  public boolean isMarked() {&lt;br /&gt;
    return mark;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * String rep of edge&lt;br /&gt;
   * &lt;br /&gt;
   * @return string rep with from/to vertex names and cost&lt;br /&gt;
   */&lt;br /&gt;
  public String toString() {&lt;br /&gt;
    StringBuffer tmp = new StringBuffer(&amp;quot;Edge[from: &amp;quot;);&lt;br /&gt;
    tmp.append(from.getName());&lt;br /&gt;
    tmp.append(&amp;quot;,to: &amp;quot;);&lt;br /&gt;
    tmp.append(to.getName());&lt;br /&gt;
    tmp.append(&amp;quot;, cost: &amp;quot;);&lt;br /&gt;
    tmp.append(cost);&lt;br /&gt;
    tmp.append(&amp;quot;]&amp;quot;);&lt;br /&gt;
    return tmp.toString();&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
/*&lt;br /&gt;
 * JBoss, Home of Professional Open Source Copyright 2006, Red Hat Middleware&lt;br /&gt;
 * LLC, and individual contributors by the @authors tag. See the copyright.txt&lt;br /&gt;
 * in the distribution for a full listing of individual contributors.&lt;br /&gt;
 * &lt;br /&gt;
 * This is free software; you can redistribute it and/or modify it under the&lt;br /&gt;
 * terms of the GNU Lesser General Public License as published by the Free&lt;br /&gt;
 * Software Foundation; either version 2.1 of the License, or (at your option)&lt;br /&gt;
 * any later version.&lt;br /&gt;
 * &lt;br /&gt;
 * This software is distributed in the hope that it will be useful, but WITHOUT&lt;br /&gt;
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS&lt;br /&gt;
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more&lt;br /&gt;
 * details.&lt;br /&gt;
 * &lt;br /&gt;
 * You should have received a copy of the GNU Lesser General Public License&lt;br /&gt;
 * along with this software; if not, write to the Free Software Foundation,&lt;br /&gt;
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF&lt;br /&gt;
 * site: http://www.fsf.org.&lt;br /&gt;
 */&lt;br /&gt;
/**&lt;br /&gt;
 * A named graph vertex with optional data.&lt;br /&gt;
 * &lt;br /&gt;
 * @author Scott.Stark@jboss.org&lt;br /&gt;
 * @version $Revision$&lt;br /&gt;
 * @param &amp;lt;T&amp;gt;&lt;br /&gt;
 */&lt;br /&gt;
@SuppressWarnings(&amp;quot;unchecked&amp;quot;)&lt;br /&gt;
class Vertex&amp;lt;T&amp;gt; {&lt;br /&gt;
  private List&amp;lt;Edge&amp;lt;T&amp;gt;&amp;gt; incomingEdges;&lt;br /&gt;
  private List&amp;lt;Edge&amp;lt;T&amp;gt;&amp;gt; outgoingEdges;&lt;br /&gt;
  private String name;&lt;br /&gt;
  private boolean mark;&lt;br /&gt;
  private int markState;&lt;br /&gt;
  private T data;&lt;br /&gt;
  /**&lt;br /&gt;
   * Calls this(null, null).&lt;br /&gt;
   */&lt;br /&gt;
  public Vertex() {&lt;br /&gt;
    this(null, null);&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Create a vertex with the given name and no data&lt;br /&gt;
   * &lt;br /&gt;
   * @param n&lt;br /&gt;
   */&lt;br /&gt;
  public Vertex(String n) {&lt;br /&gt;
    this(n, null);&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Create a Vertex with name n and given data&lt;br /&gt;
   * &lt;br /&gt;
   * @param n -&lt;br /&gt;
   *          name of vertex&lt;br /&gt;
   * @param data -&lt;br /&gt;
   *          data associated with vertex&lt;br /&gt;
   */&lt;br /&gt;
  public Vertex(String n, T data) {&lt;br /&gt;
    incomingEdges = new ArrayList&amp;lt;Edge&amp;lt;T&amp;gt;&amp;gt;();&lt;br /&gt;
    outgoingEdges = new ArrayList&amp;lt;Edge&amp;lt;T&amp;gt;&amp;gt;();&lt;br /&gt;
    name = n;&lt;br /&gt;
    mark = false;&lt;br /&gt;
    this.data = data;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * @return the possibly null name of the vertex&lt;br /&gt;
   */&lt;br /&gt;
  public String getName() {&lt;br /&gt;
    return name;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * @return the possibly null data of the vertex&lt;br /&gt;
   */&lt;br /&gt;
  public T getData() {&lt;br /&gt;
    return this.data;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * @param data&lt;br /&gt;
   *          The data to set.&lt;br /&gt;
   */&lt;br /&gt;
  public void setData(T data) {&lt;br /&gt;
    this.data = data;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Add an edge to the vertex. If edge.from is this vertex, its an outgoing&lt;br /&gt;
   * edge. If edge.to is this vertex, its an incoming edge. If neither from or&lt;br /&gt;
   * to is this vertex, the edge is not added.&lt;br /&gt;
   * &lt;br /&gt;
   * @param e -&lt;br /&gt;
   *          the edge to add&lt;br /&gt;
   * @return true if the edge was added, false otherwise&lt;br /&gt;
   */&lt;br /&gt;
  public boolean addEdge(Edge&amp;lt;T&amp;gt; e) {&lt;br /&gt;
    if (e.getFrom() == this)&lt;br /&gt;
      outgoingEdges.add(e);&lt;br /&gt;
    else if (e.getTo() == this)&lt;br /&gt;
      incomingEdges.add(e);&lt;br /&gt;
    else&lt;br /&gt;
      return false;&lt;br /&gt;
    return true;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Add an outgoing edge ending at to.&lt;br /&gt;
   * &lt;br /&gt;
   * @param to -&lt;br /&gt;
   *          the destination vertex&lt;br /&gt;
   * @param cost&lt;br /&gt;
   *          the edge cost&lt;br /&gt;
   */&lt;br /&gt;
  public void addOutgoingEdge(Vertex&amp;lt;T&amp;gt; to, int cost) {&lt;br /&gt;
    Edge&amp;lt;T&amp;gt; out = new Edge&amp;lt;T&amp;gt;(this, to, cost);&lt;br /&gt;
    outgoingEdges.add(out);&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Add an incoming edge starting at from&lt;br /&gt;
   * &lt;br /&gt;
   * @param from -&lt;br /&gt;
   *          the starting vertex&lt;br /&gt;
   * @param cost&lt;br /&gt;
   *          the edge cost&lt;br /&gt;
   */&lt;br /&gt;
  public void addIncomingEdge(Vertex&amp;lt;T&amp;gt; from, int cost) {&lt;br /&gt;
    Edge&amp;lt;T&amp;gt; out = new Edge&amp;lt;T&amp;gt;(this, from, cost);&lt;br /&gt;
    incomingEdges.add(out);&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Check the vertex for either an incoming or outgoing edge mathcing e.&lt;br /&gt;
   * &lt;br /&gt;
   * @param e&lt;br /&gt;
   *          the edge to check&lt;br /&gt;
   * @return true it has an edge&lt;br /&gt;
   */&lt;br /&gt;
  public boolean hasEdge(Edge&amp;lt;T&amp;gt; e) {&lt;br /&gt;
    if (e.getFrom() == this)&lt;br /&gt;
      return incomingEdges.contains(e);&lt;br /&gt;
    else if (e.getTo() == this)&lt;br /&gt;
      return outgoingEdges.contains(e);&lt;br /&gt;
    else&lt;br /&gt;
      return false;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Remove an edge from this vertex&lt;br /&gt;
   * &lt;br /&gt;
   * @param e -&lt;br /&gt;
   *          the edge to remove&lt;br /&gt;
   * @return true if the edge was removed, false if the edge was not connected&lt;br /&gt;
   *         to this vertex&lt;br /&gt;
   */&lt;br /&gt;
  public boolean remove(Edge&amp;lt;T&amp;gt; e) {&lt;br /&gt;
    if (e.getFrom() == this)&lt;br /&gt;
      incomingEdges.remove(e);&lt;br /&gt;
    else if (e.getTo() == this)&lt;br /&gt;
      outgoingEdges.remove(e);&lt;br /&gt;
    else&lt;br /&gt;
      return false;&lt;br /&gt;
    return true;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * &lt;br /&gt;
   * @return the count of incoming edges&lt;br /&gt;
   */&lt;br /&gt;
  public int getIncomingEdgeCount() {&lt;br /&gt;
    return incomingEdges.size();&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Get the ith incoming edge&lt;br /&gt;
   * &lt;br /&gt;
   * @param i&lt;br /&gt;
   *          the index into incoming edges&lt;br /&gt;
   * @return ith incoming edge&lt;br /&gt;
   */&lt;br /&gt;
  public Edge&amp;lt;T&amp;gt; getIncomingEdge(int i) {&lt;br /&gt;
    return incomingEdges.get(i);&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Get the incoming edges&lt;br /&gt;
   * &lt;br /&gt;
   * @return incoming edge list&lt;br /&gt;
   */&lt;br /&gt;
  public List getIncomingEdges() {&lt;br /&gt;
    return this.incomingEdges;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * &lt;br /&gt;
   * @return the count of incoming edges&lt;br /&gt;
   */&lt;br /&gt;
  public int getOutgoingEdgeCount() {&lt;br /&gt;
    return outgoingEdges.size();&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Get the ith outgoing edge&lt;br /&gt;
   * &lt;br /&gt;
   * @param i&lt;br /&gt;
   *          the index into outgoing edges&lt;br /&gt;
   * @return ith outgoing edge&lt;br /&gt;
   */&lt;br /&gt;
  public Edge&amp;lt;T&amp;gt; getOutgoingEdge(int i) {&lt;br /&gt;
    return outgoingEdges.get(i);&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Get the outgoing edges&lt;br /&gt;
   * &lt;br /&gt;
   * @return outgoing edge list&lt;br /&gt;
   */&lt;br /&gt;
  public List getOutgoingEdges() {&lt;br /&gt;
    return this.outgoingEdges;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Search the outgoing edges looking for an edge whose&amp;quot;s edge.to == dest.&lt;br /&gt;
   * &lt;br /&gt;
   * @param dest&lt;br /&gt;
   *          the destination&lt;br /&gt;
   * @return the outgoing edge going to dest if one exists, null otherwise.&lt;br /&gt;
   */&lt;br /&gt;
  public Edge&amp;lt;T&amp;gt; findEdge(Vertex&amp;lt;T&amp;gt; dest) {&lt;br /&gt;
    for (Edge&amp;lt;T&amp;gt; e : outgoingEdges) {&lt;br /&gt;
      if (e.getTo() == dest)&lt;br /&gt;
        return e;&lt;br /&gt;
    }&lt;br /&gt;
    return null;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Search the outgoing edges for a match to e.&lt;br /&gt;
   * &lt;br /&gt;
   * @param e -&lt;br /&gt;
   *          the edge to check&lt;br /&gt;
   * @return e if its a member of the outgoing edges, null otherwise.&lt;br /&gt;
   */&lt;br /&gt;
  public Edge&amp;lt;T&amp;gt; findEdge(Edge&amp;lt;T&amp;gt; e) {&lt;br /&gt;
    if (outgoingEdges.contains(e))&lt;br /&gt;
      return e;&lt;br /&gt;
    else&lt;br /&gt;
      return null;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * What is the cost from this vertext to the dest vertex.&lt;br /&gt;
   * &lt;br /&gt;
   * @param dest -&lt;br /&gt;
   *          the destination vertex.&lt;br /&gt;
   * @return Return Integer.MAX_VALUE if we have no edge to dest, 0 if dest is&lt;br /&gt;
   *         this vertex, the cost of the outgoing edge otherwise.&lt;br /&gt;
   */&lt;br /&gt;
  public int cost(Vertex&amp;lt;T&amp;gt; dest) {&lt;br /&gt;
    if (dest == this)&lt;br /&gt;
      return 0;&lt;br /&gt;
    Edge&amp;lt;T&amp;gt; e = findEdge(dest);&lt;br /&gt;
    int cost = Integer.MAX_VALUE;&lt;br /&gt;
    if (e != null)&lt;br /&gt;
      cost = e.getCost();&lt;br /&gt;
    return cost;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Is there an outgoing edge ending at dest.&lt;br /&gt;
   * &lt;br /&gt;
   * @param dest -&lt;br /&gt;
   *          the vertex to check&lt;br /&gt;
   * @return true if there is an outgoing edge ending at vertex, false&lt;br /&gt;
   *         otherwise.&lt;br /&gt;
   */&lt;br /&gt;
  public boolean hasEdge(Vertex&amp;lt;T&amp;gt; dest) {&lt;br /&gt;
    return (findEdge(dest) != null);&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Has this vertex been marked during a visit&lt;br /&gt;
   * &lt;br /&gt;
   * @return true is visit has been called&lt;br /&gt;
   */&lt;br /&gt;
  public boolean visited() {&lt;br /&gt;
    return mark;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Set the vertex mark flag.&lt;br /&gt;
   * &lt;br /&gt;
   */&lt;br /&gt;
  public void mark() {&lt;br /&gt;
    mark = true;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Set the mark state to state.&lt;br /&gt;
   * &lt;br /&gt;
   * @param state&lt;br /&gt;
   *          the state&lt;br /&gt;
   */&lt;br /&gt;
  public void setMarkState(int state) {&lt;br /&gt;
    markState = state;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Get the mark state value.&lt;br /&gt;
   * &lt;br /&gt;
   * @return the mark state&lt;br /&gt;
   */&lt;br /&gt;
  public int getMarkState() {&lt;br /&gt;
    return markState;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Visit the vertex and set the mark flag to true.&lt;br /&gt;
   * &lt;br /&gt;
   */&lt;br /&gt;
  public void visit() {&lt;br /&gt;
    mark();&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Clear the visited mark flag.&lt;br /&gt;
   * &lt;br /&gt;
   */&lt;br /&gt;
  public void clearMark() {&lt;br /&gt;
    mark = false;&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * @return a string form of the vertex with in and out edges.&lt;br /&gt;
   */&lt;br /&gt;
  public String toString() {&lt;br /&gt;
    StringBuffer tmp = new StringBuffer(&amp;quot;Vertex(&amp;quot;);&lt;br /&gt;
    tmp.append(name);&lt;br /&gt;
    tmp.append(&amp;quot;, data=&amp;quot;);&lt;br /&gt;
    tmp.append(data);&lt;br /&gt;
    tmp.append(&amp;quot;), in:[&amp;quot;);&lt;br /&gt;
    for (int i = 0; i &amp;lt; incomingEdges.size(); i++) {&lt;br /&gt;
      Edge&amp;lt;T&amp;gt; e = incomingEdges.get(i);&lt;br /&gt;
      if (i &amp;gt; 0)&lt;br /&gt;
        tmp.append(&amp;quot;,&amp;quot;);&lt;br /&gt;
      tmp.append(&amp;quot;{&amp;quot;);&lt;br /&gt;
      tmp.append(e.getFrom().name);&lt;br /&gt;
      tmp.append(&amp;quot;,&amp;quot;);&lt;br /&gt;
      tmp.append(e.getCost());&lt;br /&gt;
      tmp.append(&amp;quot;}&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    tmp.append(&amp;quot;], out:[&amp;quot;);&lt;br /&gt;
    for (int i = 0; i &amp;lt; outgoingEdges.size(); i++) {&lt;br /&gt;
      Edge&amp;lt;T&amp;gt; e = outgoingEdges.get(i);&lt;br /&gt;
      if (i &amp;gt; 0)&lt;br /&gt;
        tmp.append(&amp;quot;,&amp;quot;);&lt;br /&gt;
      tmp.append(&amp;quot;{&amp;quot;);&lt;br /&gt;
      tmp.append(e.getTo().name);&lt;br /&gt;
      tmp.append(&amp;quot;,&amp;quot;);&lt;br /&gt;
      tmp.append(e.getCost());&lt;br /&gt;
      tmp.append(&amp;quot;}&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    tmp.append(&amp;quot;]&amp;quot;);&lt;br /&gt;
    return tmp.toString();&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
/*&lt;br /&gt;
 * JBoss, Home of Professional Open Source Copyright 2006, Red Hat Middleware&lt;br /&gt;
 * LLC, and individual contributors by the @authors tag. See the copyright.txt&lt;br /&gt;
 * in the distribution for a full listing of individual contributors.&lt;br /&gt;
 * &lt;br /&gt;
 * This is free software; you can redistribute it and/or modify it under the&lt;br /&gt;
 * terms of the GNU Lesser General Public License as published by the Free&lt;br /&gt;
 * Software Foundation; either version 2.1 of the License, or (at your option)&lt;br /&gt;
 * any later version.&lt;br /&gt;
 * &lt;br /&gt;
 * This software is distributed in the hope that it will be useful, but WITHOUT&lt;br /&gt;
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS&lt;br /&gt;
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more&lt;br /&gt;
 * details.&lt;br /&gt;
 * &lt;br /&gt;
 * You should have received a copy of the GNU Lesser General Public License&lt;br /&gt;
 * along with this software; if not, write to the Free Software Foundation,&lt;br /&gt;
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF&lt;br /&gt;
 * site: http://www.fsf.org.&lt;br /&gt;
 */&lt;br /&gt;
/**&lt;br /&gt;
 * A graph visitor interface.&lt;br /&gt;
 * &lt;br /&gt;
 * @author Scott.Stark@jboss.org&lt;br /&gt;
 * @version $Revision$&lt;br /&gt;
 * @param &amp;lt;T&amp;gt;&lt;br /&gt;
 */&lt;br /&gt;
interface Visitor&amp;lt;T&amp;gt; {&lt;br /&gt;
  /**&lt;br /&gt;
   * Called by the graph traversal methods when a vertex is first visited.&lt;br /&gt;
   * &lt;br /&gt;
   * @param g -&lt;br /&gt;
   *          the graph&lt;br /&gt;
   * @param v -&lt;br /&gt;
   *          the vertex being visited.&lt;br /&gt;
   */&lt;br /&gt;
  public void visit(Graph&amp;lt;T&amp;gt; g, Vertex&amp;lt;T&amp;gt; v);&lt;br /&gt;
}&lt;br /&gt;
/*&lt;br /&gt;
 * JBoss, Home of Professional Open Source Copyright 2006, Red Hat Middleware&lt;br /&gt;
 * LLC, and individual contributors by the @authors tag. See the copyright.txt&lt;br /&gt;
 * in the distribution for a full listing of individual contributors.&lt;br /&gt;
 * &lt;br /&gt;
 * This is free software; you can redistribute it and/or modify it under the&lt;br /&gt;
 * terms of the GNU Lesser General Public License as published by the Free&lt;br /&gt;
 * Software Foundation; either version 2.1 of the License, or (at your option)&lt;br /&gt;
 * any later version.&lt;br /&gt;
 * &lt;br /&gt;
 * This software is distributed in the hope that it will be useful, but WITHOUT&lt;br /&gt;
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS&lt;br /&gt;
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more&lt;br /&gt;
 * details.&lt;br /&gt;
 * &lt;br /&gt;
 * You should have received a copy of the GNU Lesser General Public License&lt;br /&gt;
 * along with this software; if not, write to the Free Software Foundation,&lt;br /&gt;
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF&lt;br /&gt;
 * site: http://www.fsf.org.&lt;br /&gt;
 */&lt;br /&gt;
/**&lt;br /&gt;
 * A graph visitor interface that can throw an exception during a visit&lt;br /&gt;
 * callback.&lt;br /&gt;
 * &lt;br /&gt;
 * @author Scott.Stark@jboss.org&lt;br /&gt;
 * @version $Revision$&lt;br /&gt;
 * @param &amp;lt;T&amp;gt;&lt;br /&gt;
 * @param &amp;lt;E&amp;gt;&lt;br /&gt;
 */&lt;br /&gt;
interface VisitorEX&amp;lt;T, E extends Exception&amp;gt; {&lt;br /&gt;
  /**&lt;br /&gt;
   * Called by the graph traversal methods when a vertex is first visited.&lt;br /&gt;
   * &lt;br /&gt;
   * @param g -&lt;br /&gt;
   *          the graph&lt;br /&gt;
   * @param v -&lt;br /&gt;
   *          the vertex being visited.&lt;br /&gt;
   * @throws E&lt;br /&gt;
   *           exception for any error&lt;br /&gt;
   */&lt;br /&gt;
  public void visit(Graph&amp;lt;T&amp;gt; g, Vertex&amp;lt;T&amp;gt; v) throws E;&lt;br /&gt;
}&lt;br /&gt;
/*&lt;br /&gt;
 * JBoss, Home of Professional Open Source Copyright 2006, Red Hat Middleware&lt;br /&gt;
 * LLC, and individual contributors by the @authors tag. See the copyright.txt&lt;br /&gt;
 * in the distribution for a full listing of individual contributors.&lt;br /&gt;
 * &lt;br /&gt;
 * This is free software; you can redistribute it and/or modify it under the&lt;br /&gt;
 * terms of the GNU Lesser General Public License as published by the Free&lt;br /&gt;
 * Software Foundation; either version 2.1 of the License, or (at your option)&lt;br /&gt;
 * any later version.&lt;br /&gt;
 * &lt;br /&gt;
 * This software is distributed in the hope that it will be useful, but WITHOUT&lt;br /&gt;
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS&lt;br /&gt;
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more&lt;br /&gt;
 * details.&lt;br /&gt;
 * &lt;br /&gt;
 * You should have received a copy of the GNU Lesser General Public License&lt;br /&gt;
 * along with this software; if not, write to the Free Software Foundation,&lt;br /&gt;
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF&lt;br /&gt;
 * site: http://www.fsf.org.&lt;br /&gt;
 */&lt;br /&gt;
/**&lt;br /&gt;
 * A spanning tree visitor callback interface&lt;br /&gt;
 * &lt;br /&gt;
 * @see Graph#dfsSpanningTree(Vertex, DFSVisitor)&lt;br /&gt;
 * &lt;br /&gt;
 * @author Scott.Stark@jboss.org&lt;br /&gt;
 * @version $Revision$&lt;br /&gt;
 * @param &amp;lt;T&amp;gt;&lt;br /&gt;
 */&lt;br /&gt;
interface DFSVisitor&amp;lt;T&amp;gt; {&lt;br /&gt;
  /**&lt;br /&gt;
   * Called by the graph traversal methods when a vertex is first visited.&lt;br /&gt;
   * &lt;br /&gt;
   * @param g -&lt;br /&gt;
   *          the graph&lt;br /&gt;
   * @param v -&lt;br /&gt;
   *          the vertex being visited.&lt;br /&gt;
   */&lt;br /&gt;
  public void visit(Graph&amp;lt;T&amp;gt; g, Vertex&amp;lt;T&amp;gt; v);&lt;br /&gt;
  /**&lt;br /&gt;
   * Used dfsSpanningTree to notify the visitor of each outgoing edge to an&lt;br /&gt;
   * unvisited vertex.&lt;br /&gt;
   * &lt;br /&gt;
   * @param g -&lt;br /&gt;
   *          the graph&lt;br /&gt;
   * @param v -&lt;br /&gt;
   *          the vertex being visited&lt;br /&gt;
   * @param e -&lt;br /&gt;
   *          the outgoing edge from v&lt;br /&gt;
   */&lt;br /&gt;
  public void visit(Graph&amp;lt;T&amp;gt; g, Vertex&amp;lt;T&amp;gt; v, Edge&amp;lt;T&amp;gt; e);&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;/div&gt;</summary>
			</entry>

	</feed>