org.apache.commons.collections4.functors

## Class ConstantTransformer<I,O>

- java.lang.Object
- - org.apache.commons.collections4.functors.ConstantTransformer<I,O>

- All Implemented Interfaces:
    Serializable, Transformer<I,O>

      public class ConstantTransformer<I,O>
      extends Object
      implements Transformer<I,O>, Serializable

  Transformer implementation that returns the same constant each time.

  No check is made that the object is immutable. In general, only immutable objects should use the constant factory. Mutable objects should use the prototype factory.

  Since:
    3.0
  See Also:
    Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static Transformer` | `NULL_INSTANCE` Returns null each time

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ConstantTransformer(O constantToReturn)` Constructor that performs no validation.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static <I,O> Transformer<I,O>` | `constantTransformer(O constantToReturn)` Transformer method that performs validation.
    `boolean` | `equals(Object obj)`
    `O` | `getConstant()` Gets the constant.
    `int` | `hashCode()`
    `static <I,O> Transformer<I,O>` | `nullTransformer()` Get a typed null instance.
    `O` | `transform(I input)` Transforms the input by ignoring it and returning the stored constant instead.

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### NULL_INSTANCE

          public static final Transformer NULL_INSTANCE

      Returns null each time

  - ### Constructor Detail

    - #### ConstantTransformer

          public ConstantTransformer(O constantToReturn)

      Constructor that performs no validation. Use `constantTransformer` if you want that.
      Parameters:
        `constantToReturn` - the constant to return each time

  - ### Method Detail

    - #### nullTransformer

          public static <I,O> Transformer<I,O> nullTransformer()

      Get a typed null instance.
      Type Parameters:
        `I` - the input type
        `O` - the output type
      Returns:
        Transformer<I, O> that always returns null.

    - #### constantTransformer

          public static <I,O> Transformer<I,O> constantTransformer(O constantToReturn)

      Transformer method that performs validation.
      Type Parameters:
        `I` - the input type
        `O` - the output type
      Parameters:
        `constantToReturn` - the constant object to return each time in the factory
      Returns:
        the `constant` factory.

    - #### transform

          public O transform(I input)

      Transforms the input by ignoring it and returning the stored constant instead.
      Specified by:
        `transform` in interface `Transformer<I,O>`
      Parameters:
        `input` - the input object which is ignored
      Returns:
        the stored constant

    - #### getConstant

          public O getConstant()

      Gets the constant.
      Returns:
        the constant
      Since:
        3.1

    - #### equals

          public boolean equals(Object obj)

      Overrides:
        `equals` in class `Object`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Object`

Copyright © 2001–2018 The Apache Software Foundation. All rights reserved.