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 Details

  • Constructor Details

  • Method Details

    • 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