|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--net.walend.digraph.AbstractHashCEDigraph
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 |
AbstractHashCEDigraph.HashEdgeIterator
|
protected class |
AbstractHashCEDigraph.IteratorWrapper
|
protected class |
AbstractHashCEDigraph.NodePair
|
Field Summary | |
private MutableMap |
nodePairsToEdges
|
private MutableSet |
nodes
|
Fields inherited from interface net.walend.digraph.CEDigraph |
EMPTY |
Constructor Summary | |
protected |
AbstractHashCEDigraph(CEDigraph digraph)
|
protected |
AbstractHashCEDigraph(int nodeCapacity,
int edgeCapacity)
|
Method Summary | |
protected java.lang.Object |
addEdge(java.lang.Object fromNode,
java.lang.Object toNode,
java.lang.Object edge)
Return null if fromNode or toNode are not in this CEDigraph, or if no existing edge is displaced by edge. |
protected boolean |
addNode(java.lang.Object node)
|
protected boolean |
addNodes(Set nodesToAdd)
|
protected void |
clear()
|
protected void |
clearEdges()
|
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(Set nodes)
|
int |
countInboundEdges(java.lang.Object node)
Inefficient. |
int |
countOutboundEdges(java.lang.Object node)
Inefficient. |
int |
edgeCount()
|
EdgeIterator |
edgeIterator()
Since HashCEDigraph is immutable, edgeIterator()'s remove() method throws an UnsupportedOperationException. |
java.lang.Object |
getEdge(java.lang.Object fromNode,
java.lang.Object toNode)
Returns null if either node is not in the digraph or if no edge links fromNode to toNode |
Set |
getFromNodes(java.lang.Object node)
Returns the set of nodes that can reach this node by crossing one edge. |
Set |
getInboundEdges(java.lang.Object node)
Returns the empty set if node is not in the digraph, or if node has no inbound edges. |
Set |
getNodes()
|
Set |
getOutboundEdges(java.lang.Object node)
Returns the empty set if node is not in the digraph, or if node has no outbound edges. |
java.lang.Class |
getPrincipleInterface()
Returns the class's principle interface for state comparisons. |
Set |
getToNodes(java.lang.Object node)
Returns the set of nodes that can be reached from this node by crossing one edge. |
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()
|
java.util.Iterator |
nodeIterator()
Since HashCEDigraph is immutable, nodeIterator()'s remove() method throws an UnsupportedOperationException. |
protected Set |
removeCEDigraph(CEDigraph digraph)
|
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 Set |
removeEdges(CEDigraph digraph)
|
protected Set |
removeNode(java.lang.Object node)
Return the Set of orphaned edges that are removed with node |
protected Set |
removeNodes(Set nodesToRemove)
|
protected Set |
retainNodes(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 victem)
If two HasStates have the same internal state, return true. |
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 MutableSet nodes
private MutableMap nodePairsToEdges
Constructor Detail |
protected AbstractHashCEDigraph(int nodeCapacity, int edgeCapacity)
protected AbstractHashCEDigraph(CEDigraph digraph)
Method Detail |
public int nodeCount()
nodeCount
in interface CEDigraph
public int edgeCount()
edgeCount
in interface CEDigraph
public boolean isEmpty()
isEmpty
in interface CEDigraph
public boolean containsNode(java.lang.Object node)
containsNode
in interface CEDigraph
public boolean containsEdge(java.lang.Object fromNode, java.lang.Object toNode) throws NodeMissingException
containsEdge
in interface CEDigraph
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 CEDigraph
NodeMissingException
- if either node is missing from the digraph.public int countInboundEdges(java.lang.Object node) throws NodeMissingException
countInboundEdges
in interface CEDigraph
NodeMissingException
- if node is not in the digraph.public int countOutboundEdges(java.lang.Object node) throws NodeMissingException
countOutboundEdges
in interface CEDigraph
NodeMissingException
- if node is not in the digraph.public Set 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 Set 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 Set getFromNodes(java.lang.Object node) throws NodeMissingException
Inefficient. Iterates through all the edges.
getFromNodes
in interface CEDigraph
NodeMissingException
- if node is not in the digraph.public Set getToNodes(java.lang.Object node) throws NodeMissingException
Inefficient. Iterates through all the edges.
getToNodes
in interface CEDigraph
NodeMissingException
- if node is not in the digraph.public java.util.Iterator nodeIterator()
nodeIterator
in interface CEDigraph
public EdgeIterator edgeIterator()
edgeIterator
in interface CEDigraph
public Set getNodes()
getNodes
in interface CEDigraph
public boolean isEdgeFree()
isEdgeFree
in interface CEDigraph
public boolean containsNodes(Set nodes)
containsNodes
in interface CEDigraph
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 victem)
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 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 Set 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(Set nodesToAdd)
protected Set removeNodes(Set nodesToRemove)
private Set removeEdges(CEDigraph digraph)
protected Set removeCEDigraph(CEDigraph digraph)
protected Set retainNodes(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 All Classes | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |