org.op4j.functions
Interface IFunction<T,R>

All Known Implementing Classes:
AbstractNotNullFunction, AbstractNullAsNullFunction, Call, ExpressionFunction, Function, Get, MapBuilder

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).

Since:
1.0
Author:
Daniel Fernández

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

execute

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.

Parameters:
input - the target object on which the function is to be executed
ctx - the context (metadata) for the function execution
Returns:
the result of executing the function
Throws:
Exception


Copyright © 2012 The OP4J team. All Rights Reserved.