JTools

org.jtools.depend
Interface Dependencies<T_ElementKey,T_ItemKey>

Type Parameters:
T_ElementKey - The Key type for elements.
T_ItemKey - The Key type for items.
All Known Implementing Classes:
SimpleDependencies

public interface Dependencies<T_ElementKey,T_ItemKey>

Main Interface for the Dependency feature. Dependencies are a feature to sort targets based on advanced sort criterias. These sort criterias are:

  1. The target's "default" (or "natural") order,
  2. direct dependencies between targets and
  3. indirect dependencies between targets and
  4. a sort algorithm to resolve the dependencies.
The "default order" of targets is declared by a provided Comparator or a predefined order via setDefaultOrder(Comparator) resp. setDefaultOrder(DependencyOrder).
Direct dependencies can be declared via DependencyElement's DependencyElement.addAffects(T_Key) and DependencyElement.addDepends(T_Key) methods.
Indirect dependencies can be declared via DependencyElement's DependencyElement.addInput(T_ItemKey) and DependencyElement.addOutput(T_ItemKey) methods.
A (predefined) sort algorithm can be specified by setAlgorithm(org.jtools.depend.DependencyResolution).
After declaring all dependencies, sort() sorts the targets in the implicite order and returns them in this order.

Author:
Rainer Noack

Method Summary
 DependencyElement<T_ElementKey,T_ItemKey> declareElement(T_ElementKey key)
          Declares (constructs) an element with the given key.
 DependencyItem<T_ItemKey> declareItem(T_ItemKey key)
          Declares (constructs) an item with the given key.
 DependencyElement<T_ElementKey,T_ItemKey> getElement(T_ElementKey key)
          Gets a previous declared target with the given key.
 DependencyItem<T_ItemKey> getItem(T_ItemKey key)
          Gets a previous declared item with the given key.
 boolean isChanged()
          Indicates whether the dependencies had changed since the last sorting.
 boolean isDeepDependencyCheck()
          Indicates whether the sorting algorithm does a deep dependency check.
 void setAlgorithm(DependencyAlgorithm<T_ElementKey,T_ItemKey> algorithm)
          Set the algorithm to use for resolution of direct and indirect dependencies.
 void setAlgorithm(DependencyResolution algorithm)
          Set the algorithm to use for resolution of direct and indirect dependencies.
 void setDeepDependencyCheck(Boolean onOff)
          Set deep dependency check on or off.
 void setDefaultOrder(Comparator<? super DependencyElement<T_ElementKey,T_ItemKey>> comparator)
          Sets the targets default sort order.
 void setDefaultOrder(DependencyOrder predefined)
          Sets the targets default sort order.
 Collection<DependencyElement<T_ElementKey,T_ItemKey>> sort()
          Get the targets sorted by primary and dependency order.
 

Method Detail

declareItem

DependencyItem<T_ItemKey> declareItem(T_ItemKey key)
Declares (constructs) an item with the given key. If an item with the given key is already declared, the method returns it; If not, it creates a new item.

Parameters:
key - The unique key for this item.
Returns:
The item with the given key.

declareElement

DependencyElement<T_ElementKey,T_ItemKey> declareElement(T_ElementKey key)
Declares (constructs) an element with the given key. If the element with the given key is already declared, the method returns it; If not, it creates a new target.

Parameters:
key - The unique key for this target.
Returns:
The target with the given key.

getItem

DependencyItem<T_ItemKey> getItem(T_ItemKey key)
Gets a previous declared item with the given key.

Parameters:
key - The unique key for this item.
Returns:
The item with the given key or null if it not exists.

getElement

DependencyElement<T_ElementKey,T_ItemKey> getElement(T_ElementKey key)
Gets a previous declared target with the given key.

Parameters:
key - The unique key for this target.
Returns:
The target with the given key or null if it not exists.

isChanged

boolean isChanged()
Indicates whether the dependencies had changed since the last sorting.

Returns:
True if the dependencies had changed, false otherwise.

isDeepDependencyCheck

boolean isDeepDependencyCheck()
Indicates whether the sorting algorithm does a deep dependency check.

Returns:
True if the sorting algorithm does a deep dependency check, false otherwise.

setAlgorithm

void setAlgorithm(DependencyResolution algorithm)
Set the algorithm to use for resolution of direct and indirect dependencies.

Parameters:
algorithm - The predefined algorithm to use.

setAlgorithm

void setAlgorithm(DependencyAlgorithm<T_ElementKey,T_ItemKey> algorithm)
Set the algorithm to use for resolution of direct and indirect dependencies.

Parameters:
algorithm - The algorithm to use.

setDeepDependencyCheck

void setDeepDependencyCheck(Boolean onOff)
Set deep dependency check on or off.

Parameters:
onOff - True to turn on the deep dependency check, false otherwise.

sort

Collection<DependencyElement<T_ElementKey,T_ItemKey>> sort()
                                                           throws DependencyException
Get the targets sorted by primary and dependency order.

Returns:
A collection of the sorted targets.
Throws:
DependencyException - if an error occurs.

setDefaultOrder

void setDefaultOrder(DependencyOrder predefined)
Sets the targets default sort order.

Parameters:
predefined - One of the predefined sort orders.
Throws:
DependencyException - if an error occurs.

setDefaultOrder

void setDefaultOrder(Comparator<? super DependencyElement<T_ElementKey,T_ItemKey>> comparator)
Sets the targets default sort order.

Parameters:
comparator - A custom comparator for DependencyTargets.
Throws:
DependencyException - if an error occurs.

JTools

© 2000-2006, JTools.org.