|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Object | +--net.walend.digraph.AbstractMatrixUEDigraph
This abstract class implements the UEDigraph interface using a List and a Grid. It's great for sparse graphs. Subclass it as is for an immutable UEDigraph. Mix in the MutableUEDigraph interface for one you can change.
| Nested Class Summary | |
protected class |
AbstractMatrixUEDigraph.MatrixEdgeIterator
|
protected class |
AbstractMatrixUEDigraph.NodeIterator
|
| Field Summary | |
private int |
edgeCount
|
private MutableGrid2D |
edgeGrid
|
private int |
nodeCount
|
private java.util.ArrayList |
nodeList
|
| Fields inherited from interface net.walend.digraph.UEDigraph |
EMPTY |
| Constructor Summary | |
protected |
AbstractMatrixUEDigraph(int nodeCapacity)
|
protected |
AbstractMatrixUEDigraph(UEDigraph digraph)
|
| Method Summary | |
protected java.lang.Object |
addEdge(java.lang.Object fromNode,
java.lang.Object toNode,
java.lang.Object edge)
|
protected boolean |
addNode(java.lang.Object node)
|
protected boolean |
addNodes(java.util.Set nodesToAdd)
|
private void |
checkEdge(java.lang.Object edge)
|
private void |
checkNode(java.lang.Object node)
|
protected void |
clear()
|
protected void |
clearEdges()
|
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 edges)
|
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)
Efficient. |
int |
countOutboundEdges(java.lang.Object node)
Efficient. |
int |
edgeCount()
|
EdgeIterator |
edgeIterator()
|
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.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.util.Set |
getInboundEdges(java.lang.Object node)
Returns the empty set if node has no inbound edges. |
java.util.Set |
getNodes()
|
java.util.Set |
getOutboundEdges(java.lang.Object node)
Returns the empty set if node has no outbound edges. |
java.lang.Class |
getPrincipleInterface()
Returns the class's principle interface for state comparisons. |
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 |
growMatrix(int newSize)
This method doubles the size of the matrix |
private int |
indexOfNode(java.lang.Object node)
|
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()
|
java.util.Iterator |
nodeIterator()
Implementations should explicitly state how they interpret nodeIterator()'s remove method. |
private void |
putNodeInFirstNull(java.lang.Object node)
|
protected boolean |
removeEdge(java.lang.Object edge)
|
protected java.lang.Object |
removeEdge(java.lang.Object fromNode,
java.lang.Object toNode)
|
protected boolean |
removeEdges(java.util.Set edges)
|
private java.util.Set |
removeEdges(UEDigraph digraph)
|
protected java.util.Set |
removeNode(java.lang.Object node)
|
protected java.util.Set |
removeNodes(java.util.Set nodesToRemove)
|
protected java.util.Set |
removeUEDigraph(UEDigraph digraph)
|
protected boolean |
retainEdges(java.util.Set retainedEdges)
|
protected java.util.Set |
retainNodes(java.util.Set retainedNodes)
|
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. |
java.lang.String |
toString()
|
UEDigraph |
unionUEDigraph(UEDigraph digraph)
Returns a new digraph that is the union of this with digraph. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
private java.util.ArrayList nodeList
private MutableGrid2D edgeGrid
private int nodeCount
private int edgeCount
| Constructor Detail |
protected AbstractMatrixUEDigraph(int nodeCapacity)
protected AbstractMatrixUEDigraph(UEDigraph digraph)
| Method Detail |
public int nodeCount()
nodeCount in interface Digraphpublic int edgeCount()
edgeCount in interface Digraphpublic boolean isEmpty()
isEmpty in interface Digraphprivate void checkNode(java.lang.Object node)
public boolean containsNode(java.lang.Object node)
containsNode in interface Digraphprivate int indexOfNode(java.lang.Object node)
public boolean containsEdge(java.lang.Object fromNode,
java.lang.Object toNode)
throws NodeMissingException
Digraph
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 UEDigraphNodeMissingException - if either node is missing from the digraph.private void checkEdge(java.lang.Object edge)
public boolean containsEdge(java.lang.Object edge)
containsEdge in interface UEDigraph
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 java.util.Set getInboundEdges(java.lang.Object node)
throws NodeMissingException
Inefficient. Iterates through all the edges.
getInboundEdges in interface UEDigraphNodeMissingException - if node is not in the digraph.
public java.util.Set getOutboundEdges(java.lang.Object node)
throws NodeMissingException
Inefficient. Iterates through all the edges.
getOutboundEdges in interface UEDigraphNodeMissingException - if node is not in the digraph.
public java.lang.Object getFromNode(java.lang.Object edge)
throws EdgeMissingException
getFromNode in interface UEDigraphEdgeMissingException - if the edge is not in the digraph.
public java.lang.Object getToNode(java.lang.Object edge)
throws EdgeMissingException
getToNode in interface UEDigraphEdgeMissingException - if the edge is not in the digraph.
public java.lang.Object getEdge(java.lang.Object fromNode,
java.lang.Object toNode)
throws NodeMissingException
getEdge in interface UEDigraphNodeMissingException - if either node is missing from the digraph.
public java.util.Set getFromNodes(java.lang.Object node)
throws NodeMissingException
Inefficient. Iterates through all the edges.
getFromNodes in interface DigraphNodeMissingException - if node is not in the digraph.
public java.util.Set getToNodes(java.lang.Object node)
throws NodeMissingException
Inefficient. Iterates through all the edges.
getToNodes in interface DigraphNodeMissingException - if node is not in the digraph.public java.util.Iterator nodeIterator()
Digraph
nodeIterator in interface Digraphpublic EdgeIterator edgeIterator()
edgeIterator in interface UEDigraphpublic EdgeNodeIterator edgeNodeIterator()
edgeNodeIterator in interface Digraphpublic java.util.Set getNodes()
getNodes in interface Digraphpublic java.util.Set getEdges()
getEdges in interface UEDigraphpublic boolean isEdgeFree()
isEdgeFree in interface Digraphpublic boolean containsNodes(java.util.Set nodes)
containsNodes in interface Digraphpublic boolean containsEdges(java.util.Set edges)
containsEdges in interface UEDigraphpublic boolean containsUEDigraph(UEDigraph digraph)
containsUEDigraph in interface UEDigraphpublic boolean sameUEDigraphAs(UEDigraph digraph)
sameUEDigraphAs in interface UEDigraphpublic UEDigraph intersectWithUEDigraph(UEDigraph digraph)
intersectWithUEDigraph in interface UEDigraphpublic UEDigraph unionUEDigraph(UEDigraph digraph)
unionUEDigraph in interface UEDigraphpublic 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 HasStateprotected void growMatrix(int newSize)
private void putNodeInFirstNull(java.lang.Object node)
protected boolean addNode(java.lang.Object node)
protected java.lang.Object addEdge(java.lang.Object fromNode,
java.lang.Object toNode,
java.lang.Object edge)
throws NodeMissingException,
EdgeNotUniqueException
NodeMissingException
EdgeNotUniqueException
protected java.util.Set removeNode(java.lang.Object node)
throws NodeMissingException
NodeMissingExceptionprotected boolean removeEdge(java.lang.Object edge)
protected java.lang.Object removeEdge(java.lang.Object fromNode,
java.lang.Object toNode)
throws NodeMissingException
NodeMissingExceptionprotected boolean addNodes(java.util.Set nodesToAdd)
protected java.util.Set removeNodes(java.util.Set nodesToRemove)
protected boolean removeEdges(java.util.Set edges)
private java.util.Set removeEdges(UEDigraph digraph)
protected java.util.Set removeUEDigraph(UEDigraph digraph)
protected java.util.Set retainNodes(java.util.Set retainedNodes)
protected boolean retainEdges(java.util.Set retainedEdges)
protected void clear()
protected void clearEdges()
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 | ||||||||||