harpoon.Analysis.GraphColoring
Class AbstractGraph

java.lang.Object
  extended by harpoon.Analysis.GraphColoring.AbstractGraph
All Implemented Interfaces:
Graph
Direct Known Subclasses:
SparseGraph

public abstract class AbstractGraph
extends Object
implements Graph

AbstractGraph is a skeletal implementation of the Graph interface, to minimize the effort required to implement this interface. To implement an unmodifiable graph, the programmer needs only to extend this class and provide implementations for the nodeSet and neighborsOf methods. To implement a modifiable graph, the programmer must additionally override this class's addNode and addEdge methods (which otherwise throws UnsupportedOperationException).

Version:
$Id: AbstractGraph.java,v 1.4 2004/02/08 01:52:03 cananian Exp $
Author:
Felix S. Klock II <pnkfelix@mit.edu>

Constructor Summary
AbstractGraph()
          Creates a AbstractGraph.
 
Method Summary
 boolean addEdge(Object m, Object n)
          Ensures that this graph contains an edge between m and n (optional operation).
 boolean addNode(Object n)
          Ensures that this graph contains node (optional operation).
 Collection edges()
          Returns a collection view of the edges contained in this graph.
 Collection edgesFor(Object n)
          Returns a collection view of the edges joining node to nodes in the graph.
 int getDegree(Object n)
          Returns the degree of node.
abstract  Collection neighborsOf(Object n)
          Returns a collection view for the neighbors of a specific node.
abstract  Set nodeSet()
          Returns a set view of the nodes in this.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractGraph

public AbstractGraph()
Creates a AbstractGraph.

Method Detail

nodeSet

public abstract Set nodeSet()
Description copied from interface: Graph
Returns a set view of the nodes in this.
effects: Returns an Set of the Objects that have been successfully added to this.

Specified by:
nodeSet in interface Graph

neighborsOf

public abstract Collection neighborsOf(Object n)
Description copied from interface: Graph
Returns a collection view for the neighbors of a specific node.
effects: Returns an Collection of Objects that have an edge between node and them.
mandates: node is not removed from this while the returned Collection is in use.

Specified by:
neighborsOf in interface Graph

addNode

public boolean addNode(Object n)
Description copied from interface: Graph
Ensures that this graph contains node (optional operation).
modifies: this
effects: If this method returns normally, node will be present in the node-set for this. Returns true if this graph changed as a result of the call, false otherwise.

Specified by:
addNode in interface Graph

addEdge

public boolean addEdge(Object m,
                       Object n)
Description copied from interface: Graph
Ensures that this graph contains an edge between m and n (optional operation).
modifies: this.
effects: If this method returns normally, an edge between m and n will be in this. Returns true if this changed as a result of the call.

Specified by:
addEdge in interface Graph

getDegree

public int getDegree(Object n)
Description copied from interface: Graph
Returns the degree of node.
effects: Returns the number of other Objects that node is joined with.

Specified by:
getDegree in interface Graph

edgesFor

public Collection edgesFor(Object n)
Description copied from interface: Graph
Returns a collection view of the edges joining node to nodes in the graph.
effects: Returns a Collection of two-element Collections (known as pairs) where each pair corresponds to an edge { node, n } in this. If the graph is modified while an iteration over the collection is in progress, the results of the iteration are undefined. Order may or may not be significant in the pairs returned.

Specified by:
edgesFor in interface Graph

edges

public Collection edges()
Description copied from interface: Graph
Returns a collection view of the edges contained in this graph.
effects: Returns a Collection of two-element Collections (known as pairs) where each pair corresponds to an edge { n1, n2 } in this. If the graph is modified while an iteration over the collection is in progress, the results of the iteration are undefined. Order may or may not be significant in the pairs returned.

Specified by:
edges in interface Graph