de.cau.cs.kieler.core.util
Class DependencyGraph<S extends Comparable<S>,T extends IDepending<S>>

java.lang.Object
  extended by de.cau.cs.kieler.core.util.DependencyGraph<S,T>
Type Parameters:
S - the identifier type
T - the object type
All Implemented Interfaces:
IDependencyGraph<S,T>

public class DependencyGraph<S extends Comparable<S>,T extends IDepending<S>>
extends Object
implements IDependencyGraph<S,T>

A graph structure for expressing and resolving object dependencies.

Rating red

Nested Class Summary
 
Nested classes/interfaces inherited from interface de.cau.cs.kieler.core.util.IDependencyGraph
IDependencyGraph.DerivationDetail<T,R>
 
Constructor Summary
DependencyGraph()
           
 
Method Summary
 boolean add(T object)
          Adds an object to the graph if all dependencies can be resolved.
 List<T> addAll(Collection<T> objects)
          Adds a collection of objects to the graph and tries to resolve dependencies.
Returns a list of objects that could not be added cause they had missing dependencies or were part of a cycle.
 List<T> dependencySort(List<T> objects)
          Returns a sorted list of the objects so that an object that depends on another object precedes it in the list.
<R> R
deriveObject(T object, IDependencyGraph.DerivationDetail<T,R> derivationDetail)
          Derives a new object from an object in the graph, preserving the dependency information.
 T get(S id)
          Returns an object by it's identifier.
 List<T> remove(T object)
          Removes an object from the graph and all objects depending on it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DependencyGraph

public DependencyGraph()
Method Detail

add

public boolean add(T object)
Adds an object to the graph if all dependencies can be resolved.

Specified by:
add in interface IDependencyGraph<S extends Comparable<S>,T extends IDepending<S>>
Parameters:
object - the object
Returns:
true if the object was added

remove

public List<T> remove(T object)
Removes an object from the graph and all objects depending on it.

Specified by:
remove in interface IDependencyGraph<S extends Comparable<S>,T extends IDepending<S>>
Parameters:
object - the object to remove
Returns:
the removed objects

addAll

public List<T> addAll(Collection<T> objects)
Adds a collection of objects to the graph and tries to resolve dependencies.
Returns a list of objects that could not be added cause they had missing dependencies or were part of a cycle.

Specified by:
addAll in interface IDependencyGraph<S extends Comparable<S>,T extends IDepending<S>>
Parameters:
objects - the objects to add
Returns:
the list of objects that could not be added

get

public T get(S id)
Returns an object by it's identifier.

Specified by:
get in interface IDependencyGraph<S extends Comparable<S>,T extends IDepending<S>>
Parameters:
id - the identifier
Returns:
the object

dependencySort

public List<T> dependencySort(List<T> objects)
Returns a sorted list of the objects so that an object that depends on another object precedes it in the list. Removes objects that are not represented in this graph.

Specified by:
dependencySort in interface IDependencyGraph<S extends Comparable<S>,T extends IDepending<S>>
Parameters:
objects - the objects
Returns:
a sorted list respecting dependencies between the objects

deriveObject

public <R> R deriveObject(T object,
                          IDependencyGraph.DerivationDetail<T,R> derivationDetail)
Derives a new object from an object in the graph, preserving the dependency information.

Specified by:
deriveObject in interface IDependencyGraph<S extends Comparable<S>,T extends IDepending<S>>
Type Parameters:
R - the derivative type
Parameters:
object - the object in the graph
derivationDetail - the details of the derivation
Returns:
the derivative