com.phoenixst.plexus
public abstract class AbstractGraph extends Object implements Graph
Graph
interface, to minimize the effort required to
implement this interface. Any concrete extension of this class
must override the following methods to provide a full
implemnetation:
Alternately, an extension may override one or more of the following methods (which normally defer to those listed above) if doing so admits a more efficient solution. In this case, the above methods should probably still be implemented correctly.
Any modifiable concrete extensions of this class must also implement:
addNode( node )
addEdge( object, tail, head, isDirected )
The documentation for each non-abstract method in this class describes its implementation in detail. Each of these methods may be overridden if the graph being implemented admits a more efficient implementation. Note that almost every method implementation here is written in terms of an iterator over the structure of this graph; these methods are all rather inefficient.
The programmer should generally provide a void (no argument) and
Graph
constructor, as per the recommendation in the
Graph
interface specification.
Since: 1.0
Version: $Revision: 1.59 $
Constructor Summary | |
---|---|
protected | AbstractGraph()
Protected constructor, called implicitly by subclasses. |
Method Summary | |
---|---|
Graph.Edge | addEdge(Object object, Object tail, Object head, boolean isDirected)
This implementation throws an
UnsupportedOperationException . |
boolean | addNode(Object node)
This implementation throws an
UnsupportedOperationException . |
Collection | adjacentNodes(Object node, Predicate traverserPredicate)
This implementation returns a new AdjacentNodeCollection. |
boolean | containsEdge(Graph.Edge edge)
This implementation traverses over the edges in this graph
incident on the tail of the specified edge ,
looking for it and returning true if found. |
boolean | containsNode(Object node)
This implementation iterates over the nodes in this graph
looking for the specified element. |
int | degree(Object node)
This implementation counts the number of elements accessed by
this graph's traverser(
node, null ) method, counting self-loops twice. |
int | degree(Object node, Predicate traverserPredicate)
This implementation counts the number of elements accessed by
this graph's traverser(
node, traverserPredicate ) method, without counting
self-loops twice. |
protected abstract Collection | edges()
Returns a Collection view of all the
Graph.Edges in this Graph .
|
Collection | edges(Predicate edgePredicate)
This implementation delegates to edges() ,
except for when the specified edgePredicate is
either INSTANCE or an instance of
EqualPredicate. |
Object | getAdjacentNode(Object node, Predicate traverserPredicate)
This implementation returns the other endpoint of the
Edge returned by getIncidentEdge if present, otherwise it
returns null . |
Graph.Edge | getEdge(Predicate edgePredicate) |
Graph.Edge | getIncidentEdge(Object node, Predicate traverserPredicate)
This implementation returns the first Edge
accessed by incidentEdges if
present, otherwise it returns null . |
Object | getNode(Predicate nodePredicate)
This implementation returns the first node accessed by nodes if present, otherwise it returns
null . |
Collection | incidentEdges(Object node, Predicate traverserPredicate)
This implementation returns a new IncidentEdgeCollection. |
protected abstract Collection | nodes()
Returns a Collection view of all the nodes
in this Graph . |
Collection | nodes(Predicate nodePredicate)
This implementation delegates to nodes() ,
except for when the specified nodePredicate is
either INSTANCE or an instance of
EqualPredicate. |
boolean | removeEdge(Graph.Edge edge)
This implementation traverses over the edges in this graph
incident on the tail of the specified edge . |
boolean | removeNode(Object node)
This implementation iterates over the nodes in this graph
looking for the specified element. |
protected abstract Traverser | traverser(Object node)
Returns an unfiltered Traverser over those
Graph.Edges incident to the specified node.
|
Traverser | traverser(Object node, Predicate traverserPredicate)
This implementation delegates to
traverser( node ) , except for when the specified
traverserPredicate is either INSTANCE or an instance of EqualsTraverserPredicate. |
UnsupportedOperationException
.UnsupportedOperationException
.edge
,
looking for it and returning true
if found. traverser(
node, null )
method, counting self-loops twice. traverser(
node, traverserPredicate )
method, without counting
self-loops twice.Collection
view of all the
Graph.Edges
in this Graph
.
This method is only called by
edges( Predicate )
. edges()
,
except for when the specified edgePredicate
is
either INSTANCE or an instance of
EqualPredicate. These two cases are optimized.Edge
returned by getIncidentEdge if present, otherwise it
returns null
.Edge
accessed by incidentEdges if
present, otherwise it returns null
.null
.Collection
view of all the nodes
in this Graph
. This method is only called
by nodes( Predicate )
. nodes()
,
except for when the specified nodePredicate
is
either INSTANCE or an instance of
EqualPredicate. These two cases are optimized.edge
. If
it finds the element, it removes the element using using the
Traverser operation.
Note that this implementation will throw an
UnsupportedOperationException
if the traverser
returned by this graph's
traverser( node, predicate )
method does not implement the
removeEdge
method and this graph contains the
specified edge.
Note that this implementation will throw an
UnsupportedOperationException
if the iterator
returned by this graph's nodes( null ).iterator()
method does not implement the remove
method and
this graph contains the specified node.
Traverser
over those
Graph.Edges
incident to the specified node.
This method is only called by traverser( node, Predicate )
.
traverser( node )
, except for when the specified
traverserPredicate
is either INSTANCE or an instance of EqualsTraverserPredicate. These two cases are optimized.