Package ptolemy.data
Class TupleToken
- java.lang.Object
-
- ptolemy.data.Token
-
- ptolemy.data.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 Summary
Fields Modifier and Type Field Description static TupleToken
VOID
An empty tuple token.
-
Constructor Summary
Constructors Constructor Description TupleToken(Token[] value)
Construct a TupleToken with the specified token array as its value.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.Token
getElement(int index)
Return the element at the specified index.Type
getElementType(int index)
Return the element type at the specified index.Type
getType()
Return the type of this token, which is a TupleType populated with the types of the value of this token.int
hashCode()
Return a hash code value for this token.BooleanToken
isEqualTo(Token token)
Return a true-valued token if the argument is equal to this one.int
length()
Return the length of the contained token array.static TupleToken
merge(TupleToken first, TupleToken second)
Merge two tuple tokens into one by concatenating their tokens.Token
one()
Return a new TupleToken representing the multiplicative identity.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.Token[]
tupleValue()
Return an array of tokens populated with the contents of this array token.Token
zero()
Returns a new TupleToken representing the additive identity.-
Methods inherited from class ptolemy.data.Token
add, addReverse, divide, divideReverse, isCloseTo, isCloseTo, isNil, modulo, moduloReverse, multiply, multiplyReverse, notSupportedConversionMessage, notSupportedIncomparableConversionMessage, notSupportedIncomparableMessage, notSupportedMessage, notSupportedNullNilStringMessage, pow, subtract, subtractReverse, zeroReturnType
-
-
-
-
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 classjava.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.
-
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 classjava.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 classToken
- 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 classToken
- 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.
-
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 classToken
- Returns:
- A TupleToken with additive identities.
- Throws:
IllegalActionException
- If the additive identity is not supported by an element token.
-
-