Package net.sf.basedb.util.collections
Class MultiStepCollectionTransformer<S,D>
- java.lang.Object
-
- 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: 2015-04-20 11:08:18 +0200 (må, 20 apr 2015) $
-
-
Field Summary
Fields Modifier and Type Field Description private List<CollectionTransformer<?,?>>
steps
-
Constructor Summary
Constructors Constructor Description MultiStepCollectionTransformer(List<CollectionTransformer<?,?>> steps)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.
-
-
-
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 interfaceCollectionTransformer<S,D>
- Parameters:
source
- The source collectiondestination
- 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 callingCollectionTransformer.transform(Collection, Collection)
. The default implementation always createHashSet
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.
-
-