Back to index

wims  3.65+svn20090927
Public Member Functions | Private Attributes
org.javia.arity.Function Class Reference

Abstract base class for functions. More...

Inheritance diagram for org.javia.arity.Function:
Inheritance graph
[legend]

List of all members.

Public Member Functions

int arity ()
 Gives the arity of this function.
double eval () throws ArityException
 Evaluates an arity-0 function (a function with no arguments).
double eval (double x) throws ArityException
double eval (double x, double y) throws ArityException
double eval (double args[]) throws ArityException
 Evaluates the function given the argument values.
int arity ()
 Gives the arity of this function.
double eval () throws ArityException
 Evaluates an arity-0 function (a function with no arguments).
double eval (double x) throws ArityException
double eval (double x, double y) throws ArityException
double eval (double args[]) throws ArityException
 Evaluates the function given the argument values.

Private Attributes

int cachedArity = -1

Detailed Description

Abstract base class for functions.

A function has an arity (the number of arguments), and a way for evaluation given the values of the arguments.

Derive from this class to create user-defined functions.

Thread safety

Assuming the user didn't subclass Function to define user functions, the compiled Functions are thread-safe (the same Function instance can be evaluated from multiple threads without locking).

Whatsmore, parallel evaluations of the same instance from multiple threads are not serialized (good).

If the user subclasses Function, he is responsible for the thread-safety of his user-defined Functions.

Definition at line 37 of file Function.java.


Member Function Documentation

Gives the arity of this function.

Returns:
the arity (the number of arguments). Arity >= 0.

Reimplemented in org.javia.arity.CompiledFunction, and org.javia.arity.CompiledFunction.

Definition at line 44 of file Function.java.

                       {
        if (cachedArity == -1) {
            cachedArity = 0;
            for (int i = 0; i < 5; ++i) {
                double args[] = new double[i];
                try {
                    eval(args);
                    cachedArity = i;
                    break;
                } catch (ArityException e) {
                    //ignore, continue
                }
            }
        }
        return cachedArity;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Gives the arity of this function.

Returns:
the arity (the number of arguments). Arity >= 0.

Reimplemented in org.javia.arity.CompiledFunction, and org.javia.arity.CompiledFunction.

Definition at line 44 of file Function.java.

                       {
        if (cachedArity == -1) {
            cachedArity = 0;
            for (int i = 0; i < 5; ++i) {
                double args[] = new double[i];
                try {
                    eval(args);
                    cachedArity = i;
                    break;
                } catch (ArityException e) {
                    //ignore, continue
                }
            }
        }
        return cachedArity;
    }

Here is the call graph for this function:

double org.javia.arity.Function.eval ( ) throws ArityException [inline]

Evaluates an arity-0 function (a function with no arguments).

Returns:
the value of the function

Reimplemented in org.javia.arity.CompiledFunction, org.javia.arity.CompiledFunction, org.javia.arity.Constant, and org.javia.arity.Constant.

Definition at line 65 of file Function.java.

                                               {
        throw new ArityException("Didn't expect 0 args");
    }

Here is the caller graph for this function:

double org.javia.arity.Function.eval ( ) throws ArityException [inline]

Evaluates an arity-0 function (a function with no arguments).

Returns:
the value of the function

Reimplemented in org.javia.arity.CompiledFunction, org.javia.arity.CompiledFunction, org.javia.arity.Constant, and org.javia.arity.Constant.

Definition at line 65 of file Function.java.

                                               {
        throw new ArityException("Didn't expect 0 args");
    }
double org.javia.arity.Function.eval ( double  x) throws ArityException [inline]

Reimplemented in org.javia.arity.CompiledFunction, and org.javia.arity.CompiledFunction.

Definition at line 69 of file Function.java.

                                                       {
        throw new ArityException("Didn't expect 1 args");
    }
double org.javia.arity.Function.eval ( double  x) throws ArityException [inline]

Reimplemented in org.javia.arity.CompiledFunction, and org.javia.arity.CompiledFunction.

Definition at line 69 of file Function.java.

                                                       {
        throw new ArityException("Didn't expect 1 args");
    }
double org.javia.arity.Function.eval ( double  x,
double  y 
) throws ArityException [inline]

Reimplemented in org.javia.arity.CompiledFunction, and org.javia.arity.CompiledFunction.

Definition at line 73 of file Function.java.

                                                                 {
        throw new ArityException("Didn't expect 2 args");
    }
double org.javia.arity.Function.eval ( double  x,
double  y 
) throws ArityException [inline]

Reimplemented in org.javia.arity.CompiledFunction, and org.javia.arity.CompiledFunction.

Definition at line 73 of file Function.java.

                                                                 {
        throw new ArityException("Didn't expect 2 args");
    }
double org.javia.arity.Function.eval ( double  args[]) throws ArityException [inline]

Evaluates the function given the argument values.

Parameters:
argsarray containing the arguments.
Returns:
the value of the function
Exceptions:
ArityExceptionif args.length != arity.

Reimplemented in org.javia.arity.CompiledFunction, and org.javia.arity.CompiledFunction.

Definition at line 83 of file Function.java.

                                                            {
        switch (args.length) {
        case 0:
            return eval();
        case 1:
            return eval(args[0]);
        case 2:
            return eval(args[0], args[1]);
        }
        throw new ArityException("unexpected " + args.length + " args");
    }

Here is the call graph for this function:

double org.javia.arity.Function.eval ( double  args[]) throws ArityException [inline]

Evaluates the function given the argument values.

Parameters:
argsarray containing the arguments.
Returns:
the value of the function
Exceptions:
ArityExceptionif args.length != arity.

Reimplemented in org.javia.arity.CompiledFunction, and org.javia.arity.CompiledFunction.

Definition at line 83 of file Function.java.

                                                            {
        switch (args.length) {
        case 0:
            return eval();
        case 1:
            return eval(args[0]);
        case 2:
            return eval(args[0], args[1]);
        }
        throw new ArityException("unexpected " + args.length + " args");
    }

Here is the call graph for this function:


Member Data Documentation

Definition at line 38 of file Function.java.


The documentation for this class was generated from the following files: