|
|||||||||||
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 Digraph
public int edgeCount()
edgeCount
in interface Digraph
public boolean isEmpty()
isEmpty
in interface Digraph
private void checkNode(java.lang.Object node)
public boolean containsNode(java.lang.Object node)
containsNode
in interface Digraph
private int indexOfNode(java.lang.Object node)
public boolean containsEdge(java.lang.Object fromNode, java.lang.Object toNode) throws NodeMissingException
Digraph
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.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 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
Inefficient. Iterates through all the edges.
getInboundEdges
in interface UEDigraph
NodeMissingException
- 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 UEDigraph
NodeMissingException
- if node is not in the digraph.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.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
Inefficient. Iterates through all the edges.
getFromNodes
in interface Digraph
NodeMissingException
- 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 Digraph
NodeMissingException
- if node is not in the digraph.public java.util.Iterator nodeIterator()
Digraph
nodeIterator
in interface Digraph
public EdgeIterator edgeIterator()
edgeIterator
in interface UEDigraph
public EdgeNodeIterator edgeNodeIterator()
edgeNodeIterator
in interface Digraph
public java.util.Set getNodes()
getNodes
in interface Digraph
public java.util.Set getEdges()
getEdges
in interface UEDigraph
public boolean isEdgeFree()
isEdgeFree
in interface Digraph
public boolean containsNodes(java.util.Set nodes)
containsNodes
in interface Digraph
public boolean containsEdges(java.util.Set edges)
containsEdges
in interface UEDigraph
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
protected 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
NodeMissingException
protected boolean removeEdge(java.lang.Object edge)
protected java.lang.Object removeEdge(java.lang.Object fromNode, java.lang.Object toNode) throws NodeMissingException
NodeMissingException
protected 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 |