org.progeeks.graph
Class CompositeGraph

java.lang.Object
  extended by com.phoenixst.plexus.AbstractGraph
      extended by org.progeeks.graph.CompositeGraph
All Implemented Interfaces:
com.phoenixst.plexus.Graph, com.phoenixst.plexus.ObservableGraph

public class CompositeGraph
extends com.phoenixst.plexus.AbstractGraph
implements com.phoenixst.plexus.ObservableGraph

Graph implementation that contains other graphs and links them together as one large unified graph. Facilities are built in that allow filters to be targetted to certain sub-graphs. Note: all node iteration and other access methods may return duplicate nodes since they don't correlate the different graphs during this process. It was thought that raw speed and memory reduction is better then perfect accuracy in this case.

Version:
$Revision: 1.49 $
Author:
Paul Speed

Nested Class Summary
static class CompositeGraph.GraphCoordinator
          A coordinator can be associated with a subgraph to provide information about the types of filters that will return results and the types of nodes and edges that the graph accepts.
 
Nested classes/interfaces inherited from interface com.phoenixst.plexus.Graph
com.phoenixst.plexus.Graph.Edge
 
Constructor Summary
  CompositeGraph()
          Creates a new CompositeGraph using an empty EdgeIdentityGraph as its root.
protected CompositeGraph(com.phoenixst.plexus.Graph root)
          Constructor that can be used by subclasses to customize the root graph implementation.
 
Method Summary
 com.phoenixst.plexus.Graph.Edge addEdge(java.lang.Object object, java.lang.Object tail, java.lang.Object head, boolean isDirected)
           
 void addGraph(com.phoenixst.plexus.Graph graph)
           
 void addGraph(com.phoenixst.plexus.Graph graph, CompositeGraph.GraphCoordinator coordinator)
           
 void addGraphListener(com.phoenixst.plexus.GraphListener listener)
          Adds the specified GraphListener which will be notified whenever this ObservableGraph's structure changes.
 boolean addNode(java.lang.Object node)
           
 java.util.Collection adjacentNodes(java.lang.Object node, org.apache.commons.collections.Predicate traverserPredicate)
           
 boolean containsEdge(com.phoenixst.plexus.Graph.Edge edge)
           
 boolean containsNode(java.lang.Object node)
           
protected  boolean containsNode(java.lang.Object node, com.phoenixst.plexus.Graph skipGraph)
          Returns true if a sub-graph contains the specified node other than the graph specified.
 int degree(java.lang.Object node)
           
 int degree(java.lang.Object node, org.apache.commons.collections.Predicate traverserPredicate)
           
protected  java.util.Collection edges()
           
 java.util.Collection edges(org.apache.commons.collections.Predicate edgePredicate)
           
 java.lang.Object getAdjacentNode(java.lang.Object node, org.apache.commons.collections.Predicate traverserPredicate)
           
 com.phoenixst.plexus.Graph.Edge getEdge(org.apache.commons.collections.Predicate edgePredicate)
           
protected  org.progeeks.graph.CompositeGraph.GraphEntry getFirstEntryForNode(java.lang.Object node)
          Returns the first non-root entry that contains the node.
protected  com.phoenixst.plexus.Graph getGraphForEdge(java.lang.Object object, java.lang.Object tail, java.lang.Object head, boolean isDirected)
          Searches for an entry that is appropriate for an edge connecting both of the specified nodes.
 com.phoenixst.plexus.Graph.Edge getIncidentEdge(java.lang.Object node, org.apache.commons.collections.Predicate traverserPredicate)
           
 java.lang.Object getNode(org.apache.commons.collections.Predicate nodePredicate)
          Returns a node from this graph that matches the specified filter.
 java.util.Collection incidentEdges(java.lang.Object node, org.apache.commons.collections.Predicate traverserPredicate)
           
protected  java.util.Collection nodes()
           
 java.util.Collection nodes(org.apache.commons.collections.Predicate nodePredicate)
           
 boolean removeEdge(com.phoenixst.plexus.Graph.Edge edge)
           
 void removeGraphListener(com.phoenixst.plexus.GraphListener listener)
          Removes a previously added GraphListener.
 boolean removeNode(java.lang.Object node)
           
 java.lang.String toString()
           
protected  com.phoenixst.plexus.Traverser traverser(java.lang.Object node)
           
 com.phoenixst.plexus.Traverser traverser(java.lang.Object node, org.apache.commons.collections.Predicate traverserPredicate)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CompositeGraph

public CompositeGraph()
Creates a new CompositeGraph using an empty EdgeIdentityGraph as its root.


CompositeGraph

protected CompositeGraph(com.phoenixst.plexus.Graph root)
Constructor that can be used by subclasses to customize the root graph implementation.

Method Detail

getFirstEntryForNode

protected org.progeeks.graph.CompositeGraph.GraphEntry getFirstEntryForNode(java.lang.Object node)
Returns the first non-root entry that contains the node.


addGraph

public final void addGraph(com.phoenixst.plexus.Graph graph)

addGraph

public final void addGraph(com.phoenixst.plexus.Graph graph,
                           CompositeGraph.GraphCoordinator coordinator)

nodes

protected java.util.Collection nodes()
Specified by:
nodes in class com.phoenixst.plexus.AbstractGraph

edges

protected java.util.Collection edges()
Specified by:
edges in class com.phoenixst.plexus.AbstractGraph

traverser

protected com.phoenixst.plexus.Traverser traverser(java.lang.Object node)
Specified by:
traverser in class com.phoenixst.plexus.AbstractGraph

addNode

public boolean addNode(java.lang.Object node)
Specified by:
addNode in interface com.phoenixst.plexus.Graph
Overrides:
addNode in class com.phoenixst.plexus.AbstractGraph

removeNode

public boolean removeNode(java.lang.Object node)
Specified by:
removeNode in interface com.phoenixst.plexus.Graph
Overrides:
removeNode in class com.phoenixst.plexus.AbstractGraph

containsNode

public boolean containsNode(java.lang.Object node)
Specified by:
containsNode in interface com.phoenixst.plexus.Graph
Overrides:
containsNode in class com.phoenixst.plexus.AbstractGraph

containsNode

protected boolean containsNode(java.lang.Object node,
                               com.phoenixst.plexus.Graph skipGraph)
Returns true if a sub-graph contains the specified node other than the graph specified.


getGraphForEdge

protected com.phoenixst.plexus.Graph getGraphForEdge(java.lang.Object object,
                                                     java.lang.Object tail,
                                                     java.lang.Object head,
                                                     boolean isDirected)
Searches for an entry that is appropriate for an edge connecting both of the specified nodes. This implementation looks at every graph coordinator to see if the following conditions apply: 1) Is the edge allowed 2) Does the graph contain both nodes 3) Does the graph contain one node Any of those conditions being true makes the graph a candidate. If (1) and (2) are both true then the graph is returned without further search. Otherwise, all graphs are searched. When the searching is done, if there was a graph that had one of the endpoints and can take the edge then it is returned. Otherwise, if there is a graph that could take the edge, it is returned. If no suitable graphs were found then the root graph is returned.


addEdge

public com.phoenixst.plexus.Graph.Edge addEdge(java.lang.Object object,
                                               java.lang.Object tail,
                                               java.lang.Object head,
                                               boolean isDirected)
Specified by:
addEdge in interface com.phoenixst.plexus.Graph
Overrides:
addEdge in class com.phoenixst.plexus.AbstractGraph

removeEdge

public boolean removeEdge(com.phoenixst.plexus.Graph.Edge edge)
Specified by:
removeEdge in interface com.phoenixst.plexus.Graph
Overrides:
removeEdge in class com.phoenixst.plexus.AbstractGraph

containsEdge

public boolean containsEdge(com.phoenixst.plexus.Graph.Edge edge)
Specified by:
containsEdge in interface com.phoenixst.plexus.Graph
Overrides:
containsEdge in class com.phoenixst.plexus.AbstractGraph

degree

public int degree(java.lang.Object node)
Specified by:
degree in interface com.phoenixst.plexus.Graph
Overrides:
degree in class com.phoenixst.plexus.AbstractGraph

degree

public int degree(java.lang.Object node,
                  org.apache.commons.collections.Predicate traverserPredicate)
Specified by:
degree in interface com.phoenixst.plexus.Graph
Overrides:
degree in class com.phoenixst.plexus.AbstractGraph

nodes

public java.util.Collection nodes(org.apache.commons.collections.Predicate nodePredicate)
Specified by:
nodes in interface com.phoenixst.plexus.Graph
Overrides:
nodes in class com.phoenixst.plexus.AbstractGraph

edges

public java.util.Collection edges(org.apache.commons.collections.Predicate edgePredicate)
Specified by:
edges in interface com.phoenixst.plexus.Graph
Overrides:
edges in class com.phoenixst.plexus.AbstractGraph

getNode

public java.lang.Object getNode(org.apache.commons.collections.Predicate nodePredicate)
Returns a node from this graph that matches the specified filter.

Specified by:
getNode in interface com.phoenixst.plexus.Graph
Overrides:
getNode in class com.phoenixst.plexus.AbstractGraph

getEdge

public com.phoenixst.plexus.Graph.Edge getEdge(org.apache.commons.collections.Predicate edgePredicate)
Specified by:
getEdge in interface com.phoenixst.plexus.Graph
Overrides:
getEdge in class com.phoenixst.plexus.AbstractGraph

adjacentNodes

public java.util.Collection adjacentNodes(java.lang.Object node,
                                          org.apache.commons.collections.Predicate traverserPredicate)
Specified by:
adjacentNodes in interface com.phoenixst.plexus.Graph
Overrides:
adjacentNodes in class com.phoenixst.plexus.AbstractGraph

incidentEdges

public java.util.Collection incidentEdges(java.lang.Object node,
                                          org.apache.commons.collections.Predicate traverserPredicate)
Specified by:
incidentEdges in interface com.phoenixst.plexus.Graph
Overrides:
incidentEdges in class com.phoenixst.plexus.AbstractGraph

getAdjacentNode

public java.lang.Object getAdjacentNode(java.lang.Object node,
                                        org.apache.commons.collections.Predicate traverserPredicate)
Specified by:
getAdjacentNode in interface com.phoenixst.plexus.Graph
Overrides:
getAdjacentNode in class com.phoenixst.plexus.AbstractGraph

getIncidentEdge

public com.phoenixst.plexus.Graph.Edge getIncidentEdge(java.lang.Object node,
                                                       org.apache.commons.collections.Predicate traverserPredicate)
Specified by:
getIncidentEdge in interface com.phoenixst.plexus.Graph
Overrides:
getIncidentEdge in class com.phoenixst.plexus.AbstractGraph

traverser

public com.phoenixst.plexus.Traverser traverser(java.lang.Object node,
                                                org.apache.commons.collections.Predicate traverserPredicate)
Specified by:
traverser in interface com.phoenixst.plexus.Graph
Overrides:
traverser in class com.phoenixst.plexus.AbstractGraph

addGraphListener

public void addGraphListener(com.phoenixst.plexus.GraphListener listener)
Adds the specified GraphListener which will be notified whenever this ObservableGraph's structure changes.

Specified by:
addGraphListener in interface com.phoenixst.plexus.ObservableGraph

removeGraphListener

public void removeGraphListener(com.phoenixst.plexus.GraphListener listener)
Removes a previously added GraphListener.

Specified by:
removeGraphListener in interface com.phoenixst.plexus.ObservableGraph

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2002-2003 Paul Speed. All Rights Reserved.