2.17.2: 2011-06-17

net.sf.basedb.util.collections
Class MultiStepCollectionTransformer<S,D>

java.lang.Object
  extended by net.sf.basedb.util.collections.MultiStepCollectionTransformer<S,D>
All Implemented Interfaces:
CollectionTransformer<S,D>

public class MultiStepCollectionTransformer<S,D>
extends Object
implements CollectionTransformer<S,D>

Collection transformer implementation that transforms a source collection into the destination collection using multiple steps. Each transformation step is delegated to a transformer that is specified in the constructor. Source and destination collection types must match between each step. Eg. the destination collection from the first step is used as the source collection in the second step, the destination from the second step is used as source in the third step, and so on.

This class is abstract since it doesn't know which type of collection to use in the intermediary steps. Subclasses need to implement createTempCollection(CollectionTransformer) that should create a new collection in each step.

Version:
2.10
Author:
Nicklas
Last modified
$Date: 2010-08-13 10:50:27 +0200 (Fri, 13 Aug 2010) $

Field Summary
private  List<CollectionTransformer> steps
           
 
Constructor Summary
MultiStepCollectionTransformer(List<CollectionTransformer> steps)
           
 
Method Summary
protected  Collection createTempCollection(CollectionTransformer transformer)
          Create a temporary collection that is suitable for holding an intermediary result.
 String toString()
           
 int transform(Collection<? extends S> source, Collection<? super D> destination)
          Transform the source collection into the destination collection by applying all intermediate transformers specified in the constructor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

steps

private final List<CollectionTransformer> steps
Constructor Detail

MultiStepCollectionTransformer

public MultiStepCollectionTransformer(List<CollectionTransformer> steps)
Method Detail

transform

public int transform(Collection<? extends S> source,
                     Collection<? super D> destination)
Transform the source collection into the destination collection by applying all intermediate transformers specified in the constructor.

Specified by:
transform in interface CollectionTransformer<S,D>
Parameters:
source - The source collection
destination - The destination collection
Returns:
The result of the last transformation step

createTempCollection

protected Collection createTempCollection(CollectionTransformer transformer)
Create a temporary collection that is suitable for holding an intermediary result. The returned collection will be used as the destination collection when calling CollectionTransformer.transform(Collection, Collection). The default implementation always create HashSet collections. If a different type of collection is needed, a subclass that overrides this method should be used.

NOTE! Each call to this method should create a new collection.


toString

public String toString()
Overrides:
toString in class Object

2.17.2: 2011-06-17