public class ArrayToken extends AbstractNotConvertibleToken
Modifier and Type | Field and Description |
---|---|
protected int |
_depth
The depth of the hierarchy of array tokens used to represent
this array.
|
protected Type |
_elementType
The type of this array.
|
static ArrayToken |
NIL
A token that represents a missing value.
|
Constructor and Description |
---|
ArrayToken(java.lang.String init)
Construct an ArrayToken from the specified string.
|
ArrayToken(Token[] value)
Construct an ArrayToken with the specified token array.
|
ArrayToken(Token[] value,
int length)
Construct an ArrayToken with the first length
elements of 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.
|
Modifier and Type | Method and Description |
---|---|
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.
|
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)
Addition can occur between arrays, or between an array and a token
of some base type (i.e., anything less than or equal to String).
|
Token |
addReverse(Token leftArgument)
If the left-hand argument is a base type token, then convert it
to an array of size one.
|
ArrayToken |
append(ArrayToken token)
Append the given array to the end of this array, and return the
resulting array.
|
static ArrayToken |
append(ArrayToken[] tokens)
Append the given arrays.
|
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.
|
BooleanToken |
isCloseTo(Token token,
double epsilon)
Test that 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.
|
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 |
reverse()
Return a new ArrayToken whose elements are in reverse order of this
ArrayToken.
|
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.
|
ArrayToken |
update(int index,
Token value)
Return a new array with all elements equal to those of this
array except the one at position index, which has value
given by value.
|
Token |
zero()
Returns a new ArrayToken representing the additive identity.
|
isEqualTo, notSupportedDifferentClassesMessage
isCloseTo, notSupportedConversionMessage, notSupportedIncomparableConversionMessage, notSupportedIncomparableMessage, notSupportedMessage, notSupportedNullNilStringMessage, pow, zeroReturnType
public static final ArrayToken NIL
protected int _depth
protected Type _elementType
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(Token[] value, int length) throws IllegalActionException
value
- An (not empty) array of tokens.length
- The number of elements to be used from the
specified array.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.public Token add(Token rightArgument) throws IllegalActionException
add
in class AbstractNotConvertibleToken
rightArgument
- The array to be added to this array.IllegalActionException
- If addition between this array
and the provided argument is not supported.public Token addReverse(Token leftArgument) throws IllegalActionException
addReverse
in class AbstractNotConvertibleToken
leftArgument
- The array to add this array to.IllegalActionException
- If addition between this array
and the provided argument is not supported.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 ArrayToken append(ArrayToken[] tokens) throws IllegalActionException
tokens
- The list of arrays to be appended together.IllegalActionException
- If an array token cannot be created,
or if all specified arrays are empty.public static byte[] arrayTokenToUnsignedByteArray(ArrayToken dataArrayToken)
dataArrayToken
- to be converted to a unsigned byte array.unsignedByteArrayToArrayToken(byte[])
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 tokenIllegalActionException
- 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()
public int hashCode()
hashCode
in class java.lang.Object
public BooleanToken isCloseTo(Token token, double epsilon) throws IllegalActionException
isCloseTo
in class AbstractNotConvertibleToken
token
- The token to test closeness of this token with.epsilon
- The value that we use to determine whether two
tokens are close.IllegalActionException
- If the argument token and
this token are implemented in different classes.public boolean isNil()
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 reverse() throws IllegalActionException
IllegalActionException
- If thrown while creating the new
ArrayToken.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 subtract 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()
public static ArrayToken unsignedByteArrayToArrayToken(byte[] dataBytes) throws IllegalActionException
dataBytes
- data to be converted to an ArrayToken.IllegalActionException
- If ArrayToken can not be created.arrayTokenToUnsignedByteArray(ArrayToken)
public ArrayToken update(int index, Token value) throws IllegalActionException
index
- The index of the element to be updated.value
- The value of the element to be updated.IllegalActionException
- Should not be thrown in this base class.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.