Package ptolemy.data

Class FunctionToken

  • Direct Known Subclasses:
    FactorOracle.ChordFunction.ChordFunctionToken, FactorOracle.ChordFunctionToken

    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$
    Author:
    Xiaojun Liu, Steve Neuendorffer
    Pt.AcceptedRating:
    Red (liuxj)
    Pt.ProposedRating:
    Yellow (liuxj)
    • 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".