|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Object | +--net.walend.digraph.AbstractHashGEDigraph
This abstract class implements the GEDigraph interface using two HashSets. It's great for sparse graphs. Subclass it as is for an immutable GEDigraph. Mix in the MutableGEDigraph interface for one you can change.
| Nested Class Summary | |
protected class |
AbstractHashGEDigraph.HashEdgeIterator
|
class |
AbstractHashGEDigraph.NodeIterator
|
protected class |
AbstractHashGEDigraph.NodePair
|
| Field Summary | |
private java.util.Set |
edges
|
private java.util.Set |
nodes
|
| Fields inherited from interface net.walend.digraph.GEDigraph |
EMPTY |
| Constructor Summary | |
protected |
AbstractHashGEDigraph(CEDigraph digraph)
|
protected |
AbstractHashGEDigraph(GEDigraph digraph)
|
protected |
AbstractHashGEDigraph(int nodeCapacity,
int edgeCapacity)
|
protected |
AbstractHashGEDigraph(UEDigraph digraph)
|
| Method Summary | |
protected boolean |
addEdge(java.lang.Object fromNode,
java.lang.Object toNode)
Return true if the digraph changes when this edge is added, false if the digraph is unchanged. |
protected boolean |
addNode(java.lang.Object node)
Return true if the node is added successfully, false if the digraph does not change. |
protected boolean |
addNodes(java.util.Set nodesToAdd)
Return true if adding the nodes changes the digraph. |
protected void |
clear()
|
protected void |
clearEdges()
|
boolean |
containsEdge(java.lang.Object fromNode,
java.lang.Object toNode)
Returns true if the digraph contains any edge from fromNode to toNode |
boolean |
containsGEDigraph(GEDigraph digraph)
Returns true if digraph is a subgraph of this GEDigraph. |
boolean |
containsNode(java.lang.Object node)
|
boolean |
containsNodes(java.util.Set nodes)
|
int |
countInboundEdges(java.lang.Object node)
Inefficient. |
int |
countOutboundEdges(java.lang.Object node)
Inefficient. |
int |
edgeCount()
|
EdgeNodeIterator |
edgeNodeIterator()
Returns an iterator that iterates across pairs of nodes that make edges. |
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 |
getNodes()
|
java.lang.Class |
getPrincipleInterface()
Returns the class's principle interface for state comparisons. |
java.util.Set |
getToNodes(java.lang.Object node)
Returns the set of nodes that can be reached from this node by crossing one edge. |
GEDigraph |
intersectWithGEDigraph(GEDigraph digraph)
Returns a new digraph that is the intersection of this with digraph. |
boolean |
isEdgeFree()
Returns true if this GEDigraph has no edges. |
boolean |
isEmpty()
|
int |
nodeCount()
|
java.util.Iterator |
nodeIterator()
Implementations should explicitly state how they interpret nodeIterator()'s remove method. |
protected boolean |
removeEdge(java.lang.Object fromNode,
java.lang.Object toNode)
Return true if the digraph changes when the edge is removed, false if the digraph didn't have an edge between these two nodes. |
private boolean |
removeEdges(GEDigraph digraph)
|
protected int |
removeGEDigraph(GEDigraph digraph)
Return the number of edges orphaned when digraph is removed |
protected int |
removeNode(java.lang.Object node)
Return the number of orphaned edges that were lost when this node is removed. |
protected int |
removeNodes(java.util.Set nodesToRemove)
Return the number of edges orphaned edges when these nodes are removed. |
protected int |
retainNodes(java.util.Set retainedNodes)
Return the number of orphaned edges when the nodes are removed. |
boolean |
sameGEDigraphAs(GEDigraph 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. |
java.lang.String |
toString()
|
GEDigraph |
unionGEDigraph(GEDigraph 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.Set nodes
private java.util.Set edges
| Constructor Detail |
protected AbstractHashGEDigraph(int nodeCapacity,
int edgeCapacity)
protected AbstractHashGEDigraph(GEDigraph digraph)
protected AbstractHashGEDigraph(CEDigraph digraph)
protected AbstractHashGEDigraph(UEDigraph digraph)
| Method Detail |
public int nodeCount()
nodeCount in interface Digraphpublic int edgeCount()
edgeCount in interface Digraphpublic boolean isEmpty()
isEmpty in interface Digraphpublic boolean containsNode(java.lang.Object node)
containsNode in interface Digraph
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 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 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 EdgeNodeIterator edgeNodeIterator()
edgeNodeIterator in interface Digraphpublic java.util.Set getNodes()
getNodes in interface Digraphpublic boolean isEdgeFree()
isEdgeFree in interface Digraphpublic boolean containsNodes(java.util.Set nodes)
containsNodes in interface Digraphpublic boolean containsGEDigraph(GEDigraph digraph)
containsGEDigraph in interface GEDigraphpublic boolean sameGEDigraphAs(GEDigraph digraph)
sameGEDigraphAs in interface GEDigraphpublic GEDigraph intersectWithGEDigraph(GEDigraph digraph)
intersectWithGEDigraph in interface GEDigraphpublic GEDigraph unionGEDigraph(GEDigraph digraph)
unionGEDigraph in interface GEDigraphpublic 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 boolean addNode(java.lang.Object node)
protected boolean addEdge(java.lang.Object fromNode,
java.lang.Object toNode)
throws NodeMissingException
NodeMissingException - if either node is not in the digraph.
protected int removeNode(java.lang.Object node)
throws NodeMissingException
NodeMissingException - if the node is not in the digraph
protected boolean 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 int removeNodes(java.util.Set nodesToRemove)
private boolean removeEdges(GEDigraph digraph)
protected int removeGEDigraph(GEDigraph digraph)
protected int 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 | ||||||||||