|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--net.walend.digraph.path.AbstractListUEPath
This abstract class implements the UEPath interface using a List of nodes and a List of Edges. It implements all the methods in MutableUEPath as protected, for easy subclassing. By default, it uses ArrayLists, but one constructor allows you to supply the Lists.
Nested Class Summary | |
private class |
AbstractListUEPath.EdgeCountToken
|
protected class |
AbstractListUEPath.ListEdgeIterator
|
Field Summary | |
private static int |
DEFAULTCAPACITY
|
private UEDigraph |
digraph
|
private java.util.List |
edges
|
private int |
modCount
|
private java.util.List |
nodes
|
Fields inherited from interface net.walend.digraph.UEDigraph |
EMPTY |
Constructor Summary | |
protected |
AbstractListUEPath(UEDigraph 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 |
AbstractListUEPath(UEDigraph digraph,
java.lang.Object node)
Creates a new path on digraph that has only node in it with DEFAULTCAPACITY of 7. |
protected |
AbstractListUEPath(UEDigraph digraph,
java.lang.Object node,
int nodeCapacity)
Creates a new path on digraph that has only node in it, with a capacity nodeCapacity. |
protected |
AbstractListUEPath(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 nodeList and edgeList. |
protected |
AbstractListUEPath(UEPath path)
Create a new path that is a copy of path. |
protected |
AbstractListUEPath(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 | |
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 |
containsEdge(java.lang.Object edge)
Returns true if edge exists in the digraph anywhere |
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 |
containsEdges(java.util.Set edgeSet)
|
boolean |
containsNode(java.lang.Object node)
|
boolean |
containsNodes(java.util.Set nodes)
|
boolean |
containsUEDigraph(UEDigraph digraph)
Returns true if digraph is a subgraph of this UEDigraph. |
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. |
java.util.Set |
getEdges()
|
java.lang.Object |
getFromNode(java.lang.Object edge)
|
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()
|
java.util.Set |
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()
|
java.util.Set |
getOutboundEdges(java.lang.Object node)
This implementation takes linear time. |
java.lang.Class |
getPrincipleInterface()
Returns the class's principle interface for state comparisons. |
UEPath |
getSubpath(int startNodeIndex,
int endNodeIndex)
Returns a new path, between startNodeIndex and endNodeIndex, inclusive. |
UEPath |
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. |
UEPath |
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. |
UEPath |
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. |
UEPath |
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. |
UEDigraph |
getSupergraph()
Returns the supergraph. |
java.lang.Object |
getTail()
|
java.lang.Object |
getToNode(java.lang.Object edge)
|
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(UEPath path)
Adds a path to the beginning of this path. |
protected void |
graftToTail(UEPath path)
Adds a path to the end of this path. |
UEDigraph |
intersectWithUEDigraph(UEDigraph digraph)
Returns a new digraph that is the intersection of this with digraph. |
boolean |
isEdgeFree()
Returns true if this UEDigraph 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 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. |
protected 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. |
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 |
sameStateAs(HasState victim)
If two HasStates have the same internal state, return true. |
boolean |
sameUEDigraphAs(UEDigraph digraph)
Returns true if digraph is the same as this, and all their contents have the same state. |
boolean |
sameUEPathAs(UEPath path)
Returns true if path is the same path as this, on the same digraph. |
protected UEPath |
splice(UEPath path,
int startNodeIndex,
int endNodeIndex)
Splices in path between the startNodeIndex and endNodeIndex. |
protected UEPath |
spliceFirst(UEPath path)
Splices in path between the first occurence of path's head and the first occurence of path's tail. |
protected UEPath |
spliceFirstToLast(UEPath path)
Splices in path between the first occurence of path's head and the last occurence of path's tail. |
protected UEPath |
spliceLast(UEPath path)
Splices in path between the last occurence of path's head and the last occurence of path's tail. |
protected UEPath |
spliceLastToFirst(UEPath path)
Splices in path between the last occurence of path's head and the first occurence of path's tail. |
java.lang.String |
toString()
|
UEDigraph |
unionUEDigraph(UEDigraph 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 UEDigraph digraph
Constructor Detail |
protected AbstractListUEPath(UEPath path)
InvalidPathException
- if the path is not valid.protected AbstractListUEPath(UEPath path, java.util.List nodeList, java.util.List edgeList)
InvalidPathException
- if the path is not valid.protected AbstractListUEPath(UEDigraph digraph, java.lang.Object node)
InvalidPathException
- if the path is not valid (because the node isn't in the supergraph).protected AbstractListUEPath(UEDigraph digraph, java.lang.Object node, int nodeCapacity)
InvalidPathException
- if the path is not valid (because the node isn't in the supergraph).protected AbstractListUEPath(UEDigraph 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 AbstractListUEPath(UEDigraph 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 Digraph
public int edgeCount()
edgeCount
in interface Digraph
public int pathNodeCount()
pathNodeCount
in interface Path
public int pathEdgeCount()
pathEdgeCount
in interface Path
public boolean isEmpty()
isEmpty
in interface Digraph
public boolean containsNode(java.lang.Object node)
containsNode
in interface Digraph
public boolean containsEdge(java.lang.Object edge)
UEDigraph
containsEdge
in interface UEDigraph
public java.lang.Object getFromNode(java.lang.Object edge) throws EdgeMissingException
getFromNode
in interface UEDigraph
EdgeMissingException
- if the edge is not in the digraph.public java.lang.Object getToNode(java.lang.Object edge) throws EdgeMissingException
getToNode
in interface UEDigraph
EdgeMissingException
- if the edge is not in the digraph.public java.util.Set getEdges()
getEdges
in interface UEDigraph
public boolean containsEdges(java.util.Set edgeSet)
containsEdges
in interface UEDigraph
public boolean containsEdge(java.lang.Object fromNode, java.lang.Object toNode) throws NodeMissingException
containsEdge
in interface Digraph
NodeMissingException
- 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 UEDigraph
NodeMissingException
- if either node is missing from the digraph.public int countInboundEdges(java.lang.Object node) throws NodeMissingException
countInboundEdges
in interface Digraph
NodeMissingException
- if node is not in the digraph.public int countOutboundEdges(java.lang.Object node) throws NodeMissingException
countOutboundEdges
in interface Digraph
NodeMissingException
- if node is not in the digraph.public java.util.Set getInboundEdges(java.lang.Object node) throws NodeMissingException
getInboundEdges
in interface UEDigraph
NodeMissingException
- if node is not in the digraph.public java.util.Set getOutboundEdges(java.lang.Object node) throws NodeMissingException
getOutboundEdges
in interface UEDigraph
NodeMissingException
- 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 UEDigraph
NodeMissingException
- 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 Digraph
NodeMissingException
- 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 Digraph
NodeMissingException
- if node is not in the digraph.public java.util.Iterator nodeIterator()
nodeIterator
in interface Digraph
public java.util.Iterator pathNodeIterator()
Path
The Iterator should start at the beginning of the path and iterate to the end.
pathNodeIterator
in interface Path
public EdgeIterator edgeIterator()
edgeIterator
in interface UEDigraph
public EdgeIterator pathEdgeIterator()
UEPath
The Iterator should start at the beginning of the path and iterate to the end.
pathEdgeIterator
in interface UEPath
public EdgeNodeIterator edgeNodeIterator()
edgeNodeIterator
in interface Digraph
public EdgeNodeIterator pathEdgeNodeIterator()
Path
If Path is immutable, edgeIterator()'s remove() method throws an UnsupportedOperationException.
pathEdgeNodeIterator
in interface Path
public java.util.Set getNodes()
getNodes
in interface Digraph
public boolean isEdgeFree()
isEdgeFree
in interface Digraph
public boolean containsNodes(java.util.Set nodes)
containsNodes
in interface Digraph
public boolean containsUEDigraph(UEDigraph digraph)
containsUEDigraph
in interface UEDigraph
public boolean sameUEDigraphAs(UEDigraph digraph)
sameUEDigraphAs
in interface UEDigraph
public UEDigraph intersectWithUEDigraph(UEDigraph digraph)
intersectWithUEDigraph
in interface UEDigraph
public UEDigraph unionUEDigraph(UEDigraph digraph)
unionUEDigraph
in interface UEDigraph
public java.lang.Class getPrincipleInterface()
HasState
getPrincipleInterface
in interface HasState
public boolean sameStateAs(HasState victim)
HasState
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.
sameStateAs
in interface HasState
public boolean valid()
valid
in interface Path
public UEDigraph getSupergraph()
getSupergraph
in interface UEPath
public java.lang.Object getHead()
getHead
in interface Path
public java.lang.Object getTail()
getTail
in interface Path
public java.lang.Object getNodeAtIndex(int index)
getNodeAtIndex
in interface Path
public java.lang.Object getEdgeAtIndex(int index)
getEdgeAtIndex
in interface UEPath
public int getIndexOfNode(java.lang.Object node)
getIndexOfNode
in interface Path
public int getLastIndexOfNode(java.lang.Object node)
getLastIndexOfNode
in interface Path
public int getIndexOfEdge(java.lang.Object edge)
getIndexOfEdge
in interface UEPath
public int getLastIndexOfEdge(java.lang.Object edge)
getLastIndexOfEdge
in interface UEPath
public java.util.List getNodeList()
getNodeList
in interface Path
public java.util.List getEdgeList()
getEdgeList
in interface UEPath
private void checkIndices(int startNodeIndex, int endNodeIndex) throws InvalidSpliceException
InvalidSpliceException
public UEPath getSubpath(int startNodeIndex, int endNodeIndex) throws InvalidSpliceException
getSubpath
in interface UEPath
InvalidSpliceException
private void checkSubpathIndices(int startNodeIndex, int endNodeIndex, java.lang.Object startNode, java.lang.Object endNode) throws NodeMissingException, InvalidSpliceException
NodeMissingException
InvalidSpliceException
public UEPath getSubpathFirst(java.lang.Object startNode, java.lang.Object endNode) throws NodeMissingException, InvalidSpliceException
getSubpathFirst
in interface UEPath
NodeMissingException
- if the nodes are not in the path.
InvalidSpliceException
- if the nodes are not in the right order.public UEPath getSubpathLast(java.lang.Object startNode, java.lang.Object endNode) throws NodeMissingException, InvalidSpliceException
getSubpathLast
in interface UEPath
NodeMissingException
- if the nodes are not in the path.
InvalidSpliceException
- if the nodes are not in the right order.public UEPath getSubpathFirstToLast(java.lang.Object startNode, java.lang.Object endNode) throws NodeMissingException, InvalidSpliceException
getSubpathFirstToLast
in interface UEPath
NodeMissingException
- if the nodes are not in the path.
InvalidSpliceException
- if the nodes are not in the right order.public UEPath getSubpathLastToFirst(java.lang.Object startNode, java.lang.Object endNode) throws NodeMissingException, InvalidSpliceException
getSubpathLastToFirst
in interface UEPath
NodeMissingException
- if the nodes are not in the path.
InvalidSpliceException
- if the nodes are not in the right order.public boolean sameUEPathAs(UEPath path)
sameUEPathAs
in interface UEPath
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(UEPath 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(UEPath 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 UEPath pruneTail(int index)
protected UEPath pruneHead(int index)
public UEPath pruneTailFromFirst(java.lang.Object node) throws NodeMissingException
NodeMissingException
- if the node is not in the digraph.public UEPath pruneTailFromLast(java.lang.Object node) throws NodeMissingException
NodeMissingException
- if the node is not in the digraph.public UEPath pruneHeadFromFirst(java.lang.Object node) throws NodeMissingException
NodeMissingException
- if the node is not in the digraph.public UEPath pruneHeadFromLast(java.lang.Object node) throws NodeMissingException
NodeMissingException
- if the node is not in the digraph.protected UEPath splice(UEPath 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 UEPath spliceFirst(UEPath 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 UEPath spliceLast(UEPath 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 UEPath spliceFirstToLast(UEPath 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 UEPath spliceLastToFirst(UEPath 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.public java.lang.String toString()
toString
in class java.lang.Object
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |