net.walend.digraph.path
Class MutableListCEPath

java.lang.Object
  |
  +--net.walend.digraph.path.AbstractListCEPath
        |
        +--net.walend.digraph.path.MutableListCEPath
All Implemented Interfaces:
CEDigraph, CEPath, Digraph, HasState, MutableCEPath, Path, java.io.Serializable

public class MutableListCEPath
extends AbstractListCEPath
implements MutableCEPath, java.io.Serializable

This class implements the MutableCEPath interface using two lists.

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

Nested Class Summary
 
Nested classes inherited from class net.walend.digraph.path.AbstractListCEPath
AbstractListCEPath.ListEdgeIterator
 
Field Summary
 
Fields inherited from class net.walend.digraph.path.AbstractListCEPath
 
Fields inherited from interface net.walend.digraph.CEDigraph
EMPTY
 
Constructor Summary
MutableListCEPath(CEDigraph digraph, java.util.List nodeList, java.util.List edgeList)
          Creates a new path on digraph that has only node in it, using nodeListn and edgeList.
MutableListCEPath(CEDigraph digraph, java.lang.Object node)
          Creates a new path on digraph that has only node in it with DEFAULTCAPACITY of 7.
MutableListCEPath(CEDigraph digraph, java.lang.Object node, int nodeCapacity)
          Creates a new path on digraph that has only node in it, with a capacity nodeCapacity.
MutableListCEPath(CEDigraph digraph, java.lang.Object node, java.util.List nodeList, java.util.List edgeList)
          Creates a new path on digraph that has only node in it, using nodeListn and edgeList.
MutableListCEPath(CEPath path)
          Create a new path that is a copy of path.
MutableListCEPath(CEPath path, java.util.List nodeList, java.util.List edgeList)
          Create a new path that is a copy of path, using nodeList and edgeList.
 
Method Summary
 void addToHead(java.lang.Object node, java.lang.Object edge)
          Adds a node and edge to the beginning of the path.
 void addToTail(java.lang.Object edge, java.lang.Object node)
          Adds an edge and node to the end of the path.
 void graftToHead(CEPath path)
          Adds a path to the beginning of this path.
 void graftToTail(CEPath path)
          Adds a path to the end of this path.
 CEPath pruneHead(int index)
          Removes from the head to the edge at index.
 CEPath pruneHeadFromFirst(java.lang.Object node)
          Removes from the head to the first occurance of node.
 CEPath pruneHeadFromLast(java.lang.Object node)
          Removes from the head to the last occurance of node.
 CEPath pruneTail(int index)
          Removes from the edge at index to the tail.
 CEPath pruneTailFromFirst(java.lang.Object node)
          Removes from the first occurance of node to the tail.
 CEPath pruneTailFromLast(java.lang.Object node)
          Removes from the last occurance of node to the tail.
 java.lang.Object removeHead()
          Removes the head node from the path.
 java.lang.Object removeTail()
          Removes the tail node from the path.
 CEPath splice(CEPath path, int startNodeIndex, int endNodeIndex)
          Splices in path between the startNodeIndex and endNodeIndex.
 CEPath spliceFirst(CEPath path)
          Splices in path between the first occurence of path's head and the first occurence of path's tail.
 CEPath spliceFirstToLast(CEPath path)
          Splices in path between the first occurence of path's head and the last occurence of path's tail.
 CEPath spliceLast(CEPath path)
          Splices in path between the last occurence of path's head and the last occurence of path's tail.
 CEPath spliceLastToFirst(CEPath path)
          Splices in path between the last occurence of path's head and the first occurence of path's tail.
 
Methods inherited from class net.walend.digraph.path.AbstractListCEPath
checkValid, chopList, containsCEDigraph, containsEdge, containsEdge, containsNode, containsNodes, countInboundEdges, countOutboundEdges, edgeCount, edgeIterator, edgeNodeIterator, getEdge, getEdgeAtIndex, getEdgeList, getEdges, getFromNodes, getHead, getInboundEdges, getIndexOfEdge, getIndexOfNode, getLastIndexOfEdge, getLastIndexOfNode, getNodeAtIndex, getNodeList, getNodes, getOutboundEdges, getPrincipleInterface, getSubpath, getSubpathFirst, getSubpathFirstToLast, getSubpathLast, getSubpathLastToFirst, getSupergraph, getTail, getToNodes, intersectWithCEDigraph, isEdgeFree, isEmpty, nodeCount, nodeIterator, pathEdgeCount, pathEdgeIterator, pathEdgeNodeIterator, pathNodeCount, pathNodeIterator, sameCEDigraphAs, sameCEPathAs, sameStateAs, toString, unionCEDigraph, valid
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.walend.digraph.path.CEPath
getEdgeAtIndex, getEdgeList, getIndexOfEdge, getLastIndexOfEdge, getSubpath, getSubpathFirst, getSubpathFirstToLast, getSubpathLast, getSubpathLastToFirst, getSupergraph, pathEdgeIterator, sameCEPathAs
 
Methods inherited from interface net.walend.digraph.CEDigraph
containsCEDigraph, containsEdge, edgeIterator, getEdge, getEdges, getInboundEdges, getOutboundEdges, intersectWithCEDigraph, sameCEDigraphAs, unionCEDigraph
 
Methods inherited from interface net.walend.digraph.Digraph
containsEdge, containsNode, containsNodes, countInboundEdges, countOutboundEdges, edgeCount, edgeNodeIterator, getFromNodes, getNodes, getToNodes, isEdgeFree, isEmpty, nodeCount, nodeIterator
 
Methods inherited from interface net.walend.collection.HasState
getPrincipleInterface, sameStateAs
 
Methods inherited from interface net.walend.digraph.path.Path
getHead, getIndexOfNode, getLastIndexOfNode, getNodeAtIndex, getNodeList, getTail, pathEdgeCount, pathEdgeNodeIterator, pathNodeCount, pathNodeIterator, valid
 

Constructor Detail

MutableListCEPath

public MutableListCEPath(CEPath path)
                  throws InvalidPathException
Create a new path that is a copy of path.

Throws:
InvalidPathException - if the path is not valid.

MutableListCEPath

public MutableListCEPath(CEPath path,
                         java.util.List nodeList,
                         java.util.List edgeList)
Create a new path that is a copy of path, using nodeList and edgeList. This constructor clear()s both lists before using them.

Throws:
InvalidPathException - if the path is not valid.

MutableListCEPath

public MutableListCEPath(CEDigraph digraph,
                         java.lang.Object node)
Creates a new path on digraph that has only node in it with DEFAULTCAPACITY of 7.

Throws:
InvalidPathException - if the path is not valid (because the node isn't in the supergraph).

MutableListCEPath

public MutableListCEPath(CEDigraph digraph,
                         java.lang.Object node,
                         int nodeCapacity)
Creates a new path on digraph that has only node in it, with a capacity nodeCapacity.

Throws:
InvalidPathException - if the path is not valid (because the node isn't in the supergraph).

MutableListCEPath

public MutableListCEPath(CEDigraph digraph,
                         java.lang.Object node,
                         java.util.List nodeList,
                         java.util.List edgeList)
Creates a new path on digraph that has only node in it, using nodeListn and edgeList. This constructor clear()s both lists before using them.

Throws:
InvalidPathException - if the path is not valid (because the node isn't in the supergraph).

MutableListCEPath

public MutableListCEPath(CEDigraph digraph,
                         java.util.List nodeList,
                         java.util.List edgeList)
Creates a new path on digraph that has only node in it, using nodeListn and edgeList. This constructor uses nodeList as the list of nodes, and edgeList as the list of edges.

Throws:
InvalidPathException - if the path is not valid (because the node isn't in the supergraph).
Method Detail

addToTail

public void addToTail(java.lang.Object edge,
                      java.lang.Object node)
               throws EdgeMissingException,
                      NodeMissingException
Adds an edge and node to the end of the path.

returns true if the operation is successful, false if the path is unchanged.

Specified by:
addToTail in interface MutableCEPath
Overrides:
addToTail in class AbstractListCEPath
Throws:
EdgeMissingException - if the edge is not in the digraph between the tail node and node.
NodeMissingException - if the node is not in the digraph.

addToHead

public void addToHead(java.lang.Object node,
                      java.lang.Object edge)
               throws EdgeMissingException,
                      NodeMissingException
Adds a node and edge to the beginning of the path.

returns true if the operation is successful, false if the path is unchanged.

Specified by:
addToHead in interface MutableCEPath
Overrides:
addToHead in class AbstractListCEPath
Throws:
EdgeMissingException - if the edge is not in the digraph between the tail node and node.
NodeMissingException - if the node is not in the digraph.

removeHead

public java.lang.Object removeHead()
                            throws LastNodeException
Removes the head node from the path.

returns the orphaned edge.

Specified by:
removeHead in interface MutableCEPath
Overrides:
removeHead in class AbstractListCEPath
LastNodeException

removeTail

public java.lang.Object removeTail()
                            throws LastNodeException
Removes the tail node from the path.

returns the orphaned edge.

Specified by:
removeTail in interface MutableCEPath
Overrides:
removeTail in class AbstractListCEPath
LastNodeException

graftToTail

public void graftToTail(CEPath path)
                 throws EdgeMissingException,
                        NodeMissingException,
                        InvalidSpliceException
Adds a path to the end of this path.

Specified by:
graftToTail in interface MutableCEPath
Overrides:
graftToTail in class AbstractListCEPath
Throws:
EdgeMissingException - if the any edge in path is missing from the digraph.
NodeMissingException - if any node in path not in the digraph.
InvalidSpliceException - if path's head node is not this' tail node.

graftToHead

public void graftToHead(CEPath path)
                 throws EdgeMissingException,
                        NodeMissingException,
                        InvalidSpliceException
Adds a path to the beginning of this path.

Specified by:
graftToHead in interface MutableCEPath
Overrides:
graftToHead in class AbstractListCEPath
Throws:
EdgeMissingException - if the any edge in path is missing from the digraph.
NodeMissingException - if any node in path not in the digraph.
InvalidSpliceException - if path's tail node is not this' head node.

pruneTail

public CEPath pruneTail(int index)
Removes from the edge at index to the tail.

Specified by:
pruneTail in interface MutableCEPath
Overrides:
pruneTail in class AbstractListCEPath
Returns:
the path from the node at index to the tail.

pruneHead

public CEPath pruneHead(int index)
Removes from the head to the edge at index.

Specified by:
pruneHead in interface MutableCEPath
Overrides:
pruneHead in class AbstractListCEPath
Returns:
the path from the head to the node at index.

pruneTailFromFirst

public CEPath pruneTailFromFirst(java.lang.Object node)
                          throws NodeMissingException
Removes from the first occurance of node to the tail.

Specified by:
pruneTailFromFirst in interface MutableCEPath
Overrides:
pruneTailFromFirst in class AbstractListCEPath
Returns:
a path from the first occurance of node to the tail.
Throws:
NodeMissingException - if the node is not in the digraph.

pruneTailFromLast

public CEPath pruneTailFromLast(java.lang.Object node)
                         throws NodeMissingException
Removes from the last occurance of node to the tail.

Specified by:
pruneTailFromLast in interface MutableCEPath
Overrides:
pruneTailFromLast in class AbstractListCEPath
Returns:
a path from the last occurance of node to the tail.
Throws:
NodeMissingException - if the node is not in the digraph.

pruneHeadFromFirst

public CEPath pruneHeadFromFirst(java.lang.Object node)
                          throws NodeMissingException
Removes from the head to the first occurance of node.

Specified by:
pruneHeadFromFirst in interface MutableCEPath
Overrides:
pruneHeadFromFirst in class AbstractListCEPath
Returns:
a path from the head to the first occurance of node.
Throws:
NodeMissingException - if the node is not in the digraph.

pruneHeadFromLast

public CEPath pruneHeadFromLast(java.lang.Object node)
                         throws NodeMissingException
Removes from the head to the last occurance of node.

Specified by:
pruneHeadFromLast in interface MutableCEPath
Overrides:
pruneHeadFromLast in class AbstractListCEPath
Returns:
a path from the head to the last occurance of node.
Throws:
NodeMissingException - if the node is not in the digraph.

splice

public CEPath splice(CEPath path,
                     int startNodeIndex,
                     int endNodeIndex)
              throws EdgeMissingException,
                     NodeMissingException,
                     InvalidSpliceException
Splices in path between the startNodeIndex and endNodeIndex.

Specified by:
splice in interface MutableCEPath
Overrides:
splice in class AbstractListCEPath
Returns:
the orphaned path

Throws:
EdgeMissingException - if the any edge in path is missing from the digraph.
NodeMissingException - if any node in path not in the digraph.
InvalidSpliceException - if path's head node is not the node in this at startNodeIndex, or if the path's tail node is not the node in this at endNodeIndex.

spliceFirst

public CEPath spliceFirst(CEPath path)
                   throws EdgeMissingException,
                          NodeMissingException,
                          InvalidSpliceException
Splices in path between the first occurence of path's head and the first occurence of path's tail.

Specified by:
spliceFirst in interface MutableCEPath
Overrides:
spliceFirst in class AbstractListCEPath
Returns:
the orphaned path

Throws:
EdgeMissingException - if the any edge in path is missing from the digraph.
NodeMissingException - if any node in path not in the digraph.
InvalidSpliceException - if path's head node is not the node in this at startNodeIndex, or if the path's tail node is not the node in this at endNodeIndex.

spliceLast

public CEPath spliceLast(CEPath path)
                  throws EdgeMissingException,
                         NodeMissingException,
                         InvalidSpliceException
Splices in path between the last occurence of path's head and the last occurence of path's tail.

Specified by:
spliceLast in interface MutableCEPath
Overrides:
spliceLast in class AbstractListCEPath
Returns:
the orphaned path

Throws:
EdgeMissingException - if the any edge in path is missing from the digraph.
NodeMissingException - if any node in path not in the digraph.
InvalidSpliceException - if path's head node is not the node in this at startNodeIndex, or if the path's tail node is not the node in this at endNodeIndex.

spliceFirstToLast

public CEPath spliceFirstToLast(CEPath path)
                         throws EdgeMissingException,
                                NodeMissingException,
                                InvalidSpliceException
Splices in path between the first occurence of path's head and the last occurence of path's tail.

Specified by:
spliceFirstToLast in interface MutableCEPath
Overrides:
spliceFirstToLast in class AbstractListCEPath
Returns:
the orphaned path

Throws:
EdgeMissingException - if the any edge in path is missing from the digraph.
NodeMissingException - if any node in path not in the digraph.
InvalidSpliceException - if path's head node is not the node in this at startNodeIndex, or if the path's tail node is not the node in this at endNodeIndex.

spliceLastToFirst

public CEPath spliceLastToFirst(CEPath path)
                         throws EdgeMissingException,
                                NodeMissingException,
                                InvalidSpliceException
Splices in path between the last occurence of path's head and the first occurence of path's tail.

Specified by:
spliceLastToFirst in interface MutableCEPath
Overrides:
spliceLastToFirst in class AbstractListCEPath
Returns:
the orphaned path

Throws:
EdgeMissingException - if the any edge in path is missing from the digraph.
NodeMissingException - if any node in path not in the digraph.
InvalidSpliceException - if path's head node is not the node in this at startNodeIndex, or if the path's tail node is not the node in this at endNodeIndex.


Copyright (c) 2001, 2002, David Walend