Class MapTransformer<I,O>

java.lang.Object
org.apache.commons.collections4.functors.MapTransformer<I,O>
All Implemented Interfaces:
Serializable, Transformer<I,O>

public final class MapTransformer<I,O> extends Object implements Transformer<I,O>, Serializable
Transformer implementation that returns the value held in a specified map using the input parameter as a key.
Since:
3.0
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final Map<? super I,? extends O>
    The map of data to lookup in
    private static final long
    Serial version UID
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    MapTransformer(Map<? super I,? extends O> map)
    Constructor that performs no validation.
  • Method Summary

    Modifier and Type
    Method
    Description
    Map<? super I,? extends O>
    Gets the map to lookup in.
    static <I, O> Transformer<I,O>
    mapTransformer(Map<? super I,? extends O> map)
    Factory to create the transformer.
    transform(I input)
    Transforms the input to result by looking it up in a Map.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      Serial version UID
      See Also:
    • iMap

      private final Map<? super I,? extends O> iMap
      The map of data to lookup in
  • Constructor Details

    • MapTransformer

      private MapTransformer(Map<? super I,? extends O> map)
      Constructor that performs no validation. Use mapTransformer if you want that.
      Parameters:
      map - the map to use for lookup, not cloned
  • Method Details

    • mapTransformer

      public static <I, O> Transformer<I,O> mapTransformer(Map<? super I,? extends O> map)
      Factory to create the transformer.

      If the map is null, a transformer that always returns null is returned.

      Type Parameters:
      I - the input type
      O - the output type
      Parameters:
      map - the map, not cloned
      Returns:
      the transformer
    • transform

      public O transform(I input)
      Transforms the input to result by looking it up in a Map.
      Specified by:
      transform in interface Transformer<I,O>
      Parameters:
      input - the input object to transform
      Returns:
      the transformed result
    • getMap

      public Map<? super I,? extends O> getMap()
      Gets the map to lookup in.
      Returns:
      the map
      Since:
      3.1