jcommon.graph
Class DirectedAcyclicGraph<TVertex extends IVertex<TValue>,TValue,TProcessedValue>

java.lang.Object
  extended by jcommon.graph.DirectedAcyclicGraph<TVertex,TValue,TProcessedValue>
Type Parameters:
TVertex - Type of IVertex vertices that this graph contains.
All Implemented Interfaces:
Cloneable, IGraph<TVertex,TValue,TProcessedValue>
Direct Known Subclasses:
ObjectGraph

public class DirectedAcyclicGraph<TVertex extends IVertex<TValue>,TValue,TProcessedValue>
extends Object
implements Cloneable, IGraph<TVertex,TValue,TProcessedValue>

Factory and implementation of a dependency graph that can topologically sort its vertices.

See Also:
IGraph

Field Summary
 
Fields inherited from interface jcommon.graph.IGraph
EMPTY_VERTICES
 
Method Summary
 IGraph<TVertex,TValue,TProcessedValue> addEdge(TVertex from, TVertex to)
          Adds a new IEdge instance to this IGraph.
 IGraph<TVertex,TValue,TProcessedValue> addVertex(TVertex vertex)
          Adds a new IVertex instance of TVertex to this IGraph.
static
<TVertex extends IVertex<TValue>,TValue,TProcessedValue>
IGraph<TVertex,TValue,TProcessedValue>
build(TVertex... vertices)
          Convenience method for easily constructing an instance of IGraph with the provided vertices.
 IGraph<TVertex,TValue,TProcessedValue> copy()
          More type-safe version of Object.clone().
static
<TVertex extends IVertex<TValue>,TValue,TProcessedValue>
IGraph<TVertex,TValue,TProcessedValue>
create()
          Convenience method for easily constructing an instance of IGraph with an empty set of vertices.
 Set<IEdge<TVertex>> getEdges()
          Retrieves the set of IEdge edges represented by this IGraph.
 Set<TVertex> getVertices()
          Retrieves the set of IVertex vertices of TVertex represented by this IGraph.
 IGraph<TVertex,TValue,TProcessedValue> removeEdge(TVertex from, TVertex to)
          Removes an existing edge from this IGraph.
 IGraph<TVertex,TValue,TProcessedValue> removeVertex(TVertex vertex)
          Removes an IVertex instance of TVertex from this IGraph.
 List<TValue> sort()
          Provides a topologically sorted list of IVertex vertices.
 List<TValue> sort(ITopologicalSortStrategy<TVertex,TValue,TProcessedValue> strategy)
          Provides a topologically sorted list of IVertex vertices.
 ITopologicalSortAsyncResult<TValue,TProcessedValue> sortAsync(ExecutorService executor, ITopologicalSortCallback<TValue,TProcessedValue> callback)
          Allows you to asynchronously and in-parallel process the vertices of a graph topologically.
 ITopologicalSortAsyncResult<TValue,TProcessedValue> sortAsync(ExecutorService executor, ITopologicalSortCallback<TValue,TProcessedValue> callback, ITopologicalSortErrorCallback<TValue> errorCallback)
          Allows you to asynchronously and in-parallel process the vertices of a graph topologically.
 ITopologicalSortAsyncResult<TValue,TProcessedValue> sortAsync(ExecutorService executor, ITopologicalSortStrategy<TVertex,TValue,TProcessedValue> strategy, ITopologicalSortCallback<TValue,TProcessedValue> callback)
          Allows you to asynchronously and in-parallel process the vertices of a graph topologically.
 ITopologicalSortAsyncResult<TValue,TProcessedValue> sortAsync(ExecutorService executor, ITopologicalSortStrategy<TVertex,TValue,TProcessedValue> strategy, ITopologicalSortCallback<TValue,TProcessedValue> callback, ITopologicalSortErrorCallback<TValue> errorCallback)
          Allows you to asynchronously and in-parallel process the vertices of a graph topologically.
 ITopologicalSortAsyncResult<TValue,TProcessedValue> sortAsync(ITopologicalSortCallback<TValue,TProcessedValue> callback)
          Allows you to asynchronously and in-parallel process the vertices of a graph topologically.
 ITopologicalSortAsyncResult<TValue,TProcessedValue> sortAsync(ITopologicalSortCallback<TValue,TProcessedValue> callback, ITopologicalSortErrorCallback<TValue> errorCallback)
          Allows you to asynchronously and in-parallel process the vertices of a graph topologically.
 ITopologicalSortAsyncResult<TValue,TProcessedValue> sortAsync(ITopologicalSortStrategy<TVertex,TValue,TProcessedValue> strategy, ITopologicalSortCallback<TValue,TProcessedValue> callback)
          Allows you to asynchronously and in-parallel process the vertices of a graph topologically.
 ITopologicalSortAsyncResult<TValue,TProcessedValue> sortAsync(ITopologicalSortStrategy<TVertex,TValue,TProcessedValue> strategy, ITopologicalSortCallback<TValue,TProcessedValue> callback, ITopologicalSortErrorCallback<TValue> errorCallback)
          Allows you to asynchronously and in-parallel process the vertices of a graph topologically.
 boolean validate()
          Does a simple sanity check on the structure of the graph.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getVertices

public Set<TVertex> getVertices()
Description copied from interface: IGraph
Retrieves the set of IVertex vertices of TVertex represented by this IGraph.

Specified by:
getVertices in interface IGraph<TVertex extends IVertex<TValue>,TValue,TProcessedValue>
Returns:
The set of IVertex vertices of TVertex represented by this IGraph.
See Also:
IGraph.getVertices()

getEdges

public Set<IEdge<TVertex>> getEdges()
Description copied from interface: IGraph
Retrieves the set of IEdge edges represented by this IGraph.

Specified by:
getEdges in interface IGraph<TVertex extends IVertex<TValue>,TValue,TProcessedValue>
Returns:
The set of IEdge edges represented by this IGraph.
See Also:
IGraph.getEdges()

copy

public IGraph<TVertex,TValue,TProcessedValue> copy()
Description copied from interface: IGraph
More type-safe version of Object.clone().

Specified by:
copy in interface IGraph<TVertex extends IVertex<TValue>,TValue,TProcessedValue>
Returns:
A deep copy of this instance of IGraph.
See Also:
IGraph.copy()

build

public static <TVertex extends IVertex<TValue>,TValue,TProcessedValue> IGraph<TVertex,TValue,TProcessedValue> build(TVertex... vertices)
Convenience method for easily constructing an instance of IGraph with the provided vertices.

Type Parameters:
TVertex - Type of IVertex of the vertices in the new IGraph.
Parameters:
vertices - A list of IVertex vertices to be added to a new IGraph.
Returns:
A new instance of IGraph with the provided vertices already added.

create

public static <TVertex extends IVertex<TValue>,TValue,TProcessedValue> IGraph<TVertex,TValue,TProcessedValue> create()
Convenience method for easily constructing an instance of IGraph with an empty set of vertices.

Type Parameters:
TVertex - Type of IVertex of the vertices in the new IGraph.
Returns:
A new instance of IGraph with an empty set of vertices.

addVertex

public IGraph<TVertex,TValue,TProcessedValue> addVertex(TVertex vertex)
Description copied from interface: IGraph
Adds a new IVertex instance of TVertex to this IGraph.

Specified by:
addVertex in interface IGraph<TVertex extends IVertex<TValue>,TValue,TProcessedValue>
Parameters:
vertex - The instance of IVertex of TVertex to add to this IGraph.
Returns:
The current instance of IGraph for use in a builder-style pattern.
See Also:
IGraph.addVertex(IVertex)

removeVertex

public IGraph<TVertex,TValue,TProcessedValue> removeVertex(TVertex vertex)
Description copied from interface: IGraph
Removes an IVertex instance of TVertex from this IGraph.

Specified by:
removeVertex in interface IGraph<TVertex extends IVertex<TValue>,TValue,TProcessedValue>
Parameters:
vertex - The instance of IVertex of TVertex to remove from this IGraph.
Returns:
The current instance of IGraph for use in a builder-style pattern.
See Also:
IGraph.removeVertex(IVertex)

addEdge

public IGraph<TVertex,TValue,TProcessedValue> addEdge(TVertex from,
                                                      TVertex to)
Description copied from interface: IGraph
Adds a new IEdge instance to this IGraph.

Specified by:
addEdge in interface IGraph<TVertex extends IVertex<TValue>,TValue,TProcessedValue>
Parameters:
from - An instance of IVertex of TVertex that begins the edge.
to - An instance of IVertex of TVertex that the edge is pointing to.
Returns:
The current instance of IGraph for use in a builder-style pattern.
See Also:
IGraph.addEdge(IVertex, IVertex)

removeEdge

public IGraph<TVertex,TValue,TProcessedValue> removeEdge(TVertex from,
                                                         TVertex to)
Description copied from interface: IGraph
Removes an existing edge from this IGraph.

Specified by:
removeEdge in interface IGraph<TVertex extends IVertex<TValue>,TValue,TProcessedValue>
Parameters:
from - An instance of IVertex of TVertex that begins the edge.
to - An instance of IVertex of TVertex that the edge is pointing to.
Returns:
The current instance of IGraph for use in a builder-style pattern.
See Also:
IGraph.removeEdge(IVertex, IVertex)

validate

public boolean validate()
Description copied from interface: IGraph
Does a simple sanity check on the structure of the graph. Should not be called until the graph has been completely structured. Notably a cycle check is not done at this point. That's only detected upon a topological sort of the graph.

Specified by:
validate in interface IGraph<TVertex extends IVertex<TValue>,TValue,TProcessedValue>
Returns:
true if the graph passes a simple sanity check; false otherwise.
See Also:
IGraph.validate()

sort

public List<TValue> sort()
                  throws CyclicGraphException
Description copied from interface: IGraph
Provides a topologically sorted list of IVertex vertices.

Specified by:
sort in interface IGraph<TVertex extends IVertex<TValue>,TValue,TProcessedValue>
Returns:
A topologically sorted list of IVertex vertices in the current graph.
Throws:
CyclicGraphException - A CyclicGraphException is thrown if a cycle is detected during the sort.
See Also:
IGraph.sort()

sort

public List<TValue> sort(ITopologicalSortStrategy<TVertex,TValue,TProcessedValue> strategy)
                  throws CyclicGraphException
Description copied from interface: IGraph
Provides a topologically sorted list of IVertex vertices. It's strongly recommended that you use IGraph.sort() in most cases unless you require an alternative approach to the topological sorting algorithm.

Specified by:
sort in interface IGraph<TVertex extends IVertex<TValue>,TValue,TProcessedValue>
Parameters:
strategy - An instance of ITopologicalSortStrategy that will perform the sort.
Returns:
A topologically sorted list of IVertex vertices in the current graph.
Throws:
CyclicGraphException - A CyclicGraphException is thrown if a cycle is detected during the sort.
See Also:
IGraph.sort(ITopologicalSortStrategy)

sortAsync

public ITopologicalSortAsyncResult<TValue,TProcessedValue> sortAsync(ITopologicalSortCallback<TValue,TProcessedValue> callback)
Description copied from interface: IGraph
Allows you to asynchronously and in-parallel process the vertices of a graph topologically. Care is taken to prevent the processing of vertices before their parent vertices have completed processing.

Specified by:
sortAsync in interface IGraph<TVertex extends IVertex<TValue>,TValue,TProcessedValue>
Parameters:
callback - An instance of ITopologicalSortCallback that will be called to process each vertex. This may be called concurrently depending on the makeup of the graph.
Returns:
An instance of ITopologicalSortAsyncResult that allows the caller to coordinate the asynchronous processing of the graph.
See Also:
IGraph.sortAsync(ITopologicalSortCallback)

sortAsync

public ITopologicalSortAsyncResult<TValue,TProcessedValue> sortAsync(ITopologicalSortCallback<TValue,TProcessedValue> callback,
                                                                     ITopologicalSortErrorCallback<TValue> errorCallback)
Description copied from interface: IGraph
Allows you to asynchronously and in-parallel process the vertices of a graph topologically. Care is taken to prevent the processing of vertices before their parent vertices have completed processing.

Specified by:
sortAsync in interface IGraph<TVertex extends IVertex<TValue>,TValue,TProcessedValue>
Parameters:
callback - An instance of ITopologicalSortCallback that will be called to process each vertex. This may be called concurrently depending on the makeup of the graph.
errorCallback - An instance of ITopologicalSortErrorCallback that will be called if an error during processing occurs either in the ITopologicalSortCallback.handle(Object, ITopologicalSortInput, IVertex, ITopologicalSortCoordinator) method or in the ITopologicalSortStrategy.sortAsync(java.util.concurrent.ExecutorService, IAdjacencyList, ITopologicalSortCallback, ITopologicalSortErrorCallback) method.
Returns:
An instance of ITopologicalSortAsyncResult that allows the caller to coordinate the asynchronous processing of the graph.
See Also:
IGraph.sortAsync(ITopologicalSortCallback, ITopologicalSortErrorCallback)

sortAsync

public ITopologicalSortAsyncResult<TValue,TProcessedValue> sortAsync(ITopologicalSortStrategy<TVertex,TValue,TProcessedValue> strategy,
                                                                     ITopologicalSortCallback<TValue,TProcessedValue> callback)
Description copied from interface: IGraph
Allows you to asynchronously and in-parallel process the vertices of a graph topologically. Care is taken to prevent the processing of vertices before their parent vertices have completed processing. It's strongly recommended that you use IGraph.sortAsync(ITopologicalSortCallback) in most cases unless you require an alternative approach to the topological sorting algorithm.

Specified by:
sortAsync in interface IGraph<TVertex extends IVertex<TValue>,TValue,TProcessedValue>
Parameters:
strategy - An instance of ITopologicalSortStrategy that will perform the sort.
callback - An instance of ITopologicalSortCallback that will be called to process each vertex. This may be called concurrently depending on the makeup of the graph.
Returns:
An instance of ITopologicalSortAsyncResult that allows the caller to coordinate the asynchronous processing of the graph.
See Also:
IGraph.sortAsync(ITopologicalSortStrategy, ITopologicalSortCallback)

sortAsync

public ITopologicalSortAsyncResult<TValue,TProcessedValue> sortAsync(ITopologicalSortStrategy<TVertex,TValue,TProcessedValue> strategy,
                                                                     ITopologicalSortCallback<TValue,TProcessedValue> callback,
                                                                     ITopologicalSortErrorCallback<TValue> errorCallback)
Description copied from interface: IGraph
Allows you to asynchronously and in-parallel process the vertices of a graph topologically. Care is taken to prevent the processing of vertices before their parent vertices have completed processing. It's strongly recommended that you use IGraph.sortAsync(ITopologicalSortCallback, ITopologicalSortErrorCallback) in most cases unless you require an alternative approach to the topological sorting algorithm.

Specified by:
sortAsync in interface IGraph<TVertex extends IVertex<TValue>,TValue,TProcessedValue>
Parameters:
strategy - An instance of ITopologicalSortStrategy that will perform the sort.
callback - An instance of ITopologicalSortCallback that will be called to process each vertex. This may be called concurrently depending on the makeup of the graph.
errorCallback - An instance of ITopologicalSortErrorCallback that will be called if an error during processing occurs either in the ITopologicalSortCallback.handle(Object, ITopologicalSortInput, IVertex, ITopologicalSortCoordinator) method or in the ITopologicalSortStrategy.sortAsync(java.util.concurrent.ExecutorService, IAdjacencyList, ITopologicalSortCallback, ITopologicalSortErrorCallback) method.
Returns:
An instance of ITopologicalSortAsyncResult that allows the caller to coordinate the asynchronous processing of the graph.
See Also:
IGraph.sortAsync(ITopologicalSortStrategy, ITopologicalSortCallback, ITopologicalSortErrorCallback)

sortAsync

public ITopologicalSortAsyncResult<TValue,TProcessedValue> sortAsync(ExecutorService executor,
                                                                     ITopologicalSortCallback<TValue,TProcessedValue> callback)
Description copied from interface: IGraph
Allows you to asynchronously and in-parallel process the vertices of a graph topologically. Care is taken to prevent the processing of vertices before their parent vertices have completed processing.

Specified by:
sortAsync in interface IGraph<TVertex extends IVertex<TValue>,TValue,TProcessedValue>
Parameters:
executor - An instance of ExecutorService that will be used to submit tasks for processing vertices.
callback - An instance of ITopologicalSortCallback that will be called to process each vertex. This may be called concurrently depending on the makeup of the graph.
Returns:
An instance of ITopologicalSortAsyncResult that allows the caller to coordinate the asynchronous processing of the graph.
See Also:
IGraph.sortAsync(java.util.concurrent.ExecutorService, ITopologicalSortCallback)

sortAsync

public ITopologicalSortAsyncResult<TValue,TProcessedValue> sortAsync(ExecutorService executor,
                                                                     ITopologicalSortCallback<TValue,TProcessedValue> callback,
                                                                     ITopologicalSortErrorCallback<TValue> errorCallback)
Description copied from interface: IGraph
Allows you to asynchronously and in-parallel process the vertices of a graph topologically. Care is taken to prevent the processing of vertices before their parent vertices have completed processing.

Specified by:
sortAsync in interface IGraph<TVertex extends IVertex<TValue>,TValue,TProcessedValue>
Parameters:
executor - An instance of ExecutorService that will be used to submit tasks for processing vertices.
callback - An instance of ITopologicalSortCallback that will be called to process each vertex. This may be called concurrently depending on the makeup of the graph.
errorCallback - An instance of ITopologicalSortErrorCallback that will be called if an error during processing occurs either in the ITopologicalSortCallback.handle(Object, ITopologicalSortInput, IVertex, ITopologicalSortCoordinator) method or in the ITopologicalSortStrategy.sortAsync(java.util.concurrent.ExecutorService, IAdjacencyList, ITopologicalSortCallback, ITopologicalSortErrorCallback) method.
Returns:
An instance of ITopologicalSortAsyncResult that allows the caller to coordinate the asynchronous processing of the graph.
See Also:
IGraph.sortAsync(java.util.concurrent.ExecutorService, ITopologicalSortCallback, ITopologicalSortErrorCallback)

sortAsync

public ITopologicalSortAsyncResult<TValue,TProcessedValue> sortAsync(ExecutorService executor,
                                                                     ITopologicalSortStrategy<TVertex,TValue,TProcessedValue> strategy,
                                                                     ITopologicalSortCallback<TValue,TProcessedValue> callback)
Description copied from interface: IGraph
Allows you to asynchronously and in-parallel process the vertices of a graph topologically. Care is taken to prevent the processing of vertices before their parent vertices have completed processing. It's strongly recommended that you use IGraph.sortAsync(java.util.concurrent.ExecutorService, ITopologicalSortCallback) in most cases unless you require an alternative approach to the topological sorting algorithm.

Specified by:
sortAsync in interface IGraph<TVertex extends IVertex<TValue>,TValue,TProcessedValue>
Parameters:
executor - An instance of ExecutorService that will be used to submit tasks for processing vertices.
strategy - An instance of ITopologicalSortStrategy that will perform the sort.
callback - An instance of ITopologicalSortCallback that will be called to process each vertex. This may be called concurrently depending on the makeup of the graph.
Returns:
An instance of ITopologicalSortAsyncResult that allows the caller to coordinate the asynchronous processing of the graph.
See Also:
IGraph.sortAsync(java.util.concurrent.ExecutorService, ITopologicalSortStrategy, ITopologicalSortCallback)

sortAsync

public ITopologicalSortAsyncResult<TValue,TProcessedValue> sortAsync(ExecutorService executor,
                                                                     ITopologicalSortStrategy<TVertex,TValue,TProcessedValue> strategy,
                                                                     ITopologicalSortCallback<TValue,TProcessedValue> callback,
                                                                     ITopologicalSortErrorCallback<TValue> errorCallback)
Description copied from interface: IGraph
Allows you to asynchronously and in-parallel process the vertices of a graph topologically. Care is taken to prevent the processing of vertices before their parent vertices have completed processing. It's strongly recommended that you use IGraph.sortAsync(java.util.concurrent.ExecutorService, ITopologicalSortCallback, ITopologicalSortErrorCallback) in most cases unless you require an alternative approach to the topological sorting algorithm.

Specified by:
sortAsync in interface IGraph<TVertex extends IVertex<TValue>,TValue,TProcessedValue>
Parameters:
executor - An instance of ExecutorService that will be used to submit tasks for processing vertices.
strategy - An instance of ITopologicalSortStrategy that will perform the sort.
callback - An instance of ITopologicalSortCallback that will be called to process each vertex. This may be called concurrently depending on the makeup of the graph.
errorCallback - An instance of ITopologicalSortErrorCallback that will be called if an error during processing occurs either in the ITopologicalSortCallback.handle(Object, ITopologicalSortInput, IVertex, ITopologicalSortCoordinator) method or in the ITopologicalSortStrategy.sortAsync(java.util.concurrent.ExecutorService, IAdjacencyList, ITopologicalSortCallback, ITopologicalSortErrorCallback) method.
Returns:
An instance of ITopologicalSortAsyncResult that allows the caller to coordinate the asynchronous processing of the graph.
See Also:
IGraph.sortAsync(java.util.concurrent.ExecutorService, ITopologicalSortStrategy, ITopologicalSortCallback, ITopologicalSortErrorCallback)


Copyright © 2012-2013. All Rights Reserved.