Class ConstantTransformer<T,R>
- java.lang.Object
-
- org.apache.commons.collections4.functors.ConstantTransformer<T,R>
-
- Type Parameters:
T- the type of the input to the function.R- the type of the result of the function.
- All Implemented Interfaces:
java.io.Serializable,java.util.function.Function<T,R>,Transformer<T,R>
public class ConstantTransformer<T,R> extends java.lang.Object implements Transformer<T,R>, java.io.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 Description static TransformerNULL_INSTANCEReturns null each time
-
Constructor Summary
Constructors Constructor Description ConstantTransformer(R constantToReturn)Constructor that performs no validation.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <I,O>
Transformer<I,O>constantTransformer(O constantToReturn)Transformer method that performs validation.booleanequals(java.lang.Object obj)RgetConstant()Gets the constant.inthashCode()static <I,O>
Transformer<I,O>nullTransformer()Gets a typed null instance.Rtransform(T 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
-
Methods inherited from interface org.apache.commons.collections4.Transformer
apply
-
-
-
-
Field Detail
-
NULL_INSTANCE
public static final Transformer NULL_INSTANCE
Returns null each time
-
-
Constructor Detail
-
ConstantTransformer
public ConstantTransformer(R constantToReturn)
Constructor that performs no validation. UseconstantTransformerif you want that.- Parameters:
constantToReturn- the constant to return each time
-
-
Method Detail
-
constantTransformer
public static <I,O> Transformer<I,O> constantTransformer(O constantToReturn)
Transformer method that performs validation.- Type Parameters:
I- the input typeO- the output type- Parameters:
constantToReturn- the constant object to return each time in the factory- Returns:
- the
constantfactory.
-
nullTransformer
public static <I,O> Transformer<I,O> nullTransformer()
Gets a typed null instance.- Type Parameters:
I- the input typeO- the output type- Returns:
- Transformer<I, O> that always returns null.
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
getConstant
public R getConstant()
Gets the constant.- Returns:
- the constant
- Since:
- 3.1
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-