de.cm.frw.core.fun.impl
Class Function

java.lang.Object
  extended by de.cm.frw.core.fun.impl.Function
Direct Known Subclasses:
LP.ConsCell, NUM.Binary, NUM.BinaryTest, NUM.Unary, PF

public class Function
extends java.lang.Object


Nested Class Summary
static class Function.InvalidArguments
           
 
Constructor Summary
Function()
          The default constructor creates an unary function, i.e.
 
Method Summary
 java.lang.Object apply()
           
 java.lang.Object apply(boolean arg)
          Apply this function to a boolean
 java.lang.Object apply(boolean[] arg)
          Apply this function to a boolean array
 java.lang.Object apply(byte arg)
          Apply this function to a byte
 java.lang.Object apply(byte[] arg)
          Apply this function to a byte array
 java.lang.Object apply(char arg)
          Apply this function to a char
 java.lang.Object apply(char[] arg)
          Apply this function to a char array
 java.lang.Object apply(java.util.Collection args)
          Applies the implemented function to the passed in collection of arguments.
 java.lang.Object apply(double arg)
          Apply this function to a double
 java.lang.Object apply(double[] arg)
          Apply this function to a double array
 java.lang.Object apply(float arg)
          Apply this function to a float
 java.lang.Object apply(float[] arg)
          Apply this function to a float array
 java.lang.Object apply(int arg)
          Apply this function to an int
 java.lang.Object apply(int[] arg)
          Apply this function to an int array
 java.lang.Object apply(long arg)
          Apply this function to a long
 java.lang.Object apply(long[] arg)
          Apply this function to a long array
 java.lang.Object apply(java.lang.Object arg)
           
 java.lang.Object apply(java.lang.Object[] arg)
          Apply this function to an array of objects
 int arity()
           
static java.lang.Boolean box(boolean x)
          Create a Boolean instance from a given boolean value (aka boxing)
static java.util.Collection box(boolean[] a)
          Box a boolean array into a Bag of Booleans
static java.lang.Byte box(byte x)
          Create a Byte instance from a given byte value (aka boxing)
static java.util.Collection box(byte[] a)
          Box a byte array into a Bag of Bytes
static java.lang.Character box(char c)
          Create a Character instance from a given char value (aka boxing)
static java.util.Collection box(char[] a)
          Box a char array into a Bag of Characters
static java.lang.Double box(double x)
          Create a Double instance from a given double value (aka boxing)
static java.util.Collection box(double[] a)
          Box a double array into a Bag of Doubles
static java.lang.Float box(float x)
          Create a Float instance from a given float value (aka boxing)
static java.util.Collection box(float[] a)
          Box a float array into a Bag of Floats
static java.lang.Integer box(int x)
          Create a Integer instance from a given int value (aka boxing)
static java.util.Collection box(int[] a)
          Box an int array into a Bag of Integers
static java.lang.Long box(long x)
          Create a Long instance from a given long value (aka boxing)
static java.util.Collection box(long[] a)
          Box a long array into a Bag of Longs
static java.util.Collection box(java.lang.Object[] a)
          Box an array of objects into a Bag
 void checkArguments(java.util.Collection args)
          Override this method to check conditions on the arguments (like types) passed to the function in apply before the operate method is called.
static boolean is(java.lang.Object x)
          Return the boolean value of a given Boolean x as double
static void main(java.lang.String[] args)
           
 java.lang.Iterable map(java.util.Collection args)
           
static java.lang.Iterable map(Function f, java.lang.Iterable args)
           
 java.lang.Object operate(java.lang.Object[] operands)
          Override this to implement the actual operation realized by this function.
static java.lang.Object reduce(java.lang.Iterable args, Function f, java.lang.Object initial)
           
static int unbox(java.lang.Integer i)
           
static double val(java.lang.Object x)
          Return the value of a given number x as double
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Function

public Function()
The default constructor creates an unary function, i.e. a function that requires at least one argument.

Method Detail

apply

public java.lang.Object apply(java.util.Collection args)
                       throws Function.InvalidArguments
Applies the implemented function to the passed in collection of arguments. Checks number of arguments against arity (args.size() < arity ==> fail) and calls checkArguments to perform checks as implemented there.

Parameters:
args - A collection of arguments
Returns:
The function result.
Throws:
Function.InvalidArguments

apply

public java.lang.Object apply()
                       throws Function.InvalidArguments
Throws:
Function.InvalidArguments

apply

public java.lang.Object apply(java.lang.Object arg)
                       throws Function.InvalidArguments
Throws:
Function.InvalidArguments

apply

public final java.lang.Object apply(boolean arg)
                             throws Function.InvalidArguments
Apply this function to a boolean

Parameters:
arg - a boolean
Returns:
The function result as an Object
Throws:
Function.InvalidArguments - if this function is not applicable to arg

apply

public final java.lang.Object apply(boolean[] arg)
                             throws Function.InvalidArguments
Apply this function to a boolean array

Parameters:
arg - a boolean array
Returns:
The function result as an Object
Throws:
Function.InvalidArguments - if this function is not applicable to arg

apply

public final java.lang.Object apply(byte arg)
                             throws Function.InvalidArguments
Apply this function to a byte

Parameters:
arg - a byte
Returns:
The function result as an Object
Throws:
Function.InvalidArguments - if this function is not applicable to arg

apply

public final java.lang.Object apply(byte[] arg)
                             throws Function.InvalidArguments
Apply this function to a byte array

Parameters:
arg - a byte array
Returns:
The function result as an Object
Throws:
Function.InvalidArguments - if this function is not applicable to arg

apply

public final java.lang.Object apply(char arg)
                             throws Function.InvalidArguments
Apply this function to a char

Parameters:
arg - a char
Returns:
The function result as an Object
Throws:
Function.InvalidArguments - if this function is not applicable to arg

apply

public final java.lang.Object apply(char[] arg)
                             throws Function.InvalidArguments
Apply this function to a char array

Parameters:
arg - a char array
Returns:
The function result as an Object
Throws:
Function.InvalidArguments - if this function is not applicable to arg

apply

public final java.lang.Object apply(float arg)
                             throws Function.InvalidArguments
Apply this function to a float

Parameters:
arg - a fload
Returns:
The function result as an Object
Throws:
Function.InvalidArguments - if this function is not applicable to arg

apply

public final java.lang.Object apply(float[] arg)
                             throws Function.InvalidArguments
Apply this function to a float array

Parameters:
arg - a float array
Returns:
The function result as an Object
Throws:
Function.InvalidArguments - if this function is not applicable to arg

apply

public final java.lang.Object apply(double arg)
                             throws Function.InvalidArguments
Apply this function to a double

Parameters:
arg - a double
Returns:
The function result as an Object
Throws:
Function.InvalidArguments - if this function is not applicable to arg

apply

public final java.lang.Object apply(double[] arg)
                             throws Function.InvalidArguments
Apply this function to a double array

Parameters:
arg - a double array
Returns:
The function result as an Object
Throws:
Function.InvalidArguments - if this function is not applicable to arg

apply

public final java.lang.Object apply(int arg)
                             throws Function.InvalidArguments
Apply this function to an int

Parameters:
arg - an int
Returns:
The function result as an Object
Throws:
Function.InvalidArguments - if this function is not applicable to arg

apply

public final java.lang.Object apply(int[] arg)
                             throws Function.InvalidArguments
Apply this function to an int array

Parameters:
arg - an int array
Returns:
The function result as an Object
Throws:
Function.InvalidArguments - if this function is not applicable to arg

apply

public final java.lang.Object apply(long arg)
                             throws Function.InvalidArguments
Apply this function to a long

Parameters:
arg - a long
Returns:
The function result as an Object
Throws:
Function.InvalidArguments - if this function is not applicable to arg

apply

public final java.lang.Object apply(long[] arg)
                             throws Function.InvalidArguments
Apply this function to a long array

Parameters:
arg - a long array
Returns:
The function result as an Object
Throws:
Function.InvalidArguments - if this function is not applicable to arg

apply

public final java.lang.Object apply(java.lang.Object[] arg)
                             throws Function.InvalidArguments
Apply this function to an array of objects

Parameters:
arg - the array of objects
Returns:
The function result as an Object
Throws:
Function.InvalidArguments - if this function is not applicable to arg

checkArguments

public void checkArguments(java.util.Collection args)
                    throws Function.InvalidArguments
Override this method to check conditions on the arguments (like types) passed to the function in apply before the operate method is called. Throw the declared exception with a meaningful message when condition are not met. Note: Number of arguments < arity is checked before this is called to have enough arguments to operate on, however if more is no good, check it here ... Default implementation does nothing.

Parameters:
args -
Throws:
Function.InvalidArguments

operate

public java.lang.Object operate(java.lang.Object[] operands)
                         throws Function.InvalidArguments
Override this to implement the actual operation realized by this function.

Remember to document the number and types of the operands and any other conditions for running the operate method. Or implement checkArguments instead.

Default implementation returns first argument passed in, realizing sort of an unary identity function.

Parameters:
operands - An array of the arguments that where passed to apply
Returns:
An object as a result of the operation
Throws:
Function.InvalidArguments - when you implement it to do so ...

map

public static java.lang.Iterable map(Function f,
                                     java.lang.Iterable args)
                              throws Function.InvalidArguments
Throws:
Function.InvalidArguments

reduce

public static java.lang.Object reduce(java.lang.Iterable args,
                                      Function f,
                                      java.lang.Object initial)
                               throws Function.InvalidArguments
Throws:
Function.InvalidArguments

main

public static void main(java.lang.String[] args)
Parameters:
args -

unbox

public static int unbox(java.lang.Integer i)

map

public java.lang.Iterable map(java.util.Collection args)
                       throws Function.InvalidArguments
Throws:
Function.InvalidArguments

arity

public int arity()

box

public static java.lang.Boolean box(boolean x)
Create a Boolean instance from a given boolean value (aka boxing)

Parameters:
x - a boolean value
Returns:
a new Boolean instance for x

box

public static java.util.Collection box(boolean[] a)
Box a boolean array into a Bag of Booleans

Parameters:
a - a boolean array
Returns:
a new Bag instance containing a Boolean for each member of a

box

public static java.lang.Byte box(byte x)
Create a Byte instance from a given byte value (aka boxing)

Parameters:
x - a byte value
Returns:
a new Byte instance for x

box

public static java.util.Collection box(byte[] a)
Box a byte array into a Bag of Bytes

Parameters:
a - a byte array
Returns:
a new Bag instance containing a Byte for each member of a

box

public static java.lang.Character box(char c)
Create a Character instance from a given char value (aka boxing)

Parameters:
x - a chat value
Returns:
a new Character instance for x

box

public static java.util.Collection box(char[] a)
Box a char array into a Bag of Characters

Parameters:
a - a char array
Returns:
a new Bag instance containing a Character for each member of a

box

public static java.lang.Double box(double x)
Create a Double instance from a given double value (aka boxing)

Parameters:
x - an double value
Returns:
a new Double instance for x

box

public static java.util.Collection box(double[] a)
Box a double array into a Bag of Doubles

Parameters:
a - a double array
Returns:
a new Bag instance containing a Double for each member of a

box

public static java.lang.Float box(float x)
Create a Float instance from a given float value (aka boxing)

Parameters:
x - a float value
Returns:
a new Float instance for x

box

public static java.util.Collection box(float[] a)
Box a float array into a Bag of Floats

Parameters:
a - a float array
Returns:
a new Bag instance containing a Float for each member of a

box

public static java.lang.Integer box(int x)
Create a Integer instance from a given int value (aka boxing)

Parameters:
x - an int value
Returns:
a new Integer instance for x

box

public static java.util.Collection box(int[] a)
Box an int array into a Bag of Integers

Parameters:
a - an integer array
Returns:
a new Bag instance containing an Integer for each member of a

box

public static java.lang.Long box(long x)
Create a Long instance from a given long value (aka boxing)

Parameters:
x - a lonv value
Returns:
a new Long instance for x

box

public static java.util.Collection box(long[] a)
Box a long array into a Bag of Longs

Parameters:
a - a long array
Returns:
a new Bag instance containing a Long for each member of a

val

public static double val(java.lang.Object x)
                  throws Function.InvalidArguments
Return the value of a given number x as double

Parameters:
x - the number (instance of Number)
Returns:
the double value of x
Throws:
Function.InvalidArguments - if x is not a Number instance

is

public static boolean is(java.lang.Object x)
                  throws Function.InvalidArguments
Return the boolean value of a given Boolean x as double

Parameters:
x - the Boolean instance
Returns:
the boolean value of x
Throws:
Function.InvalidArguments - if x is not a Boolean instance

box

public static java.util.Collection box(java.lang.Object[] a)
Box an array of objects into a Bag

Parameters:
a - the array of objects
Returns:
a new Bag instance containing each member of a