net.walend.digraph.path
Class AbstractDelegateDigraphOfGEPaths

java.lang.Object
  |
  +--net.walend.digraph.path.AbstractDelegateDigraphOfGEPaths
All Implemented Interfaces:
CEDigraph, Digraph, DigraphOfGEPaths, HasState, IndexedCEDigraph, IndexedDigraph, java.io.Serializable
Direct Known Subclasses:
AbstractShortestGEPaths

public abstract class AbstractDelegateDigraphOfGEPaths
extends java.lang.Object
implements DigraphOfGEPaths, java.io.Serializable

This class implements the DigraphOfGEPaths by delegating to an underlying IndexedMutableCEDigraph. Use it for the results of algorithms like the Floyd-Warshall algorithm that rely on quick manipulation of data in the matrix.

Author:
David Walend dfw1@cornell.edu
See Also:
Serialized Form

Nested Class Summary
protected  class AbstractDelegateDigraphOfGEPaths.ADDOCEPIndexedEdgeIterator
           
protected static class AbstractDelegateDigraphOfGEPaths.DigraphGEPath
           
protected static class AbstractDelegateDigraphOfGEPaths.Edge
           
 
Field Summary
private  IndexedGEDigraph base
           
private  IndexedMutableCEDigraph delegate
           
 
Fields inherited from interface net.walend.digraph.CEDigraph
EMPTY
 
Constructor Summary
AbstractDelegateDigraphOfGEPaths(IndexedGEDigraph ceDigraph)
           
AbstractDelegateDigraphOfGEPaths(IndexedGEDigraph ceDigraph, IndexedMutableCEDigraph delegate)
           
 
Method Summary
protected  AbstractDelegateDigraphOfGEPaths.Edge addEdge(java.lang.Object fromNode, java.lang.Object toNode, AbstractDelegateDigraphOfGEPaths.Edge edge)
          If no existing edge is displaced by edge.
protected  void clearEdges()
          Remove all the edges from the CEDigraph.
 boolean containsCEDigraph(CEDigraph digraph)
          Returns true if digraph is a subgraph of this CEDigraph.
 boolean containsEdge(int fromIndex, int toIndex)
           
 boolean containsEdge(int fromIndex, int toIndex, java.lang.Object edge)
           
 boolean containsEdge(java.lang.Object fromNode, java.lang.Object toNode)
          Returns true if the digraph contains any edge from fromNode to toNode
 boolean containsEdge(java.lang.Object fromNode, java.lang.Object toNode, java.lang.Object edge)
          Returns true if edge links fromNode to toNode
 boolean containsNode(int index)
           
 boolean containsNode(java.lang.Object node)
           
 boolean containsNodes(java.util.Set nodes)
           
 int countInboundEdges(int index)
           
 int countInboundEdges(java.lang.Object node)
           
 int countOutboundEdges(int index)
           
 int countOutboundEdges(java.lang.Object node)
           
 int edgeCount()
           
 EdgeIterator edgeIterator()
           
 EdgeNodeIterator edgeNodeIterator()
          Returns an iterator that iterates across pairs of nodes that make edges.
 IndexedGEDigraph getBase()
           
protected  IndexedMutableCEDigraph getDelegate()
           
 java.lang.Object getEdge(int fromIndex, int toIndex)
           
 java.lang.Object getEdge(java.lang.Object fromNode, java.lang.Object toNode)
          Returns null if no edge links fromNode to toNode
 Bag getEdges()
           
 int[] getFromIndices(int index)
           
 java.util.Set getFromNodes(int index)
           
 java.util.Set getFromNodes(java.lang.Object node)
          Returns the set of nodes that can reach this node by crossing one edge.
 Bag getInboundEdges(int index)
           
 Bag getInboundEdges(java.lang.Object node)
          Returns the empty set if node has no inbound edges.
 java.lang.Object getNode(int index)
           
 int getNodeIndex(java.lang.Object node)
           
 java.util.Set getNodes()
           
 Bag getOutboundEdges(int index)
           
 Bag getOutboundEdges(java.lang.Object node)
          Returns the empty set if node has no outbound edges.
 GEPath getPath(int fromIndex, int toIndex)
           
 GEPath getPath(java.lang.Object fromNode, java.lang.Object toNode)
           
 java.lang.Class getPrincipleInterface()
          Returns the class's principle interface for state comparisons.
 int[] getToIndices(int index)
           
 java.util.Set getToNodes(int index)
           
 java.util.Set getToNodes(java.lang.Object node)
          Returns the set of nodes that can be reached from this node by crossing one edge.
 IndexedEdgeIterator indexedEdgeIterator()
           
 IndexedEdgeNodeIterator indexedEdgeNodeIterator()
           
 IndexedIterator indexedNodeIterator()
           
protected  void initWithNodesFrom(IndexedGEDigraph digraph)
          Initialize this with the nodes from digraph at the same index values as in digraph.
 CEDigraph intersectWithCEDigraph(CEDigraph digraph)
          Returns a new digraph that is the intersection of this with digraph.
 boolean isEdgeFree()
          Returns true if this Digraph has no edges.
 boolean isEmpty()
           
 int nodeCapacity()
          Returns the maximum capacity for nodes in this IndexedDigraph.
 int nodeCount()
           
 int[] nodeIndices()
          Returns an array if ints that show which node indices are being used.
 java.util.Iterator nodeIterator()
          Implementations should explicitly state how they interpret nodeIterator()'s remove method.
 boolean sameCEDigraphAs(CEDigraph digraph)
          Returns true if digraph is the same as this that is, if this.containsCEDigraph(digraph) and digraph.containsCEDigraph(this).
 boolean sameStateAs(HasState victim)
          If two HasStates have the same internal state, return true.
 CEDigraph unionCEDigraph(CEDigraph digraph)
          Returns a new digraph that is the union of this with digraph.
 boolean valid()
          Checks to make sure all the nodes and edges in the path still exist in the base digraph.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

base

private IndexedGEDigraph base

delegate

private IndexedMutableCEDigraph delegate
Constructor Detail

AbstractDelegateDigraphOfGEPaths

public AbstractDelegateDigraphOfGEPaths(IndexedGEDigraph ceDigraph)

AbstractDelegateDigraphOfGEPaths

public AbstractDelegateDigraphOfGEPaths(IndexedGEDigraph ceDigraph,
                                        IndexedMutableCEDigraph delegate)
Method Detail

initWithNodesFrom

protected void initWithNodesFrom(IndexedGEDigraph digraph)
Initialize this with the nodes from digraph at the same index values as in digraph.


getDelegate

protected IndexedMutableCEDigraph getDelegate()

getPath

public GEPath getPath(java.lang.Object fromNode,
                      java.lang.Object toNode)
               throws NodeMissingException
Specified by:
getPath in interface DigraphOfGEPaths
NodeMissingException

getPath

public GEPath getPath(int fromIndex,
                      int toIndex)
Specified by:
getPath in interface DigraphOfGEPaths

valid

public boolean valid()
Description copied from interface: DigraphOfGEPaths
Checks to make sure all the nodes and edges in the path still exist in the base digraph.

Specified by:
valid in interface DigraphOfGEPaths

getBase

public IndexedGEDigraph getBase()
Specified by:
getBase in interface DigraphOfGEPaths

addEdge

protected AbstractDelegateDigraphOfGEPaths.Edge addEdge(java.lang.Object fromNode,
                                                        java.lang.Object toNode,
                                                        AbstractDelegateDigraphOfGEPaths.Edge edge)
                                                 throws NodeMissingException,
                                                        EdgeNotUniqueException
If no existing edge is displaced by edge. Otherwise, return the path that is displaced.

Throws:
NodeMissingException - if either node is not in the digraph.
EdgeNotUniqueException - if the edge is already in the digraph.

clearEdges

protected void clearEdges()
Remove all the edges from the CEDigraph.


nodeCapacity

public int nodeCapacity()
Returns the maximum capacity for nodes in this IndexedDigraph.

Specified by:
nodeCapacity in interface IndexedDigraph

nodeIndices

public int[] nodeIndices()
Returns an array if ints that show which node indices are being used.

Specified by:
nodeIndices in interface IndexedDigraph

containsNode

public boolean containsNode(int index)
Specified by:
containsNode in interface IndexedDigraph
Throws:
java.lang.ArrayIndexOutOfBoundsException - if index does not have a node. Use nodeIndices() or getNodeIndex() to avoid these. In your code, catch ArrayIndexOutOfBoundsException and throw a ConcurrentModificationException if you think that's the problem.

getNode

public java.lang.Object getNode(int index)
Specified by:
getNode in interface IndexedDigraph
Throws:
java.lang.ArrayIndexOutOfBoundsException - if index does not have a node. Use nodeIndices() or getNodeIndex() to avoid these. In your code, catch ArrayIndexOutOfBoundsException and throw a ConcurrentModificationException if you think that's the problem.

getNodeIndex

public int getNodeIndex(java.lang.Object node)
                 throws NodeMissingException
Specified by:
getNodeIndex in interface IndexedDigraph
Throws:
a - NodeMissingException if the node is not in the digraph.
NodeMissingException

containsEdge

public boolean containsEdge(int fromIndex,
                            int toIndex)
Specified by:
containsEdge in interface IndexedDigraph
Throws:
java.lang.ArrayIndexOutOfBoundsException - if index does not have a node. Use nodeIndices() or getNodeIndex() to avoid these. In your code, catch ArrayIndexOutOfBoundsException and throw a ConcurrentModificationException if you think that's the problem.

countInboundEdges

public int countInboundEdges(int index)
Specified by:
countInboundEdges in interface IndexedDigraph
Throws:
java.lang.ArrayIndexOutOfBoundsException - if index does not have a node. Use nodeIndices() or getNodeIndex() to avoid these. In your code, catch ArrayIndexOutOfBoundsException and throw a ConcurrentModificationException if you think that's the problem.

countOutboundEdges

public int countOutboundEdges(int index)
Specified by:
countOutboundEdges in interface IndexedDigraph
Throws:
java.lang.ArrayIndexOutOfBoundsException - if index does not have a node. Use nodeIndices() or getNodeIndex() to avoid these. In your code, catch ArrayIndexOutOfBoundsException and throw a ConcurrentModificationException if you think that's the problem.

getFromNodes

public java.util.Set getFromNodes(int index)
Specified by:
getFromNodes in interface IndexedDigraph
Throws:
java.lang.ArrayIndexOutOfBoundsException - if index does not have a node. Use nodeIndices() or getNodeIndex() to avoid these. In your code, catch ArrayIndexOutOfBoundsException and throw a ConcurrentModificationException if you think that's the problem.

getFromIndices

public int[] getFromIndices(int index)
Specified by:
getFromIndices in interface IndexedDigraph

getToNodes

public java.util.Set getToNodes(int index)
Specified by:
getToNodes in interface IndexedDigraph
Throws:
java.lang.ArrayIndexOutOfBoundsException - if index does not have a node. Use nodeIndices() or getNodeIndex() to avoid these. In your code, catch ArrayIndexOutOfBoundsException and throw a ConcurrentModificationException if you think that's the problem.

getToIndices

public int[] getToIndices(int index)
Specified by:
getToIndices in interface IndexedDigraph

indexedEdgeNodeIterator

public IndexedEdgeNodeIterator indexedEdgeNodeIterator()
Specified by:
indexedEdgeNodeIterator in interface IndexedDigraph

indexedNodeIterator

public IndexedIterator indexedNodeIterator()
Specified by:
indexedNodeIterator in interface IndexedDigraph

containsEdge

public boolean containsEdge(int fromIndex,
                            int toIndex,
                            java.lang.Object edge)
Specified by:
containsEdge in interface IndexedCEDigraph
Throws:
java.lang.ArrayIndexOutOfBoundsException - if index does not have a node. Use nodeIndices() or getNodeIndex() to avoid these. In your code, catch ArrayIndexOutOfBoundsException and throw a ConcurrentModificationException if you think that's the problem.

getInboundEdges

public Bag getInboundEdges(int index)
Specified by:
getInboundEdges in interface IndexedCEDigraph
Throws:
java.lang.ArrayIndexOutOfBoundsException - if index does not have a node. Use nodeIndices() or getNodeIndex() to avoid these. In your code, catch ArrayIndexOutOfBoundsException and throw a ConcurrentModificationException if you think that's the problem.

getOutboundEdges

public Bag getOutboundEdges(int index)
Specified by:
getOutboundEdges in interface IndexedCEDigraph
Throws:
java.lang.ArrayIndexOutOfBoundsException - if index does not have a node. Use nodeIndices() or getNodeIndex() to avoid these. In your code, catch ArrayIndexOutOfBoundsException and throw a ConcurrentModificationException if you think that's the problem.

getEdge

public java.lang.Object getEdge(int fromIndex,
                                int toIndex)
Specified by:
getEdge in interface IndexedCEDigraph
Throws:
java.lang.ArrayIndexOutOfBoundsException - if index does not have a node. Use nodeIndices() or getNodeIndex() to avoid these. In your code, catch ArrayIndexOutOfBoundsException and throw a ConcurrentModificationException if you think that's the problem.

indexedEdgeIterator

public IndexedEdgeIterator indexedEdgeIterator()
Specified by:
indexedEdgeIterator in interface IndexedCEDigraph

containsEdge

public boolean containsEdge(java.lang.Object fromNode,
                            java.lang.Object toNode,
                            java.lang.Object edge)
                     throws NodeMissingException
Returns true if edge links fromNode to toNode

Specified by:
containsEdge in interface CEDigraph
Throws:
NodeMissingException - if either node is missing from the digraph.

getInboundEdges

public Bag getInboundEdges(java.lang.Object node)
                    throws NodeMissingException
Returns the empty set if node has no inbound edges.

Specified by:
getInboundEdges in interface CEDigraph
Throws:
NodeMissingException - if node is not in the digraph.

getOutboundEdges

public Bag getOutboundEdges(java.lang.Object node)
                     throws NodeMissingException
Returns the empty set if node has no outbound edges.

Specified by:
getOutboundEdges in interface CEDigraph
Throws:
NodeMissingException - if node is not in the digraph.

getEdge

public java.lang.Object getEdge(java.lang.Object fromNode,
                                java.lang.Object toNode)
                         throws NodeMissingException
Returns null if no edge links fromNode to toNode

Specified by:
getEdge in interface CEDigraph
Throws:
NodeMissingException - if either node is missing from the digraph.

edgeIterator

public EdgeIterator edgeIterator()
Specified by:
edgeIterator in interface CEDigraph

getEdges

public Bag getEdges()
Specified by:
getEdges in interface CEDigraph

containsCEDigraph

public boolean containsCEDigraph(CEDigraph digraph)
Returns true if digraph is a subgraph of this CEDigraph.

Specified by:
containsCEDigraph in interface CEDigraph

sameCEDigraphAs

public boolean sameCEDigraphAs(CEDigraph digraph)
Returns true if digraph is the same as this that is, if this.containsCEDigraph(digraph) and digraph.containsCEDigraph(this).

Specified by:
sameCEDigraphAs in interface CEDigraph

intersectWithCEDigraph

public CEDigraph intersectWithCEDigraph(CEDigraph digraph)
Returns a new digraph that is the intersection of this with digraph. Implementations should generally return the same implementation of CEDigraph as they have themselves.

Specified by:
intersectWithCEDigraph in interface CEDigraph

unionCEDigraph

public CEDigraph unionCEDigraph(CEDigraph digraph)
Returns a new digraph that is the union of this with digraph. Implementations should generally return the same implementation of CEDigraph as they are themselves. If the digraphs contain conflicting edges, then (unless you have a better rule) let digraph's edge win out.

Specified by:
unionCEDigraph in interface CEDigraph

nodeCount

public int nodeCount()
Specified by:
nodeCount in interface Digraph

edgeCount

public int edgeCount()
Specified by:
edgeCount in interface Digraph

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Digraph

containsNode

public boolean containsNode(java.lang.Object node)
Specified by:
containsNode in interface Digraph

containsEdge

public boolean containsEdge(java.lang.Object fromNode,
                            java.lang.Object toNode)
                     throws NodeMissingException
Returns true if the digraph contains any edge from fromNode to toNode

Specified by:
containsEdge in interface Digraph
Throws:
NodeMissingException - if either node is missing from the digraph.

countInboundEdges

public int countInboundEdges(java.lang.Object node)
                      throws NodeMissingException
Specified by:
countInboundEdges in interface Digraph
Throws:
NodeMissingException - if node is not in the digraph.

countOutboundEdges

public int countOutboundEdges(java.lang.Object node)
                       throws NodeMissingException
Specified by:
countOutboundEdges in interface Digraph
Throws:
NodeMissingException - if node is not in the digraph.

getFromNodes

public java.util.Set getFromNodes(java.lang.Object node)
                           throws NodeMissingException
Returns the set of nodes that can reach this node by crossing one edge.

Specified by:
getFromNodes in interface Digraph
Throws:
NodeMissingException - if node is not in the digraph.

getToNodes

public java.util.Set getToNodes(java.lang.Object node)
                         throws NodeMissingException
Returns the set of nodes that can be reached from this node by crossing one edge.

Specified by:
getToNodes in interface Digraph
Throws:
NodeMissingException - if node is not in the digraph.

nodeIterator

public java.util.Iterator nodeIterator()
Description copied from interface: Digraph
Implementations should explicitly state how they interpret nodeIterator()'s remove method. It should either throw an UnsupportedOperationException or cause a hidden side effects of removing edges.

Specified by:
nodeIterator in interface Digraph

edgeNodeIterator

public EdgeNodeIterator edgeNodeIterator()
Returns an iterator that iterates across pairs of nodes that make edges.

Specified by:
edgeNodeIterator in interface Digraph

getNodes

public java.util.Set getNodes()
Specified by:
getNodes in interface Digraph

isEdgeFree

public boolean isEdgeFree()
Returns true if this Digraph has no edges.

Specified by:
isEdgeFree in interface Digraph

containsNodes

public boolean containsNodes(java.util.Set nodes)
Specified by:
containsNodes in interface Digraph

getPrincipleInterface

public java.lang.Class getPrincipleInterface()
Description copied from interface: HasState
Returns the class's principle interface for state comparisons. If two objects have different principle interfaces, they never have the same state.

Specified by:
getPrincipleInterface in interface HasState

sameStateAs

public boolean sameStateAs(HasState victim)
Description copied from interface: HasState
If two HasStates have the same internal state, return true.

For objects with subobjects, Generally this method should only return true if the internal objects are equal. Implement a contentsHaveSameState() method to determine if the contents have the same state.

Specified by:
sameStateAs in interface HasState


Copyright (c) 2001, 2002, David Walend