info.javelot.functionalj
Class ComposedFunction

java.lang.Object
  extended byinfo.javelot.functionalj.Function
      extended byinfo.javelot.functionalj.ReflectionFunction
          extended byinfo.javelot.functionalj.MethodFunction
              extended byinfo.javelot.functionalj.ComposedFunction
All Implemented Interfaces:
Serializable

public class ComposedFunction
extends MethodFunction

Combines two functions where the result of one function is used as a parameter to the other function.

Author:
Copyright © 2006 Frederic Daoud
See Also:
Serialized Form

Field Summary
 
Fields inherited from class info.javelot.functionalj.Function
m_class, m_name, m_object, m_parameters, m_targets
 
Constructor Summary
ComposedFunction(Function p_f, Function p_g)
          Constructs a composed function with two functions, such that, given functions f and g, the resulting function is f o g, where 'o' is the composing operator as used in mathematics.
ComposedFunction(Function p_f, Function p_g, Function p_h)
          Constructs a composed function with two functions, such that, given functions f, g and h, the resulting function is f o g o h, where 'o' is the composing operator as used in mathematics.
 
Method Summary
 Function addParameters(Object[] p_parameters)
          Returns a new ComposedFunction with the original f function, and a new g function on which the addParameters(Object[]) has been invoked.
 Object call()
          Invokes call() on the g function, supplies the result to the f function using objectOrParameter(Object), invokes call() on the resulting function, and returns the result.
 boolean isObjectPresent()
          Returns the value of g.isObjectPresent().
 boolean isObjectRequired()
          Returns the value of g.isObjectRequired().
protected  Function newInstance(Class p_class, Object[] p_parameters)
          Returns a new ComposedFunction object with the same f function and the value of g.newInstance(Class,Object[]), using g's target class.
 Function object(Object p_object)
          Returns a new ComposedFunction with the original f function, and a new g function on which the object(Object) has been invoked.
 String toString()
          Returns a String representation of the Function objects of which this function is composed.
 
Methods inherited from class info.javelot.functionalj.MethodFunction
getAllTargets, getInsertIndex, getParameterTypes, invoke
 
Methods inherited from class info.javelot.functionalj.Function
addParameter, addParameters, addParameters, addParameters, addParameters, getName, getObject, getParameters, getTargetClass, getTargets, objectOrParameter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ComposedFunction

public ComposedFunction(Function p_f,
                        Function p_g)
                 throws FunctionException
Constructs a composed function with two functions, such that, given functions f and g, the resulting function is f o g, where 'o' is the composing operator as used in mathematics. Therefore, calling the resulting function is equivalent to calling f.objectOrParameter(g.call()).call().

Throws:
FunctionException - thrown if either of the two functions supplied is null.

ComposedFunction

public ComposedFunction(Function p_f,
                        Function p_g,
                        Function p_h)
                 throws FunctionException
Constructs a composed function with two functions, such that, given functions f, g and h, the resulting function is f o g o h, where 'o' is the composing operator as used in mathematics. Therefore, calling the resulting function is equivalent to calling f.objectOrParameter(g.objectOrParameter(h.call()).call()).call().

Throws:
FunctionException - thrown if either of the three functions supplied is null.
Method Detail

isObjectRequired

public boolean isObjectRequired()
Returns the value of g.isObjectRequired().

Specified by:
isObjectRequired in class Function
Returns:
the value returned by isObjectRequired() of the g function.

isObjectPresent

public boolean isObjectPresent()
Returns the value of g.isObjectPresent().

Overrides:
isObjectPresent in class Function
Returns:
the value returned by isObjectPresent() of the g function.

newInstance

protected Function newInstance(Class p_class,
                               Object[] p_parameters)
Returns a new ComposedFunction object with the same f function and the value of g.newInstance(Class,Object[]), using g's target class.

Specified by:
newInstance in class Function
Parameters:
p_class - the class of the target.
p_parameters - the parameters that have been supplied.
Returns:
a new ComposedFunction object with the same f function and the value returned by newInstance(Class,Object[]) of the g function using g's target class.

addParameters

public Function addParameters(Object[] p_parameters)
                       throws FunctionException
Returns a new ComposedFunction with the original f function, and a new g function on which the addParameters(Object[]) has been invoked.

Overrides:
addParameters in class Function
Parameters:
p_parameters - the parameters to be added to the list of parameters that are supplied to the function.
Returns:
a new Function object with the parameters added to the list of supplied parameters.
Throws:
FunctionException - thrown if the additional parameters cause the list of supplied parameters not to match any of the possible targets.

object

public Function object(Object p_object)
                throws FunctionException
Returns a new ComposedFunction with the original f function, and a new g function on which the object(Object) has been invoked.

Specified by:
object in class Function
Throws:
FunctionException

call

public Object call()
            throws FunctionException
Invokes call() on the g function, supplies the result to the f function using objectOrParameter(Object), invokes call() on the resulting function, and returns the result.

Overrides:
call in class ReflectionFunction
Returns:
the result of f.objectOrParameter(g.call()).call().
Throws:
FunctionException - thrown if an exception occurs when invoking the target, if an object on which to invoke the target is required but none has been supplied, or if all of the potential targets expect more parameters than have been supplied.

toString

public String toString()
Returns a String representation of the Function objects of which this function is composed.

Overrides:
toString in class Function
Returns:
a String representation of the Function objects of which this function is composed, by calling Function.toString() on each function.
See Also:
Function.toString().