net.walend.digraph.path
Class MutableListGEPath

java.lang.Object
  |
  +--net.walend.digraph.path.AbstractListGEPath
        |
        +--net.walend.digraph.path.MutableListGEPath
All Implemented Interfaces:
Digraph, GEDigraph, GEPath, HasState, MutableGEPath, Path, java.io.Serializable

public class MutableListGEPath
extends AbstractListGEPath
implements MutableGEPath, java.io.Serializable

This class implements the MutableGEPath interface using a list.

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

Nested Class Summary
 
Nested classes inherited from class net.walend.digraph.path.AbstractListGEPath
AbstractListGEPath.ListEdgeNodeIterator
 
Field Summary
 
Fields inherited from class net.walend.digraph.path.AbstractListGEPath
 
Fields inherited from interface net.walend.digraph.GEDigraph
EMPTY
 
Constructor Summary
MutableListGEPath(GEDigraph digraph, java.util.List nodeList)
          Creates a new path on digraph that has only nodeList nodes in it, using nodeList.
MutableListGEPath(GEDigraph digraph, java.lang.Object node)
          Creates a new path on digraph that has only node in it with DEFAULTCAPACITY of 7.
MutableListGEPath(GEDigraph digraph, java.lang.Object node, int nodeCapacity)
          Creates a new path on digraph that has only node in it, with a capacity nodeCapacity.
MutableListGEPath(GEDigraph digraph, java.lang.Object node, java.util.List nodeList)
          Creates a new path on digraph that has only node in it, using nodeList.
MutableListGEPath(GEPath path)
          Create a new path that is a copy of path.
MutableListGEPath(GEPath path, java.util.List nodeList)
          Create a new path that is a copy of path, using nodeList as the nodes in the path.
 
Method Summary
 void addToHead(java.lang.Object node)
          Adds a node and edge to the beginning of the path.
 void addToTail(java.lang.Object node)
          Adds an edge and node to the end of the path.
 void graftToHead(GEPath path)
          Adds a path to the beginning of this path.
 void graftToTail(GEPath path)
          Adds a path to the end of this path.
 GEPath pruneHead(int index)
          Removes from the head to the edge at index.
 GEPath pruneHeadFromFirst(java.lang.Object node)
          Removes from the head to the first occurance of node.
 GEPath pruneHeadFromLast(java.lang.Object node)
          Removes from the head to the last occurance of node.
 GEPath pruneTail(int index)
          Removes from the edge at index to the tail.
 GEPath pruneTailFromFirst(java.lang.Object node)
          Removes from the first occurance of node to the tail.
 GEPath pruneTailFromLast(java.lang.Object node)
          Removes from the last occurance of node to the tail.
 void removeHead()
          Removes the head node from the path.
 void removeTail()
          Removes the tail node from the path.
 GEPath splice(GEPath path, int startNodeIndex, int endNodeIndex)
          Splices in path between the startNodeIndex and endNodeIndex.
 GEPath spliceFirst(GEPath path)
          Splices in path between the first occurence of path's head and the first occurence of path's tail.
 GEPath spliceFirstToLast(GEPath path)
          Splices in path between the first occurence of path's head and the last occurence of path's tail.
 GEPath spliceLast(GEPath path)
          Splices in path between the last occurence of path's head and the last occurence of path's tail.
 GEPath spliceLastToFirst(GEPath 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.AbstractListGEPath
checkValid, chopList, containsEdge, containsGEDigraph, containsNode, containsNodes, countInboundEdges, countOutboundEdges, edgeCount, edgeNodeIterator, getFromNodes, getHead, getIndexOfNode, getLastIndexOfNode, getNodeAtIndex, getNodeList, getNodes, getPrincipleInterface, getSubpath, getSubpathFirst, getSubpathFirstToLast, getSubpathLast, getSubpathLastToFirst, getSupergraph, getTail, getToNodes, intersectWithGEDigraph, isEdgeFree, isEmpty, nodeCount, nodeIterator, pathEdgeCount, pathEdgeNodeIterator, pathNodeCount, pathNodeIterator, sameGEDigraphAs, sameGEPathAs, sameStateAs, toString, unionGEDigraph, 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.GEPath
getSubpath, getSubpathFirst, getSubpathFirstToLast, getSubpathLast, getSubpathLastToFirst, getSupergraph, sameGEPathAs
 
Methods inherited from interface net.walend.digraph.GEDigraph
containsGEDigraph, intersectWithGEDigraph, sameGEDigraphAs, unionGEDigraph
 
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

MutableListGEPath

public MutableListGEPath(GEPath path)
                  throws InvalidPathException
Create a new path that is a copy of path.

Throws:
InvalidPathException - if the path is not valid.

MutableListGEPath

public MutableListGEPath(GEPath path,
                         java.util.List nodeList)
Create a new path that is a copy of path, using nodeList as the nodes in the path.

Throws:
InvalidPathException - if the path is not valid.

MutableListGEPath

public MutableListGEPath(GEDigraph 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).

MutableListGEPath

public MutableListGEPath(GEDigraph 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).

MutableListGEPath

public MutableListGEPath(GEDigraph digraph,
                         java.lang.Object node,
                         java.util.List nodeList)
Creates a new path on digraph that has only node in it, using nodeList. This method clears nodeList before using it.

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

MutableListGEPath

public MutableListGEPath(GEDigraph digraph,
                         java.util.List nodeList)
Creates a new path on digraph that has only nodeList nodes in it, using nodeList. This constructor uses nodeList as the list of nodes.

Throws:
InvalidPathException - if the path is not valid.
Method Detail

addToTail

public void addToTail(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 MutableGEPath
Overrides:
addToTail in class AbstractListGEPath
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)
               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 MutableGEPath
Overrides:
addToHead in class AbstractListGEPath
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 void removeHead()
                throws LastNodeException
Removes the head node from the path.

Specified by:
removeHead in interface MutableGEPath
Overrides:
removeHead in class AbstractListGEPath
LastNodeException

removeTail

public void removeTail()
                throws LastNodeException
Removes the tail node from the path.

Specified by:
removeTail in interface MutableGEPath
Overrides:
removeTail in class AbstractListGEPath
LastNodeException

graftToTail

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

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

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

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

pruneHead

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

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

pruneTailFromFirst

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

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

pruneTailFromLast

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

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

pruneHeadFromFirst

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

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

pruneHeadFromLast

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

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

splice

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

Specified by:
splice in interface MutableGEPath
Overrides:
splice in class AbstractListGEPath
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 GEPath spliceFirst(GEPath 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 MutableGEPath
Overrides:
spliceFirst in class AbstractListGEPath
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 GEPath spliceLast(GEPath 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 MutableGEPath
Overrides:
spliceLast in class AbstractListGEPath
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 GEPath spliceFirstToLast(GEPath 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 MutableGEPath
Overrides:
spliceFirstToLast in class AbstractListGEPath
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 GEPath spliceLastToFirst(GEPath 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 MutableGEPath
Overrides:
spliceLastToFirst in class AbstractListGEPath
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