com.arsdigita.util
Class GraphSet

java.lang.Object
  extended bycom.arsdigita.util.GraphSet
All Implemented Interfaces:
Graph

public class GraphSet
extends Object
implements Graph

A Set-based implementation of the Graph interface. Once you've added a node to this graph, you must not mutate the node in a way that affects its equals(Object) and hashCode() methods.

This class permits the null node.

This implementation is not synchronized..

Since:
2003-01-22
Version:
$Date: 2004/04/07 $
Author:
Archit Shah (ashah@mit.edut), Vadim Nasardinov (vadimn@redhat.com)

Nested Class Summary
 
Nested classes inherited from class com.arsdigita.util.Graph
Graph.Edge
 
Constructor Summary
GraphSet()
           
 
Method Summary
 void addEdge(Graph.Edge edge)
          Adds an edge to the graph.
 void addEdge(Object tail, Object head, Object label)
          A convenient shortcut for addEdge(new Graph.Edge(tail, head, label)).
 void addNode(Object name)
          Adds a node to the graph.
 Graph copy()
          Creates a copy of this graph.
 List getIncomingEdges(Object node)
           
 String getLabel()
          Returns the graph's label.
 List getNodes()
          Returns a list of nodes that this graph has.
 List getOutgoingEdges(Object node)
          Returns a list of outgoing edges leaving this node.
 boolean hasEdge(Graph.Edge edge)
          Returns true if the graph has this edge.
 boolean hasNode(Object nodeName)
          Returns true if the graph has this node.
 int incomingEdgeCount(Object node)
           
 int nodeCount()
          Returns the count of nodes in this graph.
 int outgoingEdgeCount(Object node)
          Returns the number of outgoing edges this node has.
 void removeAll()
          Removes all nodes and edges.
 boolean removeEdge(Graph.Edge edge)
          Removes specified edge.
 boolean removeEdge(Object tail, Object head, Object label)
          A convenient shortcut for removeEdge(new Graph.Edge(tail, head, label)).
 boolean removeNode(Object nodeName)
          Removes specified node and all edges incident to it.
 void setLabel(String label)
          Sets the graph's label.
 String toString()
          Returns a printable representation of the graph that has the following form.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GraphSet

public GraphSet()
Method Detail

copy

public Graph copy()
Description copied from interface: Graph
Creates a copy of this graph.

Specified by:
copy in interface Graph

setLabel

public void setLabel(String label)
Description copied from interface: Graph
Sets the graph's label.

Specified by:
setLabel in interface Graph

getLabel

public String getLabel()
Description copied from interface: Graph
Returns the graph's label.

Specified by:
getLabel in interface Graph

addNode

public void addNode(Object name)
Description copied from interface: Graph
Adds a node to the graph.

Specified by:
addNode in interface Graph

hasNode

public boolean hasNode(Object nodeName)
Description copied from interface: Graph
Returns true if the graph has this node.

Specified by:
hasNode in interface Graph

hasEdge

public boolean hasEdge(Graph.Edge edge)
Description copied from interface: Graph
Returns true if the graph has this edge.

Specified by:
hasEdge in interface Graph

nodeCount

public int nodeCount()
Description copied from interface: Graph
Returns the count of nodes in this graph.

Specified by:
nodeCount in interface Graph

addEdge

public void addEdge(Graph.Edge edge)
Description copied from interface: Graph
Adds an edge to the graph.

Specified by:
addEdge in interface Graph

addEdge

public void addEdge(Object tail,
                    Object head,
                    Object label)
Description copied from interface: Graph
A convenient shortcut for addEdge(new Graph.Edge(tail, head, label)).

Specified by:
addEdge in interface Graph
See Also:
Graph.addEdge(Graph.Edge)

getNodes

public List getNodes()
Description copied from interface: Graph
Returns a list of nodes that this graph has. (Todo: this should probably return a Set.)

Specified by:
getNodes in interface Graph

removeNode

public boolean removeNode(Object nodeName)
Description copied from interface: Graph
Removes specified node and all edges incident to it.

Specified by:
removeNode in interface Graph

removeEdge

public boolean removeEdge(Object tail,
                          Object head,
                          Object label)
Description copied from interface: Graph
A convenient shortcut for removeEdge(new Graph.Edge(tail, head, label)).

Specified by:
removeEdge in interface Graph
See Also:
Graph.removeEdge(Graph.Edge)

removeEdge

public boolean removeEdge(Graph.Edge edge)
Description copied from interface: Graph
Removes specified edge.

Specified by:
removeEdge in interface Graph

removeAll

public void removeAll()
Description copied from interface: Graph
Removes all nodes and edges.

Specified by:
removeAll in interface Graph

getOutgoingEdges

public List getOutgoingEdges(Object node)
Description copied from interface: Graph
Returns a list of outgoing edges leaving this node.

Specified by:
getOutgoingEdges in interface Graph

outgoingEdgeCount

public int outgoingEdgeCount(Object node)
Description copied from interface: Graph
Returns the number of outgoing edges this node has. A convenient shortcut for getOutgoingEdges(node).size().

Specified by:
outgoingEdgeCount in interface Graph
See Also:
Graph.getOutgoingEdges(Object)

incomingEdgeCount

public int incomingEdgeCount(Object node)
Specified by:
incomingEdgeCount in interface Graph
See Also:
Graph.outgoingEdgeCount(Object)

getIncomingEdges

public List getIncomingEdges(Object node)
Specified by:
getIncomingEdges in interface Graph
See Also:
Graph.getOutgoingEdges(Object)

toString

public String toString()
Returns a printable representation of the graph that has the following form.
 digraph foo {
     Boston -> New_York [label="214 miles"];
     Boston -> Chicago [label="983 miles"];
     New_York -> Chicago [label="787 miles"];
     Boston -> Westford [label="35 miles"];
     Raleigh -> Westford [label="722 miles"];
 }
 

Note that to get a neat printable representation, each node and edge label must have a short printable representation.



Copyright (c) 2004 Red Hat, Inc. Corporation. All Rights Reserved. Generated at July 20 2004:2337 UTC