Plexus v0.13.1

com.phoenixst.plexus
Class GraphUtils

java.lang.Object
  extended by com.phoenixst.plexus.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 int ANY_DIRECTION_MASK
           
static org.apache.commons.collections.Predicate DIRECTED_EDGE_PREDICATE
          An Graph.Edge predicate which is true when directed.
static int DIRECTED_IN_MASK
           
static int DIRECTED_MASK
           
static int DIRECTED_OUT_MASK
           
static org.apache.commons.collections.Predicate DIRECTED_TRAVERSER_PREDICATE
          A Traverser predicate which is true when the edge is directed.
static Traverser EMPTY_TRAVERSER
          An empty Traverser.
static org.apache.commons.collections.Predicate IN_TRAVERSER_PREDICATE
          A Traverser predicate which is true when the edge is directed in.
static ObservableGraph NULL_GRAPH
          An immutable, ObservableGraph with no nodes or edges.
static org.apache.commons.collections.Predicate OUT_TRAVERSER_PREDICATE
          A Traverser predicate which is true when the edge is directed out.
static org.apache.commons.collections.Predicate SELF_EDGE_PREDICATE
          An Graph.Edge predicate which is true when the edge is a self-loop.
static org.apache.commons.collections.Predicate SELF_TRAVERSER_PREDICATE
          A Traverser predicate which is true when the edge is a self-loop.
static org.apache.commons.collections.Predicate UNDIRECTED_EDGE_PREDICATE
          An Graph.Edge predicate which is true when undirected.
static int UNDIRECTED_MASK
           
static org.apache.commons.collections.Predicate UNDIRECTED_TRAVERSER_PREDICATE
          A Traverser predicate which is true when the edge is undirected.
 
Method Summary
static void add(Graph destination, Graph source)
          Adds all the nodes and edges from source to destination.
static String directionFlagsToString(int directionFlags)
          Returns a String representation of the specified direction flags.
static boolean equals(Object a, Object b)
          Tests two objects for being .equals(), handling null appropriately.
static Object getFirstCommonNode(org.apache.commons.collections.Transformer incidentEdgeGetter, Object a, Object b)
          Helper method primarily for OrientedForest implementations.
static Object getLeastCommonAncestor(OrientedForest forest, Object a, Object b)
          Helper method for OrientedForest implementations.
static CharSequence getTextValue(Graph.Edge edge, boolean includeUserObject)
          Returns a CharSequence representing the specified edge.
static int invertDirection(int directionFlags)
          Returns the inverse of the specified direction flags.
static Iterator singletonEdgeIterator(Graph graph, Graph.Edge edge)
          Returns a modifiable Iterator over the specified edge.
static Graph singletonGraph(Object node)
          Returns an unmodifiable, serializable Graph with the single specified node and no edges.
static Traverser singletonTraverser(Graph graph, Object endpoint, Graph.Edge edge)
          Returns a modifiable Traverser over the specified edge.
static ObservableGraph synchronizedGraph(Graph graph)
          Returns a synchronized view of the specified Graph.
static ObservableGraph unmodifiableGraph(Graph graph)
          Returns an unmodifiable view of the specified Graph.
static Iterator unmodifiableIterator(Iterator iterator)
          Returns an unmodifiable view of the specified Iterator.
static Traverser unmodifiableTraverser(Traverser traverser)
          Returns an unmodifiable view of the specified Traverser.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNDIRECTED_MASK

public static final int UNDIRECTED_MASK
See Also:
Constant Field Values

DIRECTED_OUT_MASK

public static final int DIRECTED_OUT_MASK
See Also:
Constant Field Values

DIRECTED_IN_MASK

public static final int DIRECTED_IN_MASK
See Also:
Constant Field Values

DIRECTED_MASK

public static final int DIRECTED_MASK
See Also:
Constant Field Values

ANY_DIRECTION_MASK

public static final int ANY_DIRECTION_MASK
See Also:
Constant Field Values

EMPTY_TRAVERSER

public static final Traverser EMPTY_TRAVERSER
An empty Traverser.


NULL_GRAPH

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


DIRECTED_EDGE_PREDICATE

public static final org.apache.commons.collections.Predicate DIRECTED_EDGE_PREDICATE
An Graph.Edge predicate which is true when directed.


UNDIRECTED_EDGE_PREDICATE

public static final org.apache.commons.collections.Predicate UNDIRECTED_EDGE_PREDICATE
An Graph.Edge predicate which is true when undirected.


SELF_EDGE_PREDICATE

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


OUT_TRAVERSER_PREDICATE

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


IN_TRAVERSER_PREDICATE

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


DIRECTED_TRAVERSER_PREDICATE

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


UNDIRECTED_TRAVERSER_PREDICATE

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


SELF_TRAVERSER_PREDICATE

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

Method Detail

invertDirection

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


directionFlagsToString

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


getTextValue

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


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.


equals

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


getLeastCommonAncestor

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


getFirstCommonNode

public static Object getFirstCommonNode(org.apache.commons.collections.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.


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.

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.

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.

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.

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.addGraphListener(com.phoenixst.plexus.GraphListener) and ObservableGraph.removeGraphListener(com.phoenixst.plexus.GraphListener) 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.

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.addGraphListener(com.phoenixst.plexus.GraphListener) and ObservableGraph.removeGraphListener(com.phoenixst.plexus.GraphListener) 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.

Plexus v0.13.1

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