org.mmbase.util.functions
Class CombinedFunction<R>

java.lang.Object
  extended by org.mmbase.util.functions.CombinedFunction<R>
All Implemented Interfaces:
Function<R>

public class CombinedFunction<R>
extends Object
implements Function<R>

A combined function combines other function objects. Depending on the provided filled paramters it calls the right function. So, it uses the function for which the provided parameters object matched best. The best match is determined by a kind of scoring mechanism. Every missing required parameter makes the function score very bad. Otherwise the rule is that the more parameters of the function are provided, the better it is.

Since:
MMBase-1.9
Version:
$Id: CombinedFunction.java 41943 2010-04-16 17:18:19Z michiel $
Author:
Michiel Meeuwissen

Constructor Summary
CombinedFunction(String name)
           
 
Method Summary
 void addFunction(Function<R> func)
           
 Parameters createParameters()
          Creates an empty 'Parameters' object for you, which you have to fill and feed back to getFunctionValue
protected  void determinDefinition()
          Combines the parameter definitions of the wrapped function to one new parameter definition
 String getDescription()
           
 R getFunctionValue(Parameters parameters)
          Executes the defined function supplying the given arguments.
 R getFunctionValueWithArgs(Object... parameters)
          A 'varargs' version of getFunctionValueWithList.
 R getFunctionValueWithList(List<?> parameters)
          Executes the defined function supplying the given List of arguments.
 String getName()
          A function must have a name.
 Parameter<?>[] getParameterDefinition()
           
 ReturnType<R> getReturnType()
           
 void setDescription(String description)
          For documentational purposes a function object needs a description too.
 void setParameterDefinition(Parameter<?>[] params)
          A function object is of no use, as long as it lacks a definition.
 void setReturnType(ReturnType<R> type)
          Sets the return type of the function's result value.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CombinedFunction

public CombinedFunction(String name)
Method Detail

addFunction

public void addFunction(Function<R> func)

createParameters

public Parameters createParameters()
Description copied from interface: Function
Creates an empty 'Parameters' object for you, which you have to fill and feed back to getFunctionValue

Specified by:
createParameters in interface Function<R>
See Also:
Function.getFunctionValue(Parameters)

getFunctionValue

public R getFunctionValue(Parameters parameters)
Description copied from interface: Function
Executes the defined function supplying the given arguments.

Specified by:
getFunctionValue in interface Function<R>
Parameters:
parameters - The parameters for the function. To specify an empty parameter list use Parameters.VOID. Implementors are encouraged to support null too.
Returns:
The function value, which can be of any type compatible to Function.getReturnType()
See Also:
Function.createParameters()

determinDefinition

protected void determinDefinition()
Combines the parameter definitions of the wrapped function to one new parameter definition


getFunctionValueWithList

public R getFunctionValueWithList(List<?> parameters)
Description copied from interface: Function
Executes the defined function supplying the given List of arguments. This is a convenience method, as the List is mapped to a Parameters type and passed to Function.getFunctionValue(Parameters).

Specified by:
getFunctionValueWithList in interface Function<R>
Parameters:
parameters - The parameters for the function. To specify an empty parameter list use Parameters.VOID.
Returns:
The function value, which can be of any type compatible to Function.getReturnType()

getFunctionValueWithArgs

public R getFunctionValueWithArgs(Object... parameters)
Description copied from interface: Function
A 'varargs' version of getFunctionValueWithList.

Specified by:
getFunctionValueWithArgs in interface Function<R>

setDescription

public void setDescription(String description)
Description copied from interface: Function
For documentational purposes a function object needs a description too.

Specified by:
setDescription in interface Function<R>

getDescription

public String getDescription()
Specified by:
getDescription in interface Function<R>
See Also:
Function.setDescription(String)

getName

public String getName()
Description copied from interface: Function
A function must have a name. This is the name which was used to aquire the function object.

Specified by:
getName in interface Function<R>
Returns:
The function's name, never null

getParameterDefinition

public Parameter<?>[] getParameterDefinition()
Specified by:
getParameterDefinition in interface Function<R>
Returns:
The currently set Parameter definition array, or null if not set already.

setParameterDefinition

public void setParameterDefinition(Parameter<?>[] params)
Description copied from interface: Function
A function object is of no use, as long as it lacks a definition.

Specified by:
setParameterDefinition in interface Function<R>
Parameters:
params - An array of Parameter objects.

getReturnType

public ReturnType<R> getReturnType()
Specified by:
getReturnType in interface Function<R>
Returns:
The return type of the function's result value, or null if unknown.

setReturnType

public void setReturnType(ReturnType<R> type)
Description copied from interface: Function
Sets the return type of the function's result value.

Specified by:
setReturnType in interface Function<R>
Parameters:
type - A ReturnType object. For void functions that could be ReturnType.VOID.

toString

public String toString()
Overrides:
toString in class Object


MMBase 2.0-SNAPSHOT - null