Plexus v0.13.1

com.phoenixst.plexus.examples
Class AbstractIntegerNodeGraph

java.lang.Object
  extended by com.phoenixst.plexus.AbstractGraph
      extended by com.phoenixst.plexus.examples.AbstractIntegerNodeGraph
All Implemented Interfaces:
Graph, Serializable
Direct Known Subclasses:
CirculantGraph, CompleteGraph, CompleteTree, EmptyGraph, LoopGraph, Path, PetersenGraph

public abstract class AbstractIntegerNodeGraph
extends AbstractGraph
implements Serializable

An unmodifiable graph where the nodes are Integers from zero to a specified number (exclusive) and the edges do not contain user-defined objects. This is mainly useful for implementing special-case graphs that do not actually need to explicitly store their structure.

This implementation is simple. Any extension must also be simple to support on-the-fly Graph.Edge creation. To fully implement an extension of this class, the programmer must provide implementations for the following methods:

In addition, it is recommended that the programmer override degree( node ) (when applicable) since its default implementation inefficiently depends upon other iterator-returning methods.

Since:
1.0
Version:
$Revision: 1.8 $
Author:
Ray A. Conner
See Also:
Serialized Form

Nested Class Summary
protected  class AbstractIntegerNodeGraph.AbstractIntegerEdgeCollection
           
protected static class AbstractIntegerNodeGraph.EdgeImpl
          Protected Graph.Edge implementation.
 
Nested classes/interfaces inherited from interface com.phoenixst.plexus.Graph
Graph.Edge
 
Constructor Summary
protected AbstractIntegerNodeGraph(int n)
          Creates a new AbstractIntegerNodeGraph.
 
Method Summary
protected  int checkNode(Object node)
          Returns the specified node as a primitive int from 0 to the number of nodes in this graph (exclusive) if the specified node is in this graph.
 boolean containsEdge(Graph.Edge edge)
          Returns true if this Graph contains the specified Graph.Edge.
 boolean containsNode(Object node)
          Returns true if this Graph contains the specified node.
protected abstract  Graph.Edge createEdge(int tailIndex, int headIndex)
          If an edge exists between the specified indices, create and return it.
protected abstract  Collection createEdgeCollection()
          Creates the (single) collection of edges for this instance.
protected abstract  Traverser createTraverser(int nodeIndex)
          Creates a traverser with no filtering; assumes that the node index is valid.
protected  Collection edges()
          Returns a Collection view of all the Graph.Edges in this Graph.
protected  int getNodeIndex(Object node)
          Returns the specified node as a primitive int from 0 to the number of nodes in this graph (exclusive) if the specified node is in this graph.
protected  int getNodeSize()
          Returns the number of nodes in this AbstractIntegerNodeGraph.
protected  Collection nodes()
          Returns a Collection view of all the nodes in this Graph.
 boolean removeEdge(Graph.Edge edge)
          Throws an UnsupportedOperationException.
 boolean removeNode(Object node)
          Throws an UnsupportedOperationException.
protected  Traverser traverser(Object node)
          Returns an unfiltered Traverser over those Graph.Edges incident to the specified node.
 
Methods inherited from class com.phoenixst.plexus.AbstractGraph
addEdge, addNode, adjacentNodes, degree, degree, edges, getAdjacentNode, getEdge, getIncidentEdge, getNode, incidentEdges, nodes, traverser
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractIntegerNodeGraph

protected AbstractIntegerNodeGraph(int n)
Creates a new AbstractIntegerNodeGraph.

Method Detail

nodes

protected final Collection nodes()
Description copied from class: AbstractGraph
Returns a Collection view of all the nodes in this Graph. This method is only called by nodes( Predicate ).

Specified by:
nodes in class AbstractGraph

edges

protected final Collection edges()
Description copied from class: AbstractGraph
Returns a Collection view of all the Graph.Edges in this Graph. This method is only called by edges( Predicate ).

Specified by:
edges in class AbstractGraph

traverser

protected final Traverser traverser(Object node)
Description copied from class: AbstractGraph
Returns an unfiltered Traverser over those Graph.Edges incident to the specified node. This method is only called by traverser( node, Predicate ).

Specified by:
traverser in class AbstractGraph

removeNode

public final boolean removeNode(Object node)
Throws an UnsupportedOperationException.

Specified by:
removeNode in interface Graph
Overrides:
removeNode in class AbstractGraph
Parameters:
node - the node to be removed from this Graph.
Returns:
true if this Graph contained node.

containsNode

public final boolean containsNode(Object node)
Returns true if this Graph contains the specified node.

Specified by:
containsNode in interface Graph
Overrides:
containsNode in class AbstractGraph
Parameters:
node - the node whose presence in this Graph is to be tested.
Returns:
true if this Graph contains the specified node.

removeEdge

public final boolean removeEdge(Graph.Edge edge)
Throws an UnsupportedOperationException.

Specified by:
removeEdge in interface Graph
Overrides:
removeEdge in class AbstractGraph
Parameters:
edge - the Graph.Edge to be removed from this Graph.
Returns:
true if this Graph contained the specified Graph.Edge.

containsEdge

public boolean containsEdge(Graph.Edge edge)
Returns true if this Graph contains the specified Graph.Edge. This implementation tests the specified edge for equality with the one returned by createEdge( tailIndex, headIndex ) with the same tail and head.

Specified by:
containsEdge in interface Graph
Overrides:
containsEdge in class AbstractGraph
Parameters:
edge - the Graph.Edge whose presence in this Graph is to be tested.
Returns:
true if this Graph contains the specified Graph.Edge.

getNodeSize

protected final int getNodeSize()
Returns the number of nodes in this AbstractIntegerNodeGraph.


getNodeIndex

protected final int getNodeIndex(Object node)
Returns the specified node as a primitive int from 0 to the number of nodes in this graph (exclusive) if the specified node is in this graph. Otherwise, returns -1.


checkNode

protected final int checkNode(Object node)
Returns the specified node as a primitive int from 0 to the number of nodes in this graph (exclusive) if the specified node is in this graph. Otherwise, throws an NoSuchNodeException.


createEdge

protected abstract Graph.Edge createEdge(int tailIndex,
                                         int headIndex)
If an edge exists between the specified indices, create and return it. If not, return null. The indices are assumed to represent valid nodes for this Graph.


createEdgeCollection

protected abstract Collection createEdgeCollection()
Creates the (single) collection of edges for this instance.


createTraverser

protected abstract Traverser createTraverser(int nodeIndex)
Creates a traverser with no filtering; assumes that the node index is valid.


Plexus v0.13.1

See the Plexus project home, hosted by SourceForge.
Copyright ? 1994-2006, by Phoenix Software Technologists, Inc. and others. All Rights Reserved. Use is subject to license terms.