org.pfsw.odem
Class DependencySet<S extends IExplorableElement,T extends IExplorableElement>

java.lang.Object
  extended by org.pfsw.odem.DependencySet<S,T>

public class DependencySet<S extends IExplorableElement,T extends IExplorableElement>
extends java.lang.Object

A set of IDependency objects. It allows to simply lookup particular elements and to iterate over the elements.

Type S defines the type of the source elements in the dependencies supported by this dependency set and type T specifies the type of the target elements.
Be aware that this implies the assumption that all dependency objects in a dependency set are of the same type.


Constructor Summary
DependencySet()
          Initialize the new instance with a default capcity of 50.
DependencySet(int initialCapacity)
          Initialize the new instance with an initial capacity.
 
Method Summary
 void add(IDependency<S,T> dependency)
          Add a new dependency.
protected  void addAll(java.util.Collection<IDependency<S,T>> someDependencies)
          Adds all the dependencies in the given collection to the internal dependency list.
 java.util.List<IDependency<S,T>> collect(IDependencyFilter<IDependency<S,T>> filter)
          Return a list of all dependencies that match the given filter.
 java.util.List<IDependency<S,T>> collectForClassification(DependencyClassification classification)
          Return a list of all dependencies with the given classification.
 void collectInto(java.util.Collection<IDependency<S,T>> collection, IDependencyFilter<IDependency<S,T>> filter)
          Adds all dependencies that match the given filter to the provided collection.
 DependencySet<S,T> copy()
          Returns a copy of this dependency set that contains the identical dependency objects (i.e. no deep copy).
protected  IDependency<S,T> findFirstDependencyWith(IExplorableElement element, boolean elementIsSource)
          Returns the first dependency with the a source element equal to the given element.
 IDependency<S,T> lookupSourceElement(S source)
          Returns the first dependency with the source element equal to the given element.
 IDependency<S,T> lookupTargetElement(T target)
          Returns the first dependency with the a target element equal to the given element.
 java.util.List<IDependency<S,T>> newList(int initialCapacity)
          Returns a new list to hold dependency objects of the correct type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DependencySet

public DependencySet()
Initialize the new instance with a default capcity of 50.


DependencySet

public DependencySet(int initialCapacity)
Initialize the new instance with an initial capacity.

Method Detail

add

public void add(IDependency<S,T> dependency)
Add a new dependency.


lookupSourceElement

public IDependency<S,T> lookupSourceElement(S source)
Returns the first dependency with the source element equal to the given element.

Parameters:
source - The source element to look for
Returns:
The dependency or null if not found

lookupTargetElement

public IDependency<S,T> lookupTargetElement(T target)
Returns the first dependency with the a target element equal to the given element.

Parameters:
target - The target element to look for
Returns:
The dependency or null if not found

collectInto

public void collectInto(java.util.Collection<IDependency<S,T>> collection,
                        IDependencyFilter<IDependency<S,T>> filter)
Adds all dependencies that match the given filter to the provided collection.

Parameters:
collection - The collection to which the dependencies will be added
filter - The filter that determines which dependencies to add

collect

public java.util.List<IDependency<S,T>> collect(IDependencyFilter<IDependency<S,T>> filter)
Return a list of all dependencies that match the given filter.

Parameters:
filter - The filter the dependencies must match.
Returns:
Always a list, never null

collectForClassification

public java.util.List<IDependency<S,T>> collectForClassification(DependencyClassification classification)
Return a list of all dependencies with the given classification.

Parameters:
classification - The classification of the dependencies to collect.
Returns:
Always a list, never null

copy

public DependencySet<S,T> copy()
Returns a copy of this dependency set that contains the identical dependency objects (i.e. no deep copy).


newList

public java.util.List<IDependency<S,T>> newList(int initialCapacity)
Returns a new list to hold dependency objects of the correct type. Here this methods creates a new java.util.ArrayList.
Subclasses may override this method in order to provide a different type of List implementation.
Whenever a new list is needed in this class then this method will be used to get one.

Parameters:
initialCapacity - The initial capacity of the new list.

findFirstDependencyWith

protected IDependency<S,T> findFirstDependencyWith(IExplorableElement element,
                                                   boolean elementIsSource)
Returns the first dependency with the a source element equal to the given element.

Parameters:
element - The element to look for
elementIsSource - if true the given element is the source element, otherwise false
Returns:
The dependency or null if not found

addAll

protected void addAll(java.util.Collection<IDependency<S,T>> someDependencies)
Adds all the dependencies in the given collection to the internal dependency list.

Parameters:
someDependencies - A collection of dependencies (must not be null)