edu.neu.ccs.parser
Class AbstractFunction

java.lang.Object
  extended byedu.neu.ccs.parser.AbstractFunction
Direct Known Subclasses:
SimpleFunction

public abstract class AbstractFunction
extends Object

Class AbstractFunction encapsulates a function definition and its corresponding String name for for use with a parser.

This class is abstract since the method functionCall must be defined in a derived class.

As of 2.5.0, the class AbstractParser was made concrete and renamed BaseParser. At that time, its static inner classes were extracted and made standalone. This class was formerly named Procedure but the name AbstractFunction seemed more descriptive.

This class should not be confused with the class Function in edu.neu.ccs. The latter class is defined solely to collect several interfaces that are useful in classifying mathematical functions.


Field Summary
private  int arguments
          The number of arguments required by this function.
private  String name
          The name representing this function.
 
Constructor Summary
AbstractFunction(String name, int arguments)
          Constructs a function with the given String name and given number of expected arguments.
 
Method Summary
 int arguments()
          Returns the number of arguments of this function.
 void checkValues(Object[] values)
          Throws a ParseExpection if: the values are null the length of values is not equal to arguments
 void checkValuesAsNumeric(Object[] values)
          Throws a ParseExpection if: the values are null the length of values is not equal to arguments the elements in values are not of type XNumber
 void checkValuesAsXObject(Object[] values)
          Throws a ParseExpection if: the values are null the length of values is not equal to arguments the elements in values are not of type XObject
abstract  Object functionCall(Object[] values)
          Applies the function using the provided array of argument values whose length must equal the number of arguments and returns its result.
static AbstractFunction makeFourArg(String name, Function.FourArg f)
          Constructs an AbstractFunction object using the given name and the givenFunction.FourArg for its implementation.
static AbstractFunction makeNoArg(String name, Function.NoArg f)
          Constructs an AbstractFunction object using the given name and the givenFunction.NoArg for its implementation.
static AbstractFunction makeOneArg(String name, Function.OneArg f)
          Constructs an AbstractFunction object using the given name and the givenFunction.OneArg for its implementation.
static AbstractFunction makeThreeArg(String name, Function.ThreeArg f)
          Constructs an AbstractFunction object using the given name and the givenFunction.ThreeArg for its implementation.
static AbstractFunction makeTwoArg(String name, Function.TwoArg f)
          Constructs an AbstractFunction object using the given name and the givenFunction.TwoArg for its implementation.
 String name()
          Returns the String name of this function.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

name

private String name
The name representing this function.


arguments

private int arguments
The number of arguments required by this function.

Constructor Detail

AbstractFunction

public AbstractFunction(String name,
                        int arguments)

Constructs a function with the given String name and given number of expected arguments.

The given name is trimmed prior to being used to define the function name.

Throws IllegalArgumentException if the name is not valid when tested by BaseParser.isPossibleIdentifier or if the given arguments value is negative.

Parameters:
name - the identifier for this function
arguments - the required number of arguments
Throws:
IllegalArgumentException
Method Detail

functionCall

public abstract Object functionCall(Object[] values)
                             throws ParseException

Applies the function using the provided array of argument values whose length must equal the number of arguments and returns its result.

Parameters:
values - the array of argument values
Throws:
ParseException

name

public final String name()
Returns the String name of this function.


arguments

public final int arguments()
Returns the number of arguments of this function.


checkValues

public final void checkValues(Object[] values)
                       throws ParseException
Throws a ParseExpection if:

Parameters:
values - the array of argument values
Throws:
ParseException

checkValuesAsXObject

public final void checkValuesAsXObject(Object[] values)
                                throws ParseException
Throws a ParseExpection if:

Parameters:
values - the array of argument values
Throws:
ParseException

checkValuesAsNumeric

public final void checkValuesAsNumeric(Object[] values)
                                throws ParseException
Throws a ParseExpection if:

Parameters:
values - the array of argument values
Throws:
ParseException

makeNoArg

public static AbstractFunction makeNoArg(String name,
                                         Function.NoArg f)

Constructs an AbstractFunction object using the given name and the givenFunction.NoArg for its implementation.

Naturally, this function will require 0 arguments.

Parameters:
name - the function name to be used in a parser
f - the implementation function
Throws:
IllegalArgumentException

makeOneArg

public static AbstractFunction makeOneArg(String name,
                                          Function.OneArg f)

Constructs an AbstractFunction object using the given name and the givenFunction.OneArg for its implementation.

Naturally, this function will require 1 argument.

Parameters:
name - the function name to be used in a parser
f - the implementation function
Throws:
IllegalArgumentException

makeTwoArg

public static AbstractFunction makeTwoArg(String name,
                                          Function.TwoArg f)

Constructs an AbstractFunction object using the given name and the givenFunction.TwoArg for its implementation.

Naturally, this function will require 2 arguments.

Parameters:
name - the function name to be used in a parser
f - the implementation function
Throws:
IllegalArgumentException

makeThreeArg

public static AbstractFunction makeThreeArg(String name,
                                            Function.ThreeArg f)

Constructs an AbstractFunction object using the given name and the givenFunction.ThreeArg for its implementation.

Naturally, this function will require 3 arguments.

Parameters:
name - the function name to be used in a parser
f - the implementation function
Throws:
IllegalArgumentException

makeFourArg

public static AbstractFunction makeFourArg(String name,
                                           Function.FourArg f)

Constructs an AbstractFunction object using the given name and the givenFunction.FourArg for its implementation.

Naturally, this function will require 1 argument.

Parameters:
name - the function name to be used in a parser
f - the implementation function
Throws:
IllegalArgumentException