com.phoenixst.plexus.examples

Class AbstractIntegerNodeGraph

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

Nested Class Summary
protected abstract classAbstractIntegerNodeGraph.AbstractIntegerEdgeCollection
protected static classAbstractIntegerNodeGraph.EdgeImpl
Protected Graph.Edge implementation.
Constructor Summary
protected AbstractIntegerNodeGraph(int n)
Creates a new AbstractIntegerNodeGraph.
Method Summary
protected intcheckNode(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.
booleancontainsEdge(Graph.Edge edge)
Returns true if this Graph contains the specified Graph.Edge.
booleancontainsNode(Object node)
Returns true if this Graph contains the specified node.
protected abstract Graph.EdgecreateEdge(int tailIndex, int headIndex)
If an edge exists between the specified indices, create and return it.
protected abstract CollectioncreateEdgeCollection()
Creates the (single) collection of edges for this instance.
protected abstract TraversercreateTraverser(int nodeIndex)
Creates a traverser with no filtering; assumes that the node index is valid.
protected Collectionedges()
protected intgetNodeIndex(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 intgetNodeSize()
Returns the number of nodes in this AbstractIntegerNodeGraph.
protected Collectionnodes()
booleanremoveEdge(Graph.Edge edge)
Throws an UnsupportedOperationException.
booleanremoveNode(Object node)
Throws an UnsupportedOperationException.
protected Traversertraverser(Object node)

Constructor Detail

AbstractIntegerNodeGraph

protected AbstractIntegerNodeGraph(int n)
Creates a new AbstractIntegerNodeGraph.

Method Detail

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.

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.

containsNode

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

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.

edges

protected final Collection edges()

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.

getNodeSize

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

nodes

protected final Collection nodes()

removeEdge

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

removeNode

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

traverser

protected final Traverser traverser(Object node)
See the Plexus project home, hosted by SourceForge.
Copyright B) 1994-2006, by Phoenix Software Technologists, Inc. and others. All Rights Reserved. Use is subject to license terms.