com.phoenixst.plexus

Class GraphUtils

public class GraphUtils extends Object

This class contains static final members and static methods related to graphs and their iterators.

Since: 1.0

Version: $Revision: 1.78 $

Author: Ray A. Conner

Field Summary
static intANY_DIRECTION_MASK
static PredicateDIRECTED_EDGE_PREDICATE
An Graph.Edge predicate which is true when directed.
static intDIRECTED_IN_MASK
static intDIRECTED_MASK
static intDIRECTED_OUT_MASK
static PredicateDIRECTED_TRAVERSER_PREDICATE
A Traverser predicate which is true when the edge is directed.
static TraverserEMPTY_TRAVERSER
An empty Traverser.
static PredicateIN_TRAVERSER_PREDICATE
A Traverser predicate which is true when the edge is directed in.
static ObservableGraphNULL_GRAPH
An immutable, ObservableGraph with no nodes or edges.
static PredicateOUT_TRAVERSER_PREDICATE
A Traverser predicate which is true when the edge is directed out.
static PredicateSELF_EDGE_PREDICATE
An Graph.Edge predicate which is true when the edge is a self-loop.
static PredicateSELF_TRAVERSER_PREDICATE
A Traverser predicate which is true when the edge is a self-loop.
static PredicateUNDIRECTED_EDGE_PREDICATE
An Graph.Edge predicate which is true when undirected.
static intUNDIRECTED_MASK
static PredicateUNDIRECTED_TRAVERSER_PREDICATE
A Traverser predicate which is true when the edge is undirected.
Method Summary
static voidadd(Graph destination, Graph source)
Adds all the nodes and edges from source to destination.
static StringdirectionFlagsToString(int directionFlags)
Returns a String representation of the specified direction flags.
static booleanequals(Object a, Object b)
Tests two objects for being .equals(), handling null appropriately.
static ObjectgetFirstCommonNode(Transformer incidentEdgeGetter, Object a, Object b)
Helper method primarily for OrientedForest implementations.
static ObjectgetLeastCommonAncestor(OrientedForest forest, Object a, Object b)
Helper method for OrientedForest implementations.
static CharSequencegetTextValue(Graph.Edge edge, boolean includeUserObject)
Returns a CharSequence representing the specified edge.
static intinvertDirection(int directionFlags)
Returns the inverse of the specified direction flags.
static IteratorsingletonEdgeIterator(Graph graph, Graph.Edge edge)
Returns a modifiable Iterator over the specified edge.
static GraphsingletonGraph(Object node)
Returns an unmodifiable, serializable Graph with the single specified node and no edges.
static TraversersingletonTraverser(Graph graph, Object endpoint, Graph.Edge edge)
Returns a modifiable Traverser over the specified edge.
static ObservableGraphsynchronizedGraph(Graph graph)
Returns a synchronized view of the specified Graph.
static ObservableGraphunmodifiableGraph(Graph graph)
Returns an unmodifiable view of the specified Graph.
static IteratorunmodifiableIterator(Iterator iterator)
Returns an unmodifiable view of the specified Iterator.
static TraverserunmodifiableTraverser(Traverser traverser)
Returns an unmodifiable view of the specified Traverser.

Field Detail

ANY_DIRECTION_MASK

public static final int ANY_DIRECTION_MASK

DIRECTED_EDGE_PREDICATE

public static final Predicate DIRECTED_EDGE_PREDICATE
An Graph.Edge predicate which is true when directed.

DIRECTED_IN_MASK

public static final int DIRECTED_IN_MASK

DIRECTED_MASK

public static final int DIRECTED_MASK

DIRECTED_OUT_MASK

public static final int DIRECTED_OUT_MASK

DIRECTED_TRAVERSER_PREDICATE

public static final Predicate DIRECTED_TRAVERSER_PREDICATE
A Traverser predicate which is true when the edge is directed.

EMPTY_TRAVERSER

public static final Traverser EMPTY_TRAVERSER
An empty Traverser.

IN_TRAVERSER_PREDICATE

public static final Predicate IN_TRAVERSER_PREDICATE
A Traverser predicate which is true when the edge is directed in.

NULL_GRAPH

public static final ObservableGraph NULL_GRAPH
An immutable, ObservableGraph with no nodes or edges.

OUT_TRAVERSER_PREDICATE

public static final Predicate OUT_TRAVERSER_PREDICATE
A Traverser predicate which is true when the edge is directed out.

SELF_EDGE_PREDICATE

public static final Predicate SELF_EDGE_PREDICATE
An Graph.Edge predicate which is true when the edge is a self-loop.

SELF_TRAVERSER_PREDICATE

public static final Predicate SELF_TRAVERSER_PREDICATE
A Traverser predicate which is true when the edge is a self-loop.

UNDIRECTED_EDGE_PREDICATE

public static final Predicate UNDIRECTED_EDGE_PREDICATE
An Graph.Edge predicate which is true when undirected.

UNDIRECTED_MASK

public static final int UNDIRECTED_MASK

UNDIRECTED_TRAVERSER_PREDICATE

public static final Predicate UNDIRECTED_TRAVERSER_PREDICATE
A Traverser predicate which is true when the edge is undirected.

Method Detail

add

public static void add(Graph destination, Graph source)
Adds all the nodes and edges from source to destination. If the two Graphs are incompatible in some way (nodes and/or edges from from the source graph not allowed in the destination), then a best effort is still made.

directionFlagsToString

public static final String directionFlagsToString(int directionFlags)
Returns a String representation of the specified direction flags.

equals

public static final boolean equals(Object a, Object b)
Tests two objects for being .equals(), handling null appropriately.

getFirstCommonNode

public static Object getFirstCommonNode(Transformer incidentEdgeGetter, Object a, Object b)
Helper method primarily for OrientedForest implementations. This method will repeatedly apply the Transformer to each node argument until it returns null, so the traversal should terminate.

getLeastCommonAncestor

public static Object getLeastCommonAncestor(OrientedForest forest, Object a, Object b)
Helper method for OrientedForest implementations.

getTextValue

public static CharSequence getTextValue(Graph.Edge edge, boolean includeUserObject)
Returns a CharSequence representing the specified edge.

invertDirection

public static final int invertDirection(int directionFlags)
Returns the inverse of the specified direction flags.

singletonEdgeIterator

public static Iterator singletonEdgeIterator(Graph graph, Graph.Edge edge)
Returns a modifiable Iterator over the specified edge.

Parameters: graph the graph containing the edge over which the returned Iterator iterates. edge the edge over which the returned Iterator iterates.

Returns: a modifiable Iterator over the specified edge.

singletonGraph

public static Graph singletonGraph(Object node)
Returns an unmodifiable, serializable Graph with the single specified node and no edges.

Parameters: node the node which the returned Graph is to contain.

Returns: an unmodifiable, serializable Graph with the single specified node and no edges.

singletonTraverser

public static Traverser singletonTraverser(Graph graph, Object endpoint, Graph.Edge edge)
Returns a modifiable Traverser over the specified edge.

Parameters: graph the graph containing the edge over which the returned Traverser iterates. endpoint the endpoint of the edge over which the returned Traverser iterates. edge the edge over which the returned Traverser iterates.

Returns: a modifiable Traverser over the specified edge.

synchronizedGraph

public static ObservableGraph synchronizedGraph(Graph graph)
Returns a synchronized view of the specified Graph. It is the user's responsibility to manually synchronize on the returned Graph when iterating over it. If the specified Graph does not implement ObservableGraph, then ObservableGraph and ObservableGraph with throw UnsupportedOperationExceptions. The returned Graph will be serializable if the specified Graph is serializable.

Parameters: graph the Graph for which a synchronized view is to be returned.

Returns: a synchronized view of the specified Graph.

unmodifiableGraph

public static ObservableGraph unmodifiableGraph(Graph graph)
Returns an unmodifiable view of the specified Graph. If the specified Graph does not implement ObservableGraph, then ObservableGraph and ObservableGraph with throw UnsupportedOperationExceptions. The returned Graph will be serializable if the specified Graph is serializable.

Parameters: graph the Graph for which an unmodifiable view is to be returned.

Returns: an unmodifiable view of the specified Graph.

unmodifiableIterator

public static Iterator unmodifiableIterator(Iterator iterator)
Returns an unmodifiable view of the specified Iterator.

Parameters: iterator the Iterator for which an unmodifiable view is to be returned.

Returns: an unmodifiable view of the specified Iterator.

unmodifiableTraverser

public static Traverser unmodifiableTraverser(Traverser traverser)
Returns an unmodifiable view of the specified Traverser.

Parameters: traverser the Traverser for which an unmodifiable view is to be returned.

Returns: an unmodifiable view of the specified Traverser.

See the Plexus project home, hosted by SourceForge.
Copyright B) 1994-2006, by Phoenix Software Technologists, Inc. and others. All Rights Reserved. Use is subject to license terms.