de.cau.cs.kieler.kiml.grana
Class DependencyGraph<S extends Comparable<S>,T extends IDepending<S>>

java.lang.Object
  extended by de.cau.cs.kieler.kiml.grana.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

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.
 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