Package org.apache.commons.collections4.functors

# Class InvokerTransformer<T,R>

java.lang.Object
org.apache.commons.collections4.functors.InvokerTransformer<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:
  `Function<T,R>`, `Transformer<T,R>`

public class InvokerTransformer<T,R> extends Object implements Transformer<T,R>
Transformer implementation that creates a new object instance by reflection.

WARNING: from v4.1 onwards this class will not be serializable anymore in order to prevent potential remote code execution exploits. Please refer to COLLECTIONS-580 for more details.

Since:
  3.0

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `InvokerTransformer(String methodName, Class<?>[] paramTypes, Object[] args)`
  Constructor that performs no validation.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static <I, O> Transformer<I,O>`
  `invokerTransformer(String methodName)`
  Gets an instance of this transformer calling a specific method with no arguments.
  `static <I, O> Transformer<I,O>`
  `invokerTransformer(String methodName, Class<?>[] paramTypes, Object[] args)`
  Gets an instance of this transformer calling a specific method with specific values.
  `R`
  `transform(Object input)`
  Transforms the input to result by invoking a method on the input.

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

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

  ### Methods inherited from interface java.util.function.Function

  `andThen, compose`

  ### Methods inherited from interface org.apache.commons.collections4.Transformer

  `apply`

- ## Constructor Details

  - ### InvokerTransformer

    public InvokerTransformer(String methodName, Class<?>[] paramTypes, Object[] args)
    Constructor that performs no validation. Use `invokerTransformer` if you want that.

    Note: from 4.0, the input parameters will be cloned

    Parameters:
      `methodName` - The method to call
      `paramTypes` - The constructor parameter types
      `args` - The constructor arguments

- ## Method Details

  - ### invokerTransformer

    public static <I, O> Transformer<I,O> invokerTransformer(String methodName)
    Gets an instance of this transformer calling a specific method with no arguments.
    Type Parameters:
      `I` - the input type
      `O` - the output type
    Parameters:
      `methodName` - The method name to call
    Returns:
      An invoker transformer
    Throws:
      `NullPointerException` - if methodName is null
    Since:
      3.1

  - ### invokerTransformer

    public static <I, O> Transformer<I,O> invokerTransformer(String methodName, Class<?>[] paramTypes, Object[] args)
    Gets an instance of this transformer calling a specific method with specific values.
    Type Parameters:
      `I` - the input type
      `O` - the output type
    Parameters:
      `methodName` - The method name to call
      `paramTypes` - The parameter types of the method
      `args` - The arguments to pass to the method
    Returns:
      An invoker transformer
    Throws:
      `NullPointerException` - if methodName is null
      `IllegalArgumentException` - if paramTypes does not match args

  - ### transform

    public R transform(Object input)
    Transforms the input to result by invoking a method on the input.
    Specified by:
      `transform` in interface `Transformer<T,R>`
    Parameters:
      `input` - The input object to transform
    Returns:
      The transformed result, null if null input