Package ptolemy.data

Class TupleToken


  • public class TupleToken
    extends Token
    A token that contains an ordered set of tokens.
    Since:
    Ptolemy II 10.0
    Version:
    $Id$
    Author:
    Yang Zhao
    Pt.AcceptedRating:
    Red (cxh)
    Pt.ProposedRating:
    Yellow (neuendor)
    • Field Detail

      • VOID

        public static final TupleToken VOID
        An empty tuple token.
    • Constructor Detail

      • TupleToken

        public TupleToken​(Token[] value)
        Construct a TupleToken with the specified token array as its value.
        Parameters:
        value - The value.
    • Method Detail

      • tupleValue

        public Token[] tupleValue()
        Return an array of tokens populated with the contents of this array token. The returned array is a copy so the caller is free to modify it.
        Returns:
        An array of tokens.
      • equals

        public boolean equals​(java.lang.Object object)
        Return true if the class of the argument is TupleToken and it has the same length and the elements are equal to that of this token. Equality of the contained elements is tested by their equals() method.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        object - The object to compare with.
        Returns:
        True if the argument is a tuple token of the same length and the elements are equal to that of this token.
      • getElement

        public Token getElement​(int index)
        Return the element at the specified index.
        Parameters:
        index - The index of the desired element.
        Returns:
        The token contained in this array token at the specified index.
        Throws:
        java.lang.ArrayIndexOutOfBoundsException - If the specified index is outside the range of the token array.
      • getElementType

        public Type getElementType​(int index)
        Return the element type at the specified index.
        Parameters:
        index - The index of the desired element.
        Returns:
        The type of the token contained in this array token at the specified index.
        Throws:
        java.lang.ArrayIndexOutOfBoundsException - If the specified index is outside the range of the token array.
      • getType

        public Type getType()
        Return the type of this token, which is a TupleType populated with the types of the value of this token.
        Overrides:
        getType in class Token
        Returns:
        A TupleType.
      • hashCode

        public int hashCode()
        Return a hash code value for this token. This method returns the hash code length xored with the values of the tuples.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        A hash code value for this token.
      • isEqualTo

        public BooleanToken isEqualTo​(Token token)
                               throws IllegalActionException
        Return a true-valued token if the argument is equal to this one. The isEqualTo() method of the element tokens is used to make the comparison. It is assumed that the argument is a TupleToken.
        Overrides:
        isEqualTo in class Token
        Parameters:
        token - The token to compare to this token.
        Returns:
        A true-valued token if the argument is equal.
        Throws:
        IllegalActionException - If the element types do not support this comparison.
      • length

        public int length()
        Return the length of the contained token array.
        Returns:
        The length of the contained token array.
      • merge

        public static TupleToken merge​(TupleToken first,
                                       TupleToken second)
        Merge two tuple tokens into one by concatenating their tokens.
        Parameters:
        first - The first tuple token.
        second - The second tuple token.
        Returns:
        The merged tuple token.
      • one

        public Token one()
                  throws IllegalActionException
        Return a new TupleToken representing the multiplicative identity. The returned token contains a tuple of the same size as the tuple contained by this token, where each element of the tuple in the returned token is the multiplicative identity of the corresponding element of this token.
        Overrides:
        one in class Token
        Returns:
        A TupleToken of multiplicative identities.
        Throws:
        IllegalActionException - If multiplicative identity is not supported by an element token.
      • toString

        public java.lang.String toString()
        Return the value of this token as a string that can be parsed by the expression language to recover a token with the same value. FIXME: This is not currently supported by the expression language.
        Overrides:
        toString in class Token
        Returns:
        A string beginning with "<" that contains expressions for every element in the tuple separated by commas, ending with ">".
      • zero

        public Token zero()
                   throws IllegalActionException
        Returns a new TupleToken representing the additive identity. The returned token contains a tuple of the same size as the tuple contained by this token, and each element of the tuple in the returned token is the additive identity of the corresponding element of this token.
        Overrides:
        zero in class Token
        Returns:
        A TupleToken with additive identities.
        Throws:
        IllegalActionException - If the additive identity is not supported by an element token.