net.walend.digraph.path
Class MutableListUEPath

java.lang.Object
  |
  +--net.walend.digraph.path.AbstractListUEPath
        |
        +--net.walend.digraph.path.MutableListUEPath
All Implemented Interfaces:
Digraph, HasState, MutableUEPath, Path, java.io.Serializable, UEDigraph, UEPath

public class MutableListUEPath
extends AbstractListUEPath
implements MutableUEPath, java.io.Serializable

This class implements the MutableUEPath interface using two lists.

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

Nested Class Summary
 
Nested classes inherited from class net.walend.digraph.path.AbstractListUEPath
AbstractListUEPath.ListEdgeIterator
 
Field Summary
 
Fields inherited from class net.walend.digraph.path.AbstractListUEPath
 
Fields inherited from interface net.walend.digraph.UEDigraph
EMPTY
 
Constructor Summary
MutableListUEPath(UEDigraph 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.
MutableListUEPath(UEDigraph digraph, java.lang.Object node)
          Creates a new path on digraph that has only node in it with DEFAULTCAPACITY of 7.
MutableListUEPath(UEDigraph digraph, java.lang.Object node, int nodeCapacity)
          Creates a new path on digraph that has only node in it, with a capacity nodeCapacity.
MutableListUEPath(UEDigraph 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.
MutableListUEPath(UEPath path)
          Create a new path that is a copy of path.
MutableListUEPath(UEPath 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(UEPath path)
          Adds a path to the beginning of this path.
 void graftToTail(UEPath path)
          Adds a path to the end of this path.
 UEPath pruneHead(int index)
          Removes from the head to the edge at index.
 UEPath pruneHeadFromFirst(java.lang.Object node)
          Removes from the head to the first occurance of node.
 UEPath pruneHeadFromLast(java.lang.Object node)
          Removes from the head to the last occurance of node.
 UEPath pruneTail(int index)
          Removes from the edge at index to the tail.
 UEPath pruneTailFromFirst(java.lang.Object node)
          Removes from the first occurance of node to the tail.
 UEPath 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.
 UEPath splice(UEPath path, int startNodeIndex, int endNodeIndex)
          Splices in path between the startNodeIndex and endNodeIndex.
 UEPath spliceFirst(UEPath path)
          Splices in path between the first occurence of path's head and the first occurence of path's tail.
 UEPath spliceFirstToLast(UEPath path)
          Splices in path between the first occurence of path's head and the last occurence of path's tail.
 UEPath spliceLast(UEPath path)
          Splices in path between the last occurence of path's head and the last occurence of path's tail.
 UEPath spliceLastToFirst(UEPath 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.AbstractListUEPath
checkValid, chopList, containsEdge, containsEdge, containsEdge, containsEdges, containsNode, containsNodes, containsUEDigraph, countInboundEdges, countOutboundEdges, edgeCount, edgeIterator, edgeNodeIterator, getEdge, getEdgeAtIndex, getEdgeList, getEdges, getFromNode, getFromNodes, getHead, getInboundEdges, getIndexOfEdge, getIndexOfNode, getLastIndexOfEdge, getLastIndexOfNode, getNodeAtIndex, getNodeList, getNodes, getOutboundEdges, getPrincipleInterface, getSubpath, getSubpathFirst, getSubpathFirstToLast, getSubpathLast, getSubpathLastToFirst, getSupergraph, getTail, getToNode, getToNodes, intersectWithUEDigraph, isEdgeFree, isEmpty, nodeCount, nodeIterator, pathEdgeCount, pathEdgeIterator, pathEdgeNodeIterator, pathNodeCount, pathNodeIterator, sameStateAs, sameUEDigraphAs, sameUEPathAs, toString, unionUEDigraph, 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.UEPath
getEdgeAtIndex, getEdgeList, getIndexOfEdge, getLastIndexOfEdge, getSubpath, getSubpathFirst, getSubpathFirstToLast, getSubpathLast, getSubpathLastToFirst, getSupergraph, pathEdgeIterator, sameUEPathAs
 
Methods inherited from interface net.walend.digraph.UEDigraph
containsEdge, containsEdge, containsEdges, containsUEDigraph, edgeIterator, getEdge, getEdges, getFromNode, getInboundEdges, getOutboundEdges, getToNode, intersectWithUEDigraph, sameUEDigraphAs, unionUEDigraph
 
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

MutableListUEPath

public MutableListUEPath(UEPath path)
                  throws InvalidPathException
Create a new path that is a copy of path.

Throws:
InvalidPathException - if the path is not valid.

MutableListUEPath

public MutableListUEPath(UEPath 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.

MutableListUEPath

public MutableListUEPath(UEDigraph 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).

MutableListUEPath

public MutableListUEPath(UEDigraph 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).

MutableListUEPath

public MutableListUEPath(UEDigraph 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).

MutableListUEPath

public MutableListUEPath(UEDigraph 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 MutableUEPath
Overrides:
addToTail in class AbstractListUEPath
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 MutableUEPath
Overrides:
addToHead in class AbstractListUEPath
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 MutableUEPath
Overrides:
removeHead in class AbstractListUEPath
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 MutableUEPath
Overrides:
removeTail in class AbstractListUEPath
LastNodeException

graftToTail

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

Specified by:
graftToTail in interface MutableUEPath
Overrides:
graftToTail in class AbstractListUEPath
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(UEPath path)
                 throws EdgeMissingException,
                        NodeMissingException,
                        InvalidSpliceException
Adds a path to the beginning of this path.

Specified by:
graftToHead in interface MutableUEPath
Overrides:
graftToHead in class AbstractListUEPath
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 UEPath pruneTail(int index)
Removes from the edge at index to the tail.

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

pruneHead

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

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

pruneTailFromFirst

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

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

pruneTailFromLast

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

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

pruneHeadFromFirst

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

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

pruneHeadFromLast

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

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

splice

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

Specified by:
splice in interface MutableUEPath
Overrides:
splice in class AbstractListUEPath
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 UEPath spliceFirst(UEPath 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 MutableUEPath
Overrides:
spliceFirst in class AbstractListUEPath
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 UEPath spliceLast(UEPath 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 MutableUEPath
Overrides:
spliceLast in class AbstractListUEPath
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 UEPath spliceFirstToLast(UEPath 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 MutableUEPath
Overrides:
spliceFirstToLast in class AbstractListUEPath
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 UEPath spliceLastToFirst(UEPath 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 MutableUEPath
Overrides:
spliceLastToFirst in class AbstractListUEPath
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