ptolemy.data
Class FunctionToken

java.lang.Object
  extended by ptolemy.data.Token
      extended by ptolemy.data.FunctionToken
All Implemented Interfaces:
java.io.Serializable

public class FunctionToken
extends Token

A token that contains a function. The function takes a fixed number of arguments, supplied as a list of tokens. Currently, no operations between function tokens (add, multiply, etc.) are supported.

Since:
Ptolemy II 2.1
Version:
$Id: FunctionToken.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Xiaojun Liu, Steve Neuendorffer
See Also:
Serialized Form
Accepted Rating:
Red (liuxj)
Proposed Rating:
Yellow (liuxj)

Field Summary
private  Function _function
           
private  FunctionType _type
           
 
Fields inherited from class ptolemy.data.Token
NIL
 
Constructor Summary
FunctionToken(Function f, FunctionType type)
          Create a new FunctionToken that applies the given function.
FunctionToken(java.lang.String init)
          Create a new FunctionToken from the given string.
 
Method Summary
 Token apply(Token[] args)
          Apply this function to the given list of arguments.
 Function getFunction()
          Return the function of this token.
 int getNumberOfArguments()
          Return the number of arguments of the function.
 Type getType()
          Return the type of this token.
 BooleanToken isCloseTo(Token rightArgument, double epsilon)
          Test for closeness of the values of this Token and the argument Token.
 BooleanToken isEqualTo(Token rightArgument)
          Test for equality of the values of this Token and the argument Token.
 java.lang.String toString()
          Return a String representation of this function.
 
Methods inherited from class ptolemy.data.Token
add, addReverse, divide, divideReverse, isCloseTo, isNil, modulo, moduloReverse, multiply, multiplyReverse, notSupportedConversionMessage, notSupportedIncomparableConversionMessage, notSupportedIncomparableMessage, notSupportedMessage, notSupportedNullNilStringMessage, one, pow, subtract, subtractReverse, zero, zeroReturnType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_function

private Function _function

_type

private FunctionType _type
Constructor Detail

FunctionToken

public FunctionToken(Function f,
                     FunctionType type)
Create a new FunctionToken that applies the given function. The type of the function token will be the same as the given type.

Parameters:
f - The function.
type - The function type.

FunctionToken

public FunctionToken(java.lang.String init)
              throws IllegalActionException
Create a new FunctionToken from the given string.

Parameters:
init - The initialization string, for example function(x,y) 4+x+y.
Throws:
IllegalActionException - If an error occurs, or the string cannot be parsed into a function.
Method Detail

apply

public Token apply(Token[] args)
            throws IllegalActionException
Apply this function to the given list of arguments.

Parameters:
args - the arguments to which the function is applied
Returns:
The results of applying the arguments to this function.
Throws:
IllegalActionException - If the arguments are not compatible with this function, or an error occurs during evaluation.

getFunction

public Function getFunction()
Return the function of this token.

Returns:
A Function.

getNumberOfArguments

public int getNumberOfArguments()
Return the number of arguments of the function.

Returns:
The number of arguments of the function.

getType

public Type getType()
Return the type of this token.

Overrides:
getType in class Token
Returns:
A FunctionType.

isCloseTo

public BooleanToken isCloseTo(Token rightArgument,
                              double epsilon)
Test for closeness of the values of this Token and the argument Token. For function tokens, checking for closeness is the same as checking for equality.

Overrides:
isCloseTo in class Token
Parameters:
rightArgument - The token to compare to this token.
epsilon - This argument is ignored in this method.
Returns:
A true-valued token if the first argument is equal to this token.

isEqualTo

public BooleanToken isEqualTo(Token rightArgument)
Test for equality of the values of this Token and the argument Token. Two function tokens are equal if they correspond to the same expression, under renaming of any bound variables.

Overrides:
isEqualTo in class Token
Parameters:
rightArgument - The token to compare to this token.
Returns:
A token containing true if the value element of the first argument is equal to the value of this token.

toString

public java.lang.String toString()
Return a String representation of this function.

Overrides:
toString in class Token
Returns:
The String "present", unless this token is Token.NIL, in which case return the String "nil".