|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Object | +--net.walend.digraph.path.AbstractListCEPath
This abstract class implements the CEPath interface using a List of nodes and a List of Edges. It implements all the methods in MutableCEPath as protected, for easy subclassing. By default, it uses ArrayLists, but one constructor allows you to supply the Lists.
| Nested Class Summary | |
private class |
AbstractListCEPath.EdgeCountToken
|
protected class |
AbstractListCEPath.ListEdgeIterator
|
| Field Summary | |
private static int |
DEFAULTCAPACITY
|
private CEDigraph |
digraph
|
private java.util.List |
edges
|
private int |
modCount
|
private java.util.List |
nodes
|
| Fields inherited from interface net.walend.digraph.CEDigraph |
EMPTY |
| Constructor Summary | |
protected |
AbstractListCEPath(CEDigraph digraph,
java.util.List nodeList,
java.util.List edgeList)
Creates a new path on digraph that has only node in it, using nodeList and edgeList. |
protected |
AbstractListCEPath(CEDigraph digraph,
java.lang.Object node)
Creates a new path on digraph that has only node in it with DEFAULTCAPACITY of 7. |
protected |
AbstractListCEPath(CEDigraph digraph,
java.lang.Object node,
int nodeCapacity)
Creates a new path on digraph that has only node in it, with a capacity nodeCapacity. |
protected |
AbstractListCEPath(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 nodeList and edgeList. |
protected |
AbstractListCEPath(CEPath path)
Create a new path that is a copy of path. |
protected |
AbstractListCEPath(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 | |
protected void |
addToHead(java.lang.Object node,
java.lang.Object edge)
Adds a node and edge to the beginning of the path. |
protected void |
addToTail(java.lang.Object edge,
java.lang.Object node)
Adds an edge and node to the end of the path. |
private void |
checkIndices(int startNodeIndex,
int endNodeIndex)
|
private void |
checkSubpathIndices(int startNodeIndex,
int endNodeIndex,
java.lang.Object startNode,
java.lang.Object endNode)
|
protected void |
checkValid()
Throw an InvalidPathException if anything is wrong. |
protected void |
chopList(java.util.List victim,
int fromIndex,
int toIndex)
|
boolean |
containsCEDigraph(CEDigraph digraph)
Returns true if digraph is a subgraph of this CEDigraph. |
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(java.lang.Object node)
|
boolean |
containsNodes(java.util.Set nodes)
|
int |
countInboundEdges(java.lang.Object node)
This implementation takes linear time. |
int |
countOutboundEdges(java.lang.Object node)
This implementation takes linear time. |
int |
edgeCount()
This method is wildly inefficient. |
EdgeIterator |
edgeIterator()
edgeIterator()'s remove() method throws an UnsupportedOperationException. |
EdgeNodeIterator |
edgeNodeIterator()
Returns an iterator that iterates across pairs of nodes that make edges. |
java.lang.Object |
getEdge(java.lang.Object fromNode,
java.lang.Object toNode)
Returns null if no edge links fromNode to toNode. |
java.lang.Object |
getEdgeAtIndex(int index)
|
java.util.List |
getEdgeList()
Returns an immutable list of the edges. |
Bag |
getEdges()
|
java.util.Set |
getFromNodes(java.lang.Object node)
Returns the set of nodes that can reach this node by crossing one edge. |
java.lang.Object |
getHead()
|
Bag |
getInboundEdges(java.lang.Object node)
This implementation takes linear time. |
int |
getIndexOfEdge(java.lang.Object edge)
|
int |
getIndexOfNode(java.lang.Object node)
|
int |
getLastIndexOfEdge(java.lang.Object edge)
|
int |
getLastIndexOfNode(java.lang.Object node)
|
java.lang.Object |
getNodeAtIndex(int index)
|
java.util.List |
getNodeList()
Returns an immutable list of the nodes. |
java.util.Set |
getNodes()
|
Bag |
getOutboundEdges(java.lang.Object node)
This implementation takes linear time. |
java.lang.Class |
getPrincipleInterface()
Returns the class's principle interface for state comparisons. |
CEPath |
getSubpath(int startNodeIndex,
int endNodeIndex)
Returns a new path, between startNodeIndex and endNodeIndex, inclusive. |
CEPath |
getSubpathFirst(java.lang.Object startNode,
java.lang.Object endNode)
Returns a new path, between the first occurence of startNode and the first occurence of endNode, inclusive. |
CEPath |
getSubpathFirstToLast(java.lang.Object startNode,
java.lang.Object endNode)
Returns a new path, between the first occurence of startNode and the last occurence of endNode, inclusive. |
CEPath |
getSubpathLast(java.lang.Object startNode,
java.lang.Object endNode)
Returns a new path, between the last occurence of startNode and the last occurence of endNode, inclusive. |
CEPath |
getSubpathLastToFirst(java.lang.Object startNode,
java.lang.Object endNode)
Returns a new path, between the last occurence of startNode and the first occurence of endNode, inclusive. |
CEDigraph |
getSupergraph()
Returns the supergraph. |
java.lang.Object |
getTail()
|
java.util.Set |
getToNodes(java.lang.Object node)
Returns the set of nodes that can be reached from this node by crossing one edge. |
protected void |
graftToHead(CEPath path)
Adds a path to the beginning of this path. |
protected void |
graftToTail(CEPath path)
Adds a path to the end of this path. |
CEDigraph |
intersectWithCEDigraph(CEDigraph digraph)
Returns a new digraph that is the intersection of this with digraph. |
boolean |
isEdgeFree()
Returns true if this CEDigraph has no edges. |
boolean |
isEmpty()
|
int |
nodeCount()
This method is not terribly efficient. |
java.util.Iterator |
nodeIterator()
nodeIterator()'s remove() method throws an UnsupportedOperationException. |
int |
pathEdgeCount()
Returns the number of edges in the path, including repeats. |
EdgeIterator |
pathEdgeIterator()
Implementations should explicitly state how they interpret nodeIterator()'s remove method. |
EdgeNodeIterator |
pathEdgeNodeIterator()
Iterate through the edges in path order. |
int |
pathNodeCount()
Returns the number of nodes in the path, including repeates. |
java.util.Iterator |
pathNodeIterator()
Implementations should explicitly state how they interpret nodeIterator()'s remove method. |
protected CEPath |
pruneHead(int index)
Removes from the head to the edge at index. |
protected CEPath |
pruneHeadFromFirst(java.lang.Object node)
Removes from the head to the first occurance of node. |
protected CEPath |
pruneHeadFromLast(java.lang.Object node)
Removes from the head to the last occurance of node. |
protected CEPath |
pruneTail(int index)
Removes from the edge at index to the tail. |
protected CEPath |
pruneTailFromFirst(java.lang.Object node)
Removes from the first occurance of node to the tail. |
protected CEPath |
pruneTailFromLast(java.lang.Object node)
Removes from the last occurance of node to the tail. |
protected java.lang.Object |
removeHead()
Removes the head node from the path. |
protected java.lang.Object |
removeTail()
Removes the tail node from the path. |
boolean |
sameCEDigraphAs(CEDigraph digraph)
Returns true if digraph is the same as this, and all their contents have the same state. |
boolean |
sameCEPathAs(CEPath path)
Returns true if path is the same path as this, on the same digraph. |
boolean |
sameStateAs(HasState victim)
If two HasStates have the same internal state, return true. |
protected CEPath |
splice(CEPath path,
int startNodeIndex,
int endNodeIndex)
Splices in path between the startNodeIndex and endNodeIndex. |
protected CEPath |
spliceFirst(CEPath path)
Splices in path between the first occurence of path's head and the first occurence of path's tail. |
protected CEPath |
spliceFirstToLast(CEPath path)
Splices in path between the first occurence of path's head and the last occurence of path's tail. |
protected CEPath |
spliceLast(CEPath path)
Splices in path between the last occurence of path's head and the last occurence of path's tail. |
protected CEPath |
spliceLastToFirst(CEPath path)
Splices in path between the last occurence of path's head and the first occurence of path's tail. |
java.lang.String |
toString()
|
CEDigraph |
unionCEDigraph(CEDigraph digraph)
Returns a new digraph that is the union of this with digraph. |
boolean |
valid()
Returns true if this path is still a subgraph of its supergraph |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
private static final int DEFAULTCAPACITY
private java.util.List nodes
private java.util.List edges
private transient volatile int modCount
private CEDigraph digraph
| Constructor Detail |
protected AbstractListCEPath(CEPath path)
InvalidPathException - if the path is not valid.
protected AbstractListCEPath(CEPath path,
java.util.List nodeList,
java.util.List edgeList)
InvalidPathException - if the path is not valid.
protected AbstractListCEPath(CEDigraph digraph,
java.lang.Object node)
InvalidPathException - if the path is not valid (because the node isn't in the supergraph).
protected AbstractListCEPath(CEDigraph digraph,
java.lang.Object node,
int nodeCapacity)
InvalidPathException - if the path is not valid (because the node isn't in the supergraph).
protected AbstractListCEPath(CEDigraph digraph,
java.lang.Object node,
java.util.List nodeList,
java.util.List edgeList)
InvalidPathException - if the path is not valid (because the node isn't in the supergraph).
protected AbstractListCEPath(CEDigraph digraph,
java.util.List nodeList,
java.util.List edgeList)
InvalidPathException - if the path is not valid (because the node isn't in the supergraph).| Method Detail |
protected void checkValid()
public int nodeCount()
nodeCount in interface Digraphpublic int edgeCount()
edgeCount in interface Digraphpublic int pathNodeCount()
pathNodeCount in interface Pathpublic int pathEdgeCount()
pathEdgeCount in interface Pathpublic boolean isEmpty()
isEmpty in interface Digraphpublic boolean containsNode(java.lang.Object node)
containsNode in interface Digraph
public boolean containsEdge(java.lang.Object fromNode,
java.lang.Object toNode)
throws NodeMissingException
containsEdge in interface DigraphNodeMissingException - if either node is missing from the digraph.
public boolean containsEdge(java.lang.Object fromNode,
java.lang.Object toNode,
java.lang.Object edge)
throws NodeMissingException
containsEdge in interface CEDigraphNodeMissingException - if either node is missing from the digraph.
public int countInboundEdges(java.lang.Object node)
throws NodeMissingException
countInboundEdges in interface DigraphNodeMissingException - if node is not in the digraph.
public int countOutboundEdges(java.lang.Object node)
throws NodeMissingException
countOutboundEdges in interface DigraphNodeMissingException - if node is not in the digraph.
public Bag getInboundEdges(java.lang.Object node)
throws NodeMissingException
getInboundEdges in interface CEDigraphNodeMissingException - if node is not in the digraph.
public Bag getOutboundEdges(java.lang.Object node)
throws NodeMissingException
getOutboundEdges in interface CEDigraphNodeMissingException - if node is not in the digraph.
public java.lang.Object getEdge(java.lang.Object fromNode,
java.lang.Object toNode)
throws NodeMissingException
getEdge in interface CEDigraphNodeMissingException - if either node is missing from the digraph.
public java.util.Set getFromNodes(java.lang.Object node)
throws NodeMissingException
If you know this path is acyclic, override this method with one that takes constant time.
getFromNodes in interface DigraphNodeMissingException - if node is not in the digraph.
public java.util.Set getToNodes(java.lang.Object node)
throws NodeMissingException
If you know this path is acyclic, override this method with one that takes constant time.
getToNodes in interface DigraphNodeMissingException - if node is not in the digraph.public java.util.Iterator nodeIterator()
nodeIterator in interface Digraphpublic java.util.Iterator pathNodeIterator()
PathThe Iterator should start at the beginning of the path and iterate to the end.
pathNodeIterator in interface Pathpublic EdgeIterator edgeIterator()
edgeIterator in interface CEDigraphpublic EdgeIterator pathEdgeIterator()
CEPathThe Iterator should start at the beginning of the path and iterate to the end.
pathEdgeIterator in interface CEPathpublic EdgeNodeIterator edgeNodeIterator()
edgeNodeIterator in interface Digraphpublic EdgeNodeIterator pathEdgeNodeIterator()
PathIf Path is immutable, edgeIterator()'s remove() method throws an UnsupportedOperationException.
pathEdgeNodeIterator in interface Pathpublic java.util.Set getNodes()
getNodes in interface Digraphpublic Bag getEdges()
getEdges in interface CEDigraphpublic boolean isEdgeFree()
isEdgeFree in interface Digraphpublic boolean containsNodes(java.util.Set nodes)
containsNodes in interface Digraphpublic boolean containsCEDigraph(CEDigraph digraph)
containsCEDigraph in interface CEDigraphpublic boolean sameCEDigraphAs(CEDigraph digraph)
sameCEDigraphAs in interface CEDigraphpublic CEDigraph intersectWithCEDigraph(CEDigraph digraph)
intersectWithCEDigraph in interface CEDigraphpublic CEDigraph unionCEDigraph(CEDigraph digraph)
unionCEDigraph in interface CEDigraphpublic java.lang.Class getPrincipleInterface()
HasState
getPrincipleInterface in interface HasStatepublic boolean sameStateAs(HasState victim)
HasStateFor 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.
sameStateAs in interface HasStatepublic java.lang.String toString()
toString in class java.lang.Objectpublic boolean valid()
valid in interface Pathpublic CEDigraph getSupergraph()
getSupergraph in interface CEPathpublic java.lang.Object getHead()
getHead in interface Pathpublic java.lang.Object getTail()
getTail in interface Pathpublic java.lang.Object getNodeAtIndex(int index)
getNodeAtIndex in interface Pathpublic java.lang.Object getEdgeAtIndex(int index)
getEdgeAtIndex in interface CEPathpublic int getIndexOfNode(java.lang.Object node)
getIndexOfNode in interface Pathpublic int getLastIndexOfNode(java.lang.Object node)
getLastIndexOfNode in interface Pathpublic int getIndexOfEdge(java.lang.Object edge)
getIndexOfEdge in interface CEPathpublic int getLastIndexOfEdge(java.lang.Object edge)
getLastIndexOfEdge in interface CEPathpublic java.util.List getNodeList()
getNodeList in interface Pathpublic java.util.List getEdgeList()
getEdgeList in interface CEPath
private void checkIndices(int startNodeIndex,
int endNodeIndex)
throws InvalidSpliceException
InvalidSpliceException
public CEPath getSubpath(int startNodeIndex,
int endNodeIndex)
throws InvalidSpliceException
getSubpath in interface CEPathInvalidSpliceException
private void checkSubpathIndices(int startNodeIndex,
int endNodeIndex,
java.lang.Object startNode,
java.lang.Object endNode)
throws NodeMissingException,
InvalidSpliceException
NodeMissingException
InvalidSpliceException
public CEPath getSubpathFirst(java.lang.Object startNode,
java.lang.Object endNode)
throws NodeMissingException,
InvalidSpliceException
getSubpathFirst in interface CEPathNodeMissingException - if the nodes are not in the path.
InvalidSpliceException - if the nodes are not in the right order.
public CEPath getSubpathLast(java.lang.Object startNode,
java.lang.Object endNode)
throws NodeMissingException,
InvalidSpliceException
getSubpathLast in interface CEPathNodeMissingException - if the nodes are not in the path.
InvalidSpliceException - if the nodes are not in the right order.
public CEPath getSubpathFirstToLast(java.lang.Object startNode,
java.lang.Object endNode)
throws NodeMissingException,
InvalidSpliceException
getSubpathFirstToLast in interface CEPathNodeMissingException - if the nodes are not in the path.
InvalidSpliceException - if the nodes are not in the right order.
public CEPath getSubpathLastToFirst(java.lang.Object startNode,
java.lang.Object endNode)
throws NodeMissingException,
InvalidSpliceException
getSubpathLastToFirst in interface CEPathNodeMissingException - if the nodes are not in the path.
InvalidSpliceException - if the nodes are not in the right order.public boolean sameCEPathAs(CEPath path)
sameCEPathAs in interface CEPath
protected void addToTail(java.lang.Object edge,
java.lang.Object node)
throws EdgeMissingException,
NodeMissingException
returns true if the operation is successful, false if the path is unchanged.
EdgeMissingException - if the edge is not in the digraph between the tail node and node.
NodeMissingException - if the node is not in the digraph.
protected void addToHead(java.lang.Object node,
java.lang.Object edge)
throws EdgeMissingException,
NodeMissingException
returns true if the operation is successful, false if the path is unchanged.
EdgeMissingException - if the edge is not in the digraph between the tail node and node.
NodeMissingException - if the node is not in the digraph.
protected void graftToTail(CEPath path)
throws EdgeMissingException,
NodeMissingException,
InvalidSpliceException
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.
protected void graftToHead(CEPath path)
throws EdgeMissingException,
NodeMissingException,
InvalidSpliceException
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.
protected java.lang.Object removeHead()
throws LastNodeException
returns the orphaned edge.
LastNodeException
protected java.lang.Object removeTail()
throws LastNodeException
returns the orphaned edge.
LastNodeException
protected void chopList(java.util.List victim,
int fromIndex,
int toIndex)
protected CEPath pruneTail(int index)
protected CEPath pruneHead(int index)
protected CEPath pruneTailFromFirst(java.lang.Object node)
throws NodeMissingException
NodeMissingException - if the node is not in the digraph.
protected CEPath pruneTailFromLast(java.lang.Object node)
throws NodeMissingException
NodeMissingException - if the node is not in the digraph.
protected CEPath pruneHeadFromFirst(java.lang.Object node)
throws NodeMissingException
NodeMissingException - if the node is not in the digraph.
protected CEPath pruneHeadFromLast(java.lang.Object node)
throws NodeMissingException
NodeMissingException - if the node is not in the digraph.
protected CEPath splice(CEPath path,
int startNodeIndex,
int endNodeIndex)
throws EdgeMissingException,
NodeMissingException,
InvalidSpliceException
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.
protected CEPath spliceFirst(CEPath path)
throws EdgeMissingException,
NodeMissingException,
InvalidSpliceException
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.
protected CEPath spliceLast(CEPath path)
throws EdgeMissingException,
NodeMissingException,
InvalidSpliceException
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.
protected CEPath spliceFirstToLast(CEPath path)
throws EdgeMissingException,
NodeMissingException,
InvalidSpliceException
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.
protected CEPath spliceLastToFirst(CEPath path)
throws EdgeMissingException,
NodeMissingException,
InvalidSpliceException
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.
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||