net.walend.digraph
Interface UEDigraph

All Superinterfaces:
HasState
All Known Subinterfaces:
MutableUEDigraph
All Known Implementing Classes:
AbstractHashUEDigraph, MutableHashUEDigraph

public interface UEDigraph
extends HasState

UEDigraph is an interface for representing directed graphs of nodes linked by zero or one edge. Each node and edge must be a unique Object in the digraph. Reusing edges and nodes may produce unpredictable results.

By default, this digraph uses equals() as the method to determine identity. Persistent versions may use hasSameIdentity() instead, for example.

One could create a subclass of UEDigraph that will work with zero or more edges by extending this interface. I have not done that.

Direct implementations of UEDigraph should have a single constructor that takes a UEDigraph as a parameter. Some implementations should provide a view of this UEDigraph, by implementing the net.walend.collection.View interface. Others should copy the parameter to produced an immutable UEDigraph.

Since:
20010612
Author:
David Walend

Field Summary
static UEDigraph EMPTY
           
 
Method Summary
 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(Set edges)
           
 boolean containsNode(java.lang.Object node)
           
 boolean containsNodes(Set nodes)
           
 boolean containsUEDigraph(UEDigraph digraph)
          Returns true if digraph is a subgraph of this UEDigraph.
 int countInboundEdges(java.lang.Object node)
           
 int countOutboundEdges(java.lang.Object node)
           
 int edgeCount()
           
 EdgeIterator edgeIterator()
           
 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 getEdges()
           
 java.lang.Object getFromNode(java.lang.Object edge)
           
 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.Object getToNode(java.lang.Object edge)
           
 Set getToNodes(java.lang.Object node)
          Returns the set of nodes that can be reached from this node by crossing one edge.
 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.
 boolean sameUEDigraphAs(UEDigraph digraph)
          Returns true if digraph is the same as this; that is, if this.containsUEDigraph(digraph) and digraph.containsUEDigraph(this).
 UEDigraph unionUEDigraph(UEDigraph digraph)
          Returns a new digraph that is the union of this with digraph.
 
Methods inherited from interface net.walend.collection.HasState
getPrincipleInterface, sameStateAs
 

Field Detail

EMPTY

public static final UEDigraph EMPTY
Method Detail

nodeCount

public int nodeCount()

edgeCount

public int edgeCount()

isEmpty

public boolean isEmpty()

containsNode

public boolean containsNode(java.lang.Object node)

containsEdge

public boolean containsEdge(java.lang.Object fromNode,
                            java.lang.Object toNode)
                     throws NodeMissingException
Returns true if the digraph contains any edge from fromNode to toNode

Throws:
NodeMissingException - if either node is missing from the digraph.

containsEdge

public boolean containsEdge(java.lang.Object fromNode,
                            java.lang.Object toNode,
                            java.lang.Object edge)
                     throws NodeMissingException
Returns true if edge links fromNode to toNode

Throws:
NodeMissingException - if either node is missing from the digraph.

containsEdge

public boolean containsEdge(java.lang.Object edge)
Returns true if edge exists in the digraph anywhere


countInboundEdges

public int countInboundEdges(java.lang.Object node)
                      throws NodeMissingException
Throws:
NodeMissingException - if node is not in the digraph.

countOutboundEdges

public int countOutboundEdges(java.lang.Object node)
                       throws NodeMissingException
Throws:
NodeMissingException - if node is not in the digraph.

getInboundEdges

public Set getInboundEdges(java.lang.Object node)
                    throws NodeMissingException
Returns the empty set if node is not in the digraph, or if node has no inbound edges.

Throws:
NodeMissingException - if node is not in the digraph.

getOutboundEdges

public Set getOutboundEdges(java.lang.Object node)
                     throws NodeMissingException
Returns the empty set if node is not in the digraph, or if node has no outbound edges.

Throws:
NodeMissingException - if node is not in the digraph.

getFromNode

public java.lang.Object getFromNode(java.lang.Object edge)
                             throws EdgeMissingException
Throws:
EdgeMissingException - if the edge is not in the digraph.

getToNode

public java.lang.Object getToNode(java.lang.Object edge)
                           throws EdgeMissingException
Throws:
EdgeMissingException - if the edge is not in the digraph.

getEdge

public java.lang.Object getEdge(java.lang.Object fromNode,
                                java.lang.Object toNode)
                         throws NodeMissingException
Returns null if either node is not in the digraph or if no edge links fromNode to toNode

Throws:
NodeMissingException - if either node is missing from the digraph.

getFromNodes

public Set getFromNodes(java.lang.Object node)
                 throws NodeMissingException
Returns the set of nodes that can reach this node by crossing one edge.

Throws:
NodeMissingException - if node is not in the digraph.

getToNodes

public Set getToNodes(java.lang.Object node)
               throws NodeMissingException
Returns the set of nodes that can be reached from this node by crossing one edge.

Throws:
NodeMissingException - if node is not in the digraph.

nodeIterator

public java.util.Iterator nodeIterator()
Implementations should explicitly state how they interpret nodeIterator()'s remove method. It should either throw an UnsupportedOperationException or cause a hidden side effect of removing edges.


edgeIterator

public EdgeIterator edgeIterator()

getNodes

public Set getNodes()

getEdges

public Set getEdges()

isEdgeFree

public boolean isEdgeFree()
Returns true if this UEDigraph has no edges.


containsNodes

public boolean containsNodes(Set nodes)

containsEdges

public boolean containsEdges(Set edges)

containsUEDigraph

public boolean containsUEDigraph(UEDigraph digraph)
Returns true if digraph is a subgraph of this UEDigraph.


sameUEDigraphAs

public boolean sameUEDigraphAs(UEDigraph digraph)
Returns true if digraph is the same as this; that is, if this.containsUEDigraph(digraph) and digraph.containsUEDigraph(this).


intersectWithUEDigraph

public UEDigraph intersectWithUEDigraph(UEDigraph digraph)
Returns a new digraph that is the intersection of this with digraph. Implementations should generally return the same implementation of UEDigraph as they have themselves.


unionUEDigraph

public UEDigraph unionUEDigraph(UEDigraph digraph)
Returns a new digraph that is the union of this with digraph. Implementations should generally return the same implementation of UEDigraph as they are themselves. If the digraphs contain conflicting edges, then (unless you have a better rule) let digraph's edge win out.



Copyright (c) 2000, 2001, David Walend