|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--net.walend.digraph.AbstractMatrixCEDigraph
This abstract class implements the CEDigraph interface using a Map and a Set. It's great for sparse graphs. Subclass it as is for an immutable CEDigraph. Mix in the MutableCEDigraph interface for one you can change.
Nested Class Summary | |
protected class |
AbstractMatrixCEDigraph.MatrixEdgeIterator
|
protected class |
AbstractMatrixCEDigraph.NodeIterator
|
Field Summary | |
private int |
edgeCount
|
private MutableGrid2D |
edgeGrid
|
private int |
nodeCount
|
private java.util.ArrayList |
nodeList
|
Fields inherited from interface net.walend.digraph.CEDigraph |
EMPTY |
Constructor Summary | |
protected |
AbstractMatrixCEDigraph(CEDigraph digraph)
|
protected |
AbstractMatrixCEDigraph(GEDigraph digraph,
java.lang.Object edge)
|
protected |
AbstractMatrixCEDigraph(int nodeCapacity)
|
protected |
AbstractMatrixCEDigraph(UEDigraph digraph)
|
Method Summary | |
protected java.lang.Object |
addEdge(int fromIndex,
int toIndex,
java.lang.Object edge)
|
protected java.lang.Object |
addEdge(java.lang.Object fromNode,
java.lang.Object toNode,
java.lang.Object edge)
Return null if no existing edge is displaced by 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 |
containsCEDigraph(CEDigraph digraph)
Returns true if digraph is a subgraph of this CEDigraph. |
boolean |
containsEdge(int fromIndex,
int toIndex)
|
boolean |
containsEdge(int fromIndex,
int toIndex,
java.lang.Object edge)
|
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(int index)
|
boolean |
containsNode(java.lang.Object node)
|
boolean |
containsNodes(java.util.Set nodes)
|
int |
countInboundEdges(int toIndex)
|
int |
countInboundEdges(java.lang.Object node)
Inefficient. |
int |
countOutboundEdges(int fromIndex)
|
int |
countOutboundEdges(java.lang.Object node)
Inefficient. |
int |
edgeCount()
|
EdgeIterator |
edgeIterator()
|
EdgeNodeIterator |
edgeNodeIterator()
Returns an iterator that iterates across pairs of nodes that make edges. |
java.lang.Object |
getEdge(int fromIndex,
int toIndex)
|
java.lang.Object |
getEdge(java.lang.Object fromNode,
java.lang.Object toNode)
Returns null if no edge links fromNode to toNode |
Bag |
getEdges()
|
int[] |
getFromIndices(int toIndex)
|
java.util.Set |
getFromNodes(int toIndex)
|
java.util.Set |
getFromNodes(java.lang.Object node)
Returns the set of nodes that can reach this node by crossing one edge. |
Bag |
getInboundEdges(int toIndex)
|
Bag |
getInboundEdges(java.lang.Object node)
Returns the empty set if node has no inbound edges. |
java.lang.Object |
getNode(int index)
|
int |
getNodeIndex(java.lang.Object node)
|
java.util.Set |
getNodes()
|
Bag |
getOutboundEdges(int fromIndex)
|
Bag |
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. |
int[] |
getToIndices(int fromIndex)
|
java.util.Set |
getToNodes(int fromIndex)
|
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 |
IndexedEdgeIterator |
indexedEdgeIterator()
|
IndexedEdgeNodeIterator |
indexedEdgeNodeIterator()
|
IndexedIterator |
indexedNodeIterator()
|
private int |
indexOfNode(java.lang.Object node)
|
void |
insureCapacity(int capacity)
|
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 |
nodeCapacity()
Returns the maximum capacity for nodes in this IndexedDigraph. |
int |
nodeCount()
|
int[] |
nodeIndices()
Returns an array if ints that show which node indices are being used. |
java.util.Iterator |
nodeIterator()
Implementations should explicitly state how they interpret nodeIterator()'s remove method. |
private void |
putNodeInFirstNull(java.lang.Object node)
|
protected Bag |
removeCEDigraph(CEDigraph digraph)
|
protected java.lang.Object |
removeEdge(int fromIndex,
int toIndex)
|
protected java.lang.Object |
removeEdge(java.lang.Object fromNode,
java.lang.Object toNode)
Return the edge that connected fromNode to toNode, or null if no edge existed. |
private Bag |
removeEdges(CEDigraph digraph)
|
protected Bag |
removeNode(int index)
|
protected Bag |
removeNode(java.lang.Object node)
Return the Set of orphaned edges that are removed with node |
protected Bag |
removeNodes(java.util.Set nodesToRemove)
|
protected Bag |
retainNodes(java.util.Set retainedNodes)
|
boolean |
sameCEDigraphAs(CEDigraph digraph)
Returns true if digraph is the same as this, and all their contents have the same state. |
boolean |
sameStateAs(HasState victim)
If two HasStates have the same internal state, return true. |
protected java.lang.Object |
setNode(int index,
java.lang.Object node)
|
java.lang.String |
toString()
|
CEDigraph |
unionCEDigraph(CEDigraph 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 AbstractMatrixCEDigraph(int nodeCapacity)
protected AbstractMatrixCEDigraph(CEDigraph digraph)
protected AbstractMatrixCEDigraph(UEDigraph digraph)
protected AbstractMatrixCEDigraph(GEDigraph digraph, java.lang.Object edge)
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
containsEdge
in interface Digraph
NodeMissingException
- if either node is missing from the digraph.private void checkEdge(java.lang.Object edge)
public boolean containsEdge(java.lang.Object fromNode, java.lang.Object toNode, java.lang.Object edge) throws NodeMissingException
containsEdge
in interface CEDigraph
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 Bag getInboundEdges(java.lang.Object node) throws NodeMissingException
Inefficient. Iterates through all the edges.
getInboundEdges
in interface CEDigraph
NodeMissingException
- if node is not in the digraph.public Bag getOutboundEdges(java.lang.Object node) throws NodeMissingException
Inefficient. Iterates through all the edges.
getOutboundEdges
in interface CEDigraph
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 CEDigraph
NodeMissingException
- if either node is missing from the digraph.public java.util.Set getFromNodes(java.lang.Object node) throws NodeMissingException
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 CEDigraph
public EdgeNodeIterator edgeNodeIterator()
edgeNodeIterator
in interface Digraph
public java.util.Set getNodes()
getNodes
in interface Digraph
public Bag getEdges()
getEdges
in interface CEDigraph
public boolean isEdgeFree()
isEdgeFree
in interface Digraph
public boolean containsNodes(java.util.Set nodes)
containsNodes
in interface Digraph
public boolean containsCEDigraph(CEDigraph digraph)
containsCEDigraph
in interface CEDigraph
public boolean sameCEDigraphAs(CEDigraph digraph)
sameCEDigraphAs
in interface CEDigraph
public CEDigraph intersectWithCEDigraph(CEDigraph digraph)
intersectWithCEDigraph
in interface CEDigraph
public CEDigraph unionCEDigraph(CEDigraph digraph)
unionCEDigraph
in interface CEDigraph
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 int nodeCapacity()
nodeCapacity
in interface IndexedDigraph
public int[] nodeIndices()
nodeIndices
in interface IndexedDigraph
public boolean containsNode(int index)
containsNode
in interface IndexedDigraph
java.lang.ArrayIndexOutOfBoundsException
- if index does not have a node. Use nodeIndices() or getNodeIndex() to avoid these. In your code, catch ArrayIndexOutOfBoundsException and throw a ConcurrentModificationException if you think that's the problem.public java.lang.Object getNode(int index)
getNode
in interface IndexedDigraph
java.lang.ArrayIndexOutOfBoundsException
- if index does not have a node. Use nodeIndices() or getNodeIndex() to avoid these. In your code, catch ArrayIndexOutOfBoundsException and throw a ConcurrentModificationException if you think that's the problem.public int getNodeIndex(java.lang.Object node) throws NodeMissingException
getNodeIndex
in interface IndexedDigraph
a
- NodeMissingException if the node is not in the digraph.
NodeMissingException
public boolean containsEdge(int fromIndex, int toIndex)
containsEdge
in interface IndexedDigraph
java.lang.ArrayIndexOutOfBoundsException
- if index does not have a node. Use nodeIndices() or getNodeIndex() to avoid these. In your code, catch ArrayIndexOutOfBoundsException and throw a ConcurrentModificationException if you think that's the problem.public int countInboundEdges(int toIndex)
countInboundEdges
in interface IndexedDigraph
java.lang.ArrayIndexOutOfBoundsException
- if index does not have a node. Use nodeIndices() or getNodeIndex() to avoid these. In your code, catch ArrayIndexOutOfBoundsException and throw a ConcurrentModificationException if you think that's the problem.public int countOutboundEdges(int fromIndex)
countOutboundEdges
in interface IndexedDigraph
java.lang.ArrayIndexOutOfBoundsException
- if index does not have a node. Use nodeIndices() or getNodeIndex() to avoid these. In your code, catch ArrayIndexOutOfBoundsException and throw a ConcurrentModificationException if you think that's the problem.public java.util.Set getFromNodes(int toIndex)
getFromNodes
in interface IndexedDigraph
java.lang.ArrayIndexOutOfBoundsException
- if index does not have a node. Use nodeIndices() or getNodeIndex() to avoid these. In your code, catch ArrayIndexOutOfBoundsException and throw a ConcurrentModificationException if you think that's the problem.public int[] getFromIndices(int toIndex)
getFromIndices
in interface IndexedDigraph
public java.util.Set getToNodes(int fromIndex)
getToNodes
in interface IndexedDigraph
java.lang.ArrayIndexOutOfBoundsException
- if index does not have a node. Use nodeIndices() or getNodeIndex() to avoid these. In your code, catch ArrayIndexOutOfBoundsException and throw a ConcurrentModificationException if you think that's the problem.public int[] getToIndices(int fromIndex)
getToIndices
in interface IndexedDigraph
public IndexedEdgeNodeIterator indexedEdgeNodeIterator()
indexedEdgeNodeIterator
in interface IndexedDigraph
public boolean containsEdge(int fromIndex, int toIndex, java.lang.Object edge)
containsEdge
in interface IndexedCEDigraph
java.lang.ArrayIndexOutOfBoundsException
- if index does not have a node. Use nodeIndices() or getNodeIndex() to avoid these. In your code, catch ArrayIndexOutOfBoundsException and throw a ConcurrentModificationException if you think that's the problem.public Bag getInboundEdges(int toIndex)
getInboundEdges
in interface IndexedCEDigraph
java.lang.ArrayIndexOutOfBoundsException
- if index does not have a node. Use nodeIndices() or getNodeIndex() to avoid these. In your code, catch ArrayIndexOutOfBoundsException and throw a ConcurrentModificationException if you think that's the problem.public Bag getOutboundEdges(int fromIndex)
getOutboundEdges
in interface IndexedCEDigraph
java.lang.ArrayIndexOutOfBoundsException
- if index does not have a node. Use nodeIndices() or getNodeIndex() to avoid these. In your code, catch ArrayIndexOutOfBoundsException and throw a ConcurrentModificationException if you think that's the problem.public IndexedEdgeIterator indexedEdgeIterator()
indexedEdgeIterator
in interface IndexedCEDigraph
public IndexedIterator indexedNodeIterator()
indexedNodeIterator
in interface IndexedDigraph
public java.lang.Object getEdge(int fromIndex, int toIndex)
getEdge
in interface IndexedCEDigraph
java.lang.ArrayIndexOutOfBoundsException
- if index does not have a node. Use nodeIndices() or getNodeIndex() to avoid these. In your code, catch ArrayIndexOutOfBoundsException and throw a ConcurrentModificationException if you think that's the problem.protected java.lang.Object setNode(int index, java.lang.Object node)
java.lang.ArrayIndexOutOfBoundsException
- if index does not have a node. Use nodeIndices() or getNodeIndex() to avoid these. In your code, catch ArrayIndexOutOfBoundsException and throw a ConcurrentModificationException if you think that's the problem.protected java.lang.Object addEdge(int fromIndex, int toIndex, java.lang.Object edge)
java.lang.ArrayIndexOutOfBoundsException
- if index does not have a node. Use nodeIndices() or getNodeIndex() to avoid these. In your code, catch ArrayIndexOutOfBoundsException and throw a ConcurrentModificationException if you think that's the problem.protected Bag removeNode(int index)
java.lang.ArrayIndexOutOfBoundsException
- if index does not have a node. Use nodeIndices() or getNodeIndex() to avoid these. In your code, catch ArrayIndexOutOfBoundsException and throw a ConcurrentModificationException if you think that's the problem.protected java.lang.Object removeEdge(int fromIndex, int toIndex)
java.lang.ArrayIndexOutOfBoundsException
- if index does not have a node. Use nodeIndices() or getNodeIndex() to avoid these. In your code, catch ArrayIndexOutOfBoundsException and throw a ConcurrentModificationException if you think that's the problem.protected void growMatrix(int newSize)
public void insureCapacity(int capacity)
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
NodeMissingException
- if either node is not in the digraph.protected Bag removeNode(java.lang.Object node) throws NodeMissingException
NodeMissingException
- if the node is not in the digraphprotected java.lang.Object removeEdge(java.lang.Object fromNode, java.lang.Object toNode) throws NodeMissingException
NodeMissingException
- if either node is not in the digraphprotected boolean addNodes(java.util.Set nodesToAdd)
protected Bag removeNodes(java.util.Set nodesToRemove)
private Bag removeEdges(CEDigraph digraph)
protected Bag removeCEDigraph(CEDigraph digraph)
protected Bag retainNodes(java.util.Set retainedNodes)
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 |