|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectptolemy.data.Token
ptolemy.data.AbstractNotConvertibleToken
ptolemy.data.ArrayToken
public class ArrayToken
A token that contains an array of tokens. The operations between arrays are defined pointwise, and require that the lengths of the arrays are the same. The elements of the ArrayToken will be converted to the least upper bound of their input types. Zero length array tokens are supported, given a prototype element to determine the type of the array.
Red (cxh) nil token code |
Yellow (cxh) |
Field Summary | |
---|---|
private Type |
_elementType
The type of this array. |
private Token[] |
_value
The array of values of this array token. |
static ArrayToken |
NIL
A token that represents a missing value. |
Constructor Summary | |
---|---|
ArrayToken(java.lang.String init)
Construct an ArrayToken from the specified string. |
|
ArrayToken(Token[] value)
Construct an ArrayToken with the specified token array. |
|
ArrayToken(Type elementType)
Construct an empty ArrayToken with the given element type. |
|
ArrayToken(Type elementType,
Token[] value)
Construct an ArrayToken with the specified element type and token array. |
Method Summary | |
---|---|
protected Token |
_add(Token rightArgument)
Return a new token whose value is the value of the argument token added to the value of this token. |
private void |
_checkArgumentLength(Token token)
|
protected Token |
_divide(Token rightArgument)
Return a new token whose value is the value of this token divided by the value of the argument token. |
protected Token |
_divideReverse(Token rightArgument)
Return a new token whose value is the value of this token divided into the value of the argument token. |
protected BooleanToken |
_isCloseTo(Token token,
double epsilon)
Test whether the value of this token is close to the first argument, where "close" means that the distance between them is less than or equal to the second argument. |
protected BooleanToken |
_isEqualTo(Token token)
Return a true-valued token if the argument is equal to this one. |
protected Token |
_modulo(Token rightArgument)
Return a new token whose value is the value of this token modulo the value of the argument token. |
protected Token |
_moduloReverse(Token rightArgument)
Return a new token whose value is the value of this token modulo the value of the argument token. |
protected Token |
_multiply(Token rightArgument)
Return a new token whose value is the value of this token multiplied by the value of the argument token. |
protected Token |
_subtract(Token rightArgument)
Return a new token whose value is the value of the argument token subtracted from the value of this token. |
protected Token |
_subtractReverse(Token rightArgument)
Return a new token whose value is the value of this token subtracted from the value of the argument token. |
Token |
add(Token rightArgument)
Add this array token to the specified argument. |
Token |
addReverse(Token leftArgument)
Add this array token to the specified argument. |
ArrayToken |
append(ArrayToken token)
Append the given array to the end of this array, and return the resulting array. |
static byte[] |
arrayTokenToUnsignedByteArray(ArrayToken dataArrayToken)
Convert an ArrayToken to an array of unsigned bytes. |
Token[] |
arrayValue()
Return an array of tokens populated with the contents of this array token. |
BooleanToken |
contains(Token element)
Return a Boolean token that identifies whether the given token is an element of this array. |
Token |
divide(Token rightArgument)
Divide this array token by the specified argument. |
Token |
divideReverse(Token rightArgument)
Divide this array token into the specified argument. |
ArrayToken |
elementAdd(Token token)
Add the given token to each element of this array. |
ArrayToken |
elementDivide(Token token)
Divide each element of this array by the given token. |
ArrayToken |
elementModulo(Token token)
Modulo each element of this array by the given token. |
ArrayToken |
elementMultiply(Token token)
Multiply each element of this array by the given token. |
static Type |
elementMultiplyReturnType(Type type1,
Type type2)
Return the (exact) return type of the elementMultiply function above. |
ArrayToken |
elementSubtract(Token token)
Subtract the given token from each element of this array. |
boolean |
equals(java.lang.Object object)
Return true if the class of the argument is ArrayToken and of the same length and the elements are equal to that of this token. |
ArrayToken |
extract(ArrayToken selection)
Extract a non-contiguous subarray either by giving a boolean array of the same length of this array describing which elements to include and which to include, or by giving an an array of an arbitrary length giving the indices of elements from this array to include in the subarray. |
Token |
getElement(int index)
Return the element at the specified index. |
Type |
getElementType()
Return the type contained in this ArrayToken. |
Type |
getType()
Return the type of this ArrayToken. |
int |
hashCode()
Return a hash code value for this token. |
boolean |
isNil()
Return true if the token is nil, (aka null or missing). |
int |
length()
Return the length of the contained token array. |
Token |
modulo(Token rightArgument)
Return a new token whose value is the value of this token modulo the value of the argument token. |
Token |
moduloReverse(Token rightArgument)
Return a new token whose value is the value of the argument modulo the value of this token. |
Token |
multiply(Token rightArgument)
Multiply this array token by the specified argument. |
Token |
multiplyReverse(Token leftArgument)
Multiply this array token by the specified argument. |
Token |
one()
Return a new ArrayToken representing the multiplicative identity. |
ArrayToken |
subarray(int index)
Return the contiguous subarray starting at the specified index to the end of this array. |
ArrayToken |
subarray(int index,
int count)
Return the contiguous subarray starting at the specified index and of the specified length. |
Token |
subtract(Token rightArgument)
Subtract from this array token the specified argument. |
Token |
subtractReverse(Token rightArgument)
Subtract this array token from the specified argument. |
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. |
static ArrayToken |
unsignedByteArrayToArrayToken(byte[] dataBytes)
Take an array of unsigned bytes and convert it to an ArrayToken. |
Token |
zero()
Returns a new ArrayToken representing the additive identity. |
Methods inherited from class ptolemy.data.AbstractNotConvertibleToken |
---|
isCloseTo, isEqualTo, notSupportedDifferentClassesMessage |
Methods inherited from class ptolemy.data.Token |
---|
isCloseTo, notSupportedConversionMessage, notSupportedIncomparableConversionMessage, notSupportedIncomparableMessage, notSupportedMessage, notSupportedNullNilStringMessage, pow, zeroReturnType |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final ArrayToken NIL
private Token[] _value
private Type _elementType
Constructor Detail |
---|
public ArrayToken(Token[] value) throws IllegalActionException
value
- An (not empty) array of tokens.
IllegalActionException
- If the length of the given array is
zero.public ArrayToken(java.lang.String init) throws IllegalActionException
"{1, 2, 3}"
init
- A string expression of an array.
IllegalActionException
- If the string does
not contain a parsable array.public ArrayToken(Type elementType)
elementType
- A token type.public ArrayToken(Type elementType, Token[] value) throws IllegalActionException
elementType
- The type of the array.value
- An array of tokens.
IllegalActionException
- If the tokens in the array
do not have the specified type.Method Detail |
---|
public Token add(Token rightArgument) throws IllegalActionException
add
in class AbstractNotConvertibleToken
rightArgument
- The token to multiply by this token.
IllegalActionException
- If the argument token is
an array token but does not have the same length as this
token, or if multiplication is not supported between the elements
of this array and the argument.public Token addReverse(Token leftArgument) throws IllegalActionException
addReverse
in class AbstractNotConvertibleToken
leftArgument
- The token to multiply by this token.
IllegalActionException
- If the argument token is
an array token but does not have the same length as this
token, or if multiplication is not supported between the elements
of this array and the argument.public ArrayToken append(ArrayToken token) throws IllegalActionException
token
- The array to be appended to the end of this array.
IllegalActionException
- If an array token cannot be created.public static byte[] arrayTokenToUnsignedByteArray(ArrayToken dataArrayToken)
dataArrayToken
- to be converted to a unsigned byte array.
public Token[] arrayValue()
public BooleanToken contains(Token element)
element
- A token to test whether it is an element of this array.
public Token divide(Token rightArgument) throws IllegalActionException
divide
in class AbstractNotConvertibleToken
rightArgument
- The token to divide into this token.
IllegalActionException
- If the argument token is
an array token but does not have the same length as this
token, or if division is not supported between the elements
of this array and the argument.public Token divideReverse(Token rightArgument) throws IllegalActionException
divideReverse
in class AbstractNotConvertibleToken
rightArgument
- The token into which to divide this token.
IllegalActionException
- If the argument token is
an array token but does not have the same length as this
token, or if division is not supported between the elements
of this array and the argument.public ArrayToken elementAdd(Token token) throws IllegalActionException
token
- The token to be added to this token.
IllegalActionException
- If the argument token is not
of a type that can be added to an element of this token.public ArrayToken elementDivide(Token token) throws IllegalActionException
token
- The token which which to divide this token
IllegalActionException
- If the argument token is not
of a type that can be divided into an element of this token.public ArrayToken elementModulo(Token token) throws IllegalActionException
token
- The token with which to modulo this token.
IllegalActionException
- If the argument token is not
of a type that can be used with modulo.public ArrayToken elementMultiply(Token token) throws IllegalActionException
token
- The token with which to multiply this token.
IllegalActionException
- If the argument token is
not of a type that can be multiplied to an element of this token.public static Type elementMultiplyReturnType(Type type1, Type type2) throws IllegalActionException
type1
- The type of the base of the corresponding function.type2
- The type of the argument of the corresponding function.
IllegalActionException
- Not thrown in this base class.public ArrayToken elementSubtract(Token token) throws IllegalActionException
token
- The token to subtract from this token.
IllegalActionException
- If the argument token is not
of a type that can be subtracted from an element of this token.public boolean equals(java.lang.Object object)
equals
in class java.lang.Object
object
- the object to compare with.
public ArrayToken extract(ArrayToken selection) throws IllegalActionException
selection
- An ArrayToken describing the selection of elements
with which to form the subarray: either an array of integer
indices, or an array of boolean inclusion/exclusion choices.
IllegalActionException
- If the argument type is invalid
or the result cannot be constructed.
java.lang.ArrayIndexOutOfBoundsException
- If the argument is an array
of integers, and one or more of those integers is not a valid
index into this array.public Token getElement(int index)
index
- The index of the desired element.
java.lang.ArrayIndexOutOfBoundsException
- If the specified index is
outside the range of the token array.public Type getElementType()
public Type getType()
getType
in class Token
public int hashCode()
hashCode
in class java.lang.Object
public boolean isNil()
isNil
in class Token
NIL
token.public int length()
public Token modulo(Token rightArgument) throws IllegalActionException
modulo
in class AbstractNotConvertibleToken
rightArgument
- The token to divide into this token.
IllegalActionException
- If the argument token and
this token are implemented in different classes, or the
operation does not make sense for the given types.public Token moduloReverse(Token rightArgument) throws IllegalActionException
moduloReverse
in class AbstractNotConvertibleToken
rightArgument
- The token to divide into this token.
IllegalActionException
- If the argument token and
this token are implemented in different classes, or the
operation does not make sense for the given types.public Token multiply(Token rightArgument) throws IllegalActionException
multiply
in class AbstractNotConvertibleToken
rightArgument
- The token to multiply by this token.
IllegalActionException
- If the argument token is
an array token but does not have the same length as this
token, or if multiplication is not supported between the elements
of this array and the argument.public Token multiplyReverse(Token leftArgument) throws IllegalActionException
multiplyReverse
in class AbstractNotConvertibleToken
leftArgument
- The token to multiply by this token.
IllegalActionException
- If the argument token is
an array token but does not have the same length as this
token, or if multiplication is not supported between the elements
of this array and the argument.public Token one() throws IllegalActionException
one
in class Token
IllegalActionException
- If multiplicative identity is not
supported by the element token.public ArrayToken subarray(int index) throws IllegalActionException
index
- The index of the beginning of the subarray.
IllegalActionException
- If the index argument is
less than zero.public ArrayToken subarray(int index, int count) throws IllegalActionException
index
- The index of the beginning of the subarray.count
- The length of the subarray.
IllegalActionException
- If the index argument is
less than zero.public Token subtract(Token rightArgument) throws IllegalActionException
subtract
in class AbstractNotConvertibleToken
rightArgument
- The token to subctract from this token.
IllegalActionException
- If the argument token is
an array token but does not have the same length as this
token or length 1, or if division is not supported between the elements
of this array and the argument.public Token subtractReverse(Token rightArgument) throws IllegalActionException
subtractReverse
in class AbstractNotConvertibleToken
rightArgument
- The token from which to subtract this token.
IllegalActionException
- If the argument token is
an array token but does not have the same length as this
token or length 1, or if division is not supported between the elements
of this array and the argument.public java.lang.String toString()
toString
in class Token
public static ArrayToken unsignedByteArrayToArrayToken(byte[] dataBytes) throws IllegalActionException
dataBytes
- data to be converted to an ArrayToken.
IllegalActionException
- If ArrayToken can not be created.public Token zero() throws IllegalActionException
zero
in class Token
IllegalActionException
- If additive identity is not
supported by an element token.protected Token _add(Token rightArgument) throws IllegalActionException
_add
in class AbstractNotConvertibleToken
rightArgument
- The token whose value we add to the value
of this token.
IllegalActionException
- If the argument is an
ArrayToken of different length, or calling the add method of
an element token throws it.protected Token _divide(Token rightArgument) throws IllegalActionException
_divide
in class AbstractNotConvertibleToken
rightArgument
- The token to divide this token by.
IllegalActionException
- If the argument is an
ArrayToken of different length, or calling the divide method
of the element token throws it.protected Token _divideReverse(Token rightArgument) throws IllegalActionException
rightArgument
- The token into which to divide this token.
IllegalActionException
- If the argument is an
ArrayToken of different length, or calling the divide method
of the element token throws it.protected BooleanToken _isCloseTo(Token token, double epsilon) throws IllegalActionException
_isCloseTo
in class AbstractNotConvertibleToken
token
- The token to compare to this token.epsilon
- The value that we use to determine whether two
tokens are close.
IllegalActionException
- If the elements do not support
this comparison.protected BooleanToken _isEqualTo(Token token) throws IllegalActionException
_isEqualTo
in class AbstractNotConvertibleToken
token
- The token to compare to this token.
IllegalActionException
- If the element types do not
support this comparison.protected Token _modulo(Token rightArgument) throws IllegalActionException
_modulo
in class AbstractNotConvertibleToken
rightArgument
- The token to modulo this token by.
IllegalActionException
- If the argument is an
ArrayToken of different length, or calling the modulo method
of the element token throws it.protected Token _moduloReverse(Token rightArgument) throws IllegalActionException
rightArgument
- The token into which to modulo this token.
IllegalActionException
- If the argument is an
ArrayToken of different length, or calling the modulo method
of the element token throws it.protected Token _multiply(Token rightArgument) throws IllegalActionException
_multiply
in class AbstractNotConvertibleToken
rightArgument
- The token to multiply this token by.
IllegalActionException
- If the argument is an
ArrayToken of different length, or calling the multiply method
of the element token throws it.protected Token _subtract(Token rightArgument) throws IllegalActionException
_subtract
in class AbstractNotConvertibleToken
rightArgument
- The token to subtract to this token.
IllegalActionException
- If the argument is an
ArrayToken of different length, or calling the subtract method
of the element token throws it.protected Token _subtractReverse(Token rightArgument) throws IllegalActionException
rightArgument
- The token from which to subtract this token.
IllegalActionException
- If the argument is an
ArrayToken of different length (and not length 1), or calling the subtract method
of the element token throws it.private void _checkArgumentLength(Token token) throws IllegalActionException
IllegalActionException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |