|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface IFunction<T,R>
The interface that every function in op4j must implement. IFunction<T,R> means that the function receives an object of type T (called target) and returns an object of type R.
This interface only defines one method: execute(Object, ExecCtx)
,
which receives the target object on which the function will be executed
and an ExecCtx
object containing some metadata about the
execution (for example, the index in an iteration).
When creating an implementation class, any function parameters should be arguments to the implementation's constructor.
Functions can be created anonymously:
String result = Op.on(value).exec(new IFunction() { public String execute(Integer input, ExecCtx ctx) throws Exception { return "The input number is: " + input; } }).get();
If you are creating a function class (instead of an anonymous implementation),
you should consider extending the Function
abstract class, which
includes an easier-to-use Function.execute(Object)
method for executing
the function outside an op4j expression (if needed).
Method Summary | |
---|---|
R |
execute(T input,
ExecCtx ctx)
Executes the function on the current target object, which is passed as the input parameter. |
Method Detail |
---|
R execute(T input, ExecCtx ctx) throws Exception
Executes the function on the current target object, which is passed
as the input parameter. The ExecCtx
parameter
provides some metadata related to the execution, like the index in
an iteration.
The execution of a function can throw any exception.
If you intend to call the execute method directly on any of
your functions (outside an op4j expression), you might prefer using
Function.execute(Object)
instead.
input
- the target object on which the function is to be executedctx
- the context (metadata) for the function execution
Exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |