jcommon.graph
Interface IGraph<TVertex extends IVertex<TValue>,TValue,TProcessedValue>

Type Parameters:
TVertex - Type of IVertex that vertices in this graph are.
TValue - Type of Object that the vertices in this graph contain.
All Known Implementing Classes:
DirectedAcyclicGraph, NumberGraph, ObjectGraph, StringGraph

public interface IGraph<TVertex extends IVertex<TValue>,TValue,TProcessedValue>

This is a simple graph holding IVertex vertices and IEdge edges connecting them. It is intended to be used in a builder-style pattern and then operations such as sort() may be called on the graph. Of particular note is the sortAsync(ITopologicalSortCallback) method which 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.


Field Summary
static IVertex[] EMPTY_VERTICES
          Reference for an array of empty vertices that can be reused instead of having to allocate a new empty array on the heap every time.
 
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.
 IGraph<TVertex,TValue,TProcessedValue> copy()
          More type-safe version of Object.clone().
 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.
 

Field Detail

EMPTY_VERTICES

static final IVertex[] EMPTY_VERTICES
Reference for an array of empty vertices that can be reused instead of having to allocate a new empty array on the heap every time.

Method Detail

getVertices

Set<TVertex> getVertices()
Retrieves the set of IVertex vertices of TVertex represented by this IGraph.

Returns:
The set of IVertex vertices of TVertex represented by this IGraph.

getEdges

Set<IEdge<TVertex>> getEdges()
Retrieves the set of IEdge edges represented by this IGraph.

Returns:
The set of IEdge edges represented by this IGraph.

copy

IGraph<TVertex,TValue,TProcessedValue> copy()
More type-safe version of Object.clone().

Returns:
A deep copy of this instance of IGraph.

addVertex

IGraph<TVertex,TValue,TProcessedValue> addVertex(TVertex vertex)
Adds a new IVertex instance of TVertex to this IGraph.

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.

removeVertex

IGraph<TVertex,TValue,TProcessedValue> removeVertex(TVertex vertex)
Removes an IVertex instance of TVertex from this IGraph.

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.

addEdge

IGraph<TVertex,TValue,TProcessedValue> addEdge(TVertex from,
                                               TVertex to)
Adds a new IEdge instance to this IGraph.

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.

removeEdge

IGraph<TVertex,TValue,TProcessedValue> removeEdge(TVertex from,
                                                  TVertex to)
Removes an existing edge from this IGraph.

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.

validate

boolean validate()
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.

Returns:
true if the graph passes a simple sanity check; false otherwise.

sort

List<TValue> sort()
                  throws CyclicGraphException
Provides a topologically sorted list of IVertex vertices.

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:
http://en.wikipedia.org/wiki/Topological_sorting

sort

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

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:
http://en.wikipedia.org/wiki/Topological_sorting

sortAsync

ITopologicalSortAsyncResult<TValue,TProcessedValue> sortAsync(ITopologicalSortCallback<TValue,TProcessedValue> callback)
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.

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:
http://en.wikipedia.org/wiki/Topological_sorting

sortAsync

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. Care is taken to prevent the processing of vertices before their parent vertices have completed processing.

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:
http://en.wikipedia.org/wiki/Topological_sorting

sortAsync

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. Care is taken to prevent the processing of vertices before their parent vertices have completed processing. It's strongly recommended that you use sortAsync(ITopologicalSortCallback) in most cases unless you require an alternative approach to the topological sorting algorithm.

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:
http://en.wikipedia.org/wiki/Topological_sorting

sortAsync

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. Care is taken to prevent the processing of vertices before their parent vertices have completed processing. It's strongly recommended that you use sortAsync(ITopologicalSortCallback, ITopologicalSortErrorCallback) in most cases unless you require an alternative approach to the topological sorting algorithm.

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:
http://en.wikipedia.org/wiki/Topological_sorting

sortAsync

ITopologicalSortAsyncResult<TValue,TProcessedValue> sortAsync(ExecutorService executor,
                                                              ITopologicalSortCallback<TValue,TProcessedValue> callback)
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.

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:
http://en.wikipedia.org/wiki/Topological_sorting

sortAsync

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. Care is taken to prevent the processing of vertices before their parent vertices have completed processing.

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:
http://en.wikipedia.org/wiki/Topological_sorting

sortAsync

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. Care is taken to prevent the processing of vertices before their parent vertices have completed processing. It's strongly recommended that you use sortAsync(java.util.concurrent.ExecutorService, ITopologicalSortCallback) in most cases unless you require an alternative approach to the topological sorting algorithm.

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:
http://en.wikipedia.org/wiki/Topological_sorting

sortAsync

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. Care is taken to prevent the processing of vertices before their parent vertices have completed processing. It's strongly recommended that you use sortAsync(java.util.concurrent.ExecutorService, ITopologicalSortCallback, ITopologicalSortErrorCallback) in most cases unless you require an alternative approach to the topological sorting algorithm.

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:
http://en.wikipedia.org/wiki/Topological_sorting


Copyright © 2012-2013. All Rights Reserved.