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.

Version:
1.1
Author:
M.Duchrow

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.
 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).
 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
equals, 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.