Coinjema
1.7

org.coinjema.util
Class Functor<R>

java.lang.Object
  extended by org.coinjema.util.Functor<R>
All Implemented Interfaces:
Runnable, Callable<R>, Invokable<R>, InvokableOn<R>, InvokableWith<R>
Direct Known Subclasses:
DependencyFunctor

public class Functor<R>
extends Object
implements InvokableOn<R>, Callable<R>, Runnable

The functor allows an easy way to setup dynamic methods that can be passed around and efficiently invoked. The functor is easier to use than jdk Method objects as it will figure out where to find the method that you want to invoke. For instance, if you are calling a method with objects that extend the class type of the arguments to that method, Functor will still find the correct method to invoke.

Author:
mstover

Constructor Summary
Functor()
           
Functor(Object invokee, String methodName)
           
Functor(Object invokee, String methodName, Class... types)
           
Functor(Object invokee, String methodName, Object... args)
           
Functor(Object invokee, String methodName, Object[] args, Class... types)
           
Functor(String methodName)
           
Functor(String methodName, Class... types)
           
Functor(String methodName, Class[] types, Object[] args)
           
Functor(String methodName, Object... args)
           
Functor(String methodName, String oneArg)
           
 
Method Summary
 R call()
           
 Method createMethod(Object invokee, Class... types)
           
 String getMethodName()
           
 R invoke()
           
 R invoke(Object invokee, Object... args)
           
 R invokeOn(Object invokee)
           
 R invokeWith(Object... args)
           
 Functor<R> postChain(Functor<R> f)
          If a post chain is added to a functor, then the chained functor will be run on the resulting object of this functor.
 Functor<R> postChain(Object invokee, String methodName)
           
 Functor<R> postChain(String methodName)
           
 Functor<R> preChain(Functor<?> f)
          If a pre chain is added to a functor, then the chained functor will be run and the results passed into this functor to invoke on.
 Functor preChain(Object invokee, String methodName)
           
 Functor preChain(Object invokee, String methodName, Object... args)
           
 Functor preChain(String methodName)
           
 Functor preChain(String methodName, Object... args)
           
 void run()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Functor

public Functor()

Functor

public Functor(Object invokee,
               String methodName)

Functor

public Functor(Object invokee,
               String methodName,
               Class... types)

Functor

public Functor(String methodName)

Functor

public Functor(String methodName,
               Class... types)

Functor

public Functor(String methodName,
               Class[] types,
               Object[] args)

Functor

public Functor(String methodName,
               Object... args)

Functor

public Functor(String methodName,
               String oneArg)

Functor

public Functor(Object invokee,
               String methodName,
               Object... args)

Functor

public Functor(Object invokee,
               String methodName,
               Object[] args,
               Class... types)
Method Detail

run

public void run()
Specified by:
run in interface Runnable

invoke

public R invoke(Object invokee,
                Object... args)
Specified by:
invoke in interface InvokableOn<R>

call

public R call()
Specified by:
call in interface Callable<R>

invokeOn

public R invokeOn(Object invokee)
Specified by:
invokeOn in interface InvokableOn<R>

invokeWith

public R invokeWith(Object... args)
Specified by:
invokeWith in interface InvokableWith<R>

invoke

public R invoke()
Specified by:
invoke in interface Invokable<R>

createMethod

public Method createMethod(Object invokee,
                           Class... types)

getMethodName

public String getMethodName()
Returns:
Returns the methodName.

postChain

public Functor<R> postChain(Functor<R> f)
If a post chain is added to a functor, then the chained functor will be run on the resulting object of this functor.

Ie: Assume, Functor A, Functor B,Functor C.
Given: A.postChain(B).postChain(C)
A.invokeOn(myObj) is equivalent to C.invokeOn(B.invokeOn(A.invokeOn(myObj)))
A.invokeWith(objArray) is equivalent to C.invokeOn(B.invokeOn(A.invokeWith(objArray)))

Parameters:
f -

postChain

public Functor<R> postChain(String methodName)

postChain

public Functor<R> postChain(Object invokee,
                            String methodName)

preChain

public Functor<R> preChain(Functor<?> f)
If a pre chain is added to a functor, then the chained functor will be run and the results passed into this functor to invoke on.

Ie: Assume, Functor A, Functor B,Functor C.
Given: A.preChain(B).preChain(C)
A.invoke() is equivalent to A.invoke(B.invoke(C.invoke()))
A.invokeWith(objArray) is equivalent to A.invokeWith(B.invoke(C.invoke()),objArray)
A.invokeOn(invokee) is equivalent to A.invokeOn(invokee,new Object[]{B.invoke(C.invoke())})

Parameters:
f -

preChain

public Functor preChain(String methodName)

preChain

public Functor preChain(String methodName,
                        Object... args)

preChain

public Functor preChain(Object invokee,
                        String methodName)

preChain

public Functor preChain(Object invokee,
                        String methodName,
                        Object... args)

Coinjema
1.7

Public Domain Software.