org.apache.jorphan.reflect

## Class Functor

- java.lang.Object
- - org.apache.jorphan.reflect.Functor

- Direct Known Subclasses:
    TableVisualizer.SampleSuccessFunctor

      public class Functor
      extends java.lang.Object

  Implements function call-backs.

  Functors may be defined for instance objects or classes.

  The method is created on first use, which allows the invokee (class or instance) to be omitted from the constructor.

  The class name takes precedence over the instance.

  If a functor is created with a particular instance, then that is used for all future calls; if an object is provided, it is ignored. This allows easy override of the table model behaviour.

  If an argument list is provided in the constructor, then that is ignored in subsequent invoke() calls.

  Usage:

       f = new Functor("methodName");
       o = f.invoke(object); // - OR -
       o = f.invoke(object, params);

       f2 = new Functor(object, "methodName");
       o = f2.invoke(); // - OR -
       o = f2.invoke(params);

       f3 = new Functor(class, "methodName");
       o = f3.invoke(object); // - will be ignored
       o = f3.invoke(); // - OR -
       o = f3.invoke(params);
       o = f3.invoke(object, params); // - object will be ignored

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `Functor(java.lang.Class<?> _clazz, java.lang.String _methodName)` Create a functor from class and method name.
    `Functor(java.lang.Class<?> _clazz, java.lang.String _methodName, java.lang.Class<?>[] _types)` Create a functor with the class, method name, and argument class types.
    `Functor(java.lang.Object _invokee, java.lang.String _methodName)` Create a functor with the invokee and a method name.
    `Functor(java.lang.Object _invokee, java.lang.String _methodName, java.lang.Class<?>[] _types)` Create a functor with the invokee, method name, and argument class types.
    `Functor(java.lang.Object _invokee, java.lang.String _methodName, java.lang.Object[] _args)` Create a functor with an invokee, method name, and argument values.
    `Functor(java.lang.String _methodName)` Create a functor with just the method name.
    `Functor(java.lang.String _methodName, java.lang.Class<?>[] _types)` Create a functor with the method name and argument class types.
    `Functor(java.lang.String _methodName, java.lang.Object[] _args)` Create a functor from method name and arguments.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `checkMethod(java.lang.Object _invokee)` Deprecated. ** for use by Unit test code only **
    `boolean` | `checkMethod(java.lang.Object _invokee, java.lang.Class<?> c)` Deprecated. ** for use by Unit test code only **
    `java.lang.Object` | `invoke()` Invoke a Functor, which must have been created with either a class name or object.
    `java.lang.Object` | `invoke(java.lang.Object p_invokee)` Invoke the method on a given object.
    `java.lang.Object` | `invoke(java.lang.Object[] p_args)` Invoke the method with the provided parameters.
    `java.lang.Object` | `invoke(java.lang.Object p_invokee, java.lang.Object[] p_args)` Invoke the method on the invokee with the provided parameters.
    `java.lang.String` | `toString()`

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

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

- - ### Constructor Detail

    - #### Functor

          public Functor(java.lang.Object _invokee,
                         java.lang.String _methodName)

      Create a functor with the invokee and a method name. The invokee will be used in all future invoke calls.
      Parameters:
        `_invokee` - object on which to invoke the method
        `_methodName` - method name

    - #### Functor

          public Functor(java.lang.Class<?> _clazz,
                         java.lang.String _methodName)

      Create a functor from class and method name. This is useful for methods defined in interfaces. The actual invokee must be provided in all invoke() calls, and must be an instance of the class.
      Parameters:
        `_clazz` - class to be used
        `_methodName` - method name

    - #### Functor

          public Functor(java.lang.Object _invokee,
                         java.lang.String _methodName,
                         java.lang.Class<?>[] _types)

      Create a functor with the invokee, method name, and argument class types. The invokee will be ignored in any invoke() calls.
      Parameters:
        `_invokee` - object on which to invoke the method
        `_methodName` - method name
        `_types` - types of arguments to be used

    - #### Functor

          public Functor(java.lang.Class<?> _clazz,
                         java.lang.String _methodName,
                         java.lang.Class<?>[] _types)

      Create a functor with the class, method name, and argument class types. Subsequent invoke() calls must provide the appropriate invokee object.
      Parameters:
        `_clazz` - the class in which to find the method
        `_methodName` - method name
        `_types` - types of arguments to be used

    - #### Functor

          public Functor(java.lang.String _methodName)

      Create a functor with just the method name. The invokee and any parameters must be provided in all invoke() calls.
      Parameters:
        `_methodName` - method name

    - #### Functor

          public Functor(java.lang.String _methodName,
                         java.lang.Class<?>[] _types)

      Create a functor with the method name and argument class types. The invokee must be provided in all invoke() calls
      Parameters:
        `_methodName` - method name
        `_types` - parameter types

    - #### Functor

          public Functor(java.lang.Object _invokee,
                         java.lang.String _methodName,
                         java.lang.Object[] _args)

      Create a functor with an invokee, method name, and argument values. The invokee will be ignored in any invoke() calls.
      Parameters:
        `_invokee` - object on which to invoke the method
        `_methodName` - method name
        `_args` - arguments to be passed to the method

    - #### Functor

          public Functor(java.lang.String _methodName,
                         java.lang.Object[] _args)

      Create a functor from method name and arguments. The class will be determined from the first invoke call. All invoke calls must include a target object; which must be of the same type as the initial invokee.
      Parameters:
        `_methodName` - method name
        `_args` - arguments to be used

  - ### Method Detail

    - #### invoke

          public java.lang.Object invoke()

      Invoke a Functor, which must have been created with either a class name or object.
      Returns:
        the object if any

    - #### invoke

          public java.lang.Object invoke(java.lang.Object p_invokee)

      Invoke the method on a given object.
      Parameters:
        `p_invokee` - - provides the object to call; ignored if the class or object were provided to the constructor
      Returns:
        the value

    - #### invoke

          public java.lang.Object invoke(java.lang.Object[] p_args)

      Invoke the method with the provided parameters. The invokee must have been provided in the constructor.
      Parameters:
        `p_args` - parameters for the method
      Returns:
        the value

    - #### invoke

          public java.lang.Object invoke(java.lang.Object p_invokee,
                                         java.lang.Object[] p_args)

      Invoke the method on the invokee with the provided parameters. The invokee must agree with the class (if any) provided at construction time. If the invokee was provided at construction time, then this invokee will be ignored. If actual arguments were provided at construction time, then arguments will be ignored.
      Parameters:
        `p_invokee` - invokee to use, if no class or invokee was provided at construction time
        `p_args` - arguments to use
      Returns:
        result of invocation

    - #### checkMethod

          @Deprecated
          public boolean checkMethod(java.lang.Object _invokee)

      Deprecated. ** for use by Unit test code only **
      Check if a read Functor method is valid.
      Parameters:
        `_invokee` - instance on which the method should be tested
      Returns:
        `true` if method exists

    - #### checkMethod

          @Deprecated
          public boolean checkMethod(java.lang.Object _invokee,
                                                 java.lang.Class<?> c)

      Deprecated. ** for use by Unit test code only **
      Check if a write Functor method is valid.
      Parameters:
        `_invokee` - instance on which the method should be tested
        `c` - type of parameter
      Returns:
        `true` if method exists

    - #### toString

          public java.lang.String toString()

      Overrides:
        `toString` in class `java.lang.Object`

Copyright © 1998-2018 Apache Software Foundation. All Rights Reserved.