public class RecordToken extends AbstractNotConvertibleToken
Yellow (cxh) |
Green (neuendor) |
Modifier and Type | Field and Description |
---|---|
protected java.util.Map<java.lang.String,Token> |
_fields
The map of fields that has keys of type String and values of
type token.
|
static RecordToken |
EMPTY_RECORD
Empty Record.
|
Constructor and Description |
---|
RecordToken()
Construct a RecordToken with no fields.
|
RecordToken(java.util.Map<java.lang.String,Token> fieldMap)
Construct a RecordToken with the labels and values specified
by a given Map object.
|
RecordToken(java.lang.String init)
Construct a RecordToken from the specified string.
|
RecordToken(java.lang.String[] labels,
Token[] values)
Construct a RecordToken with the specified labels and values.
|
Modifier and Type | Method and Description |
---|---|
protected Token |
_add(Token rightArgument)
Return a new token whose value is the field-wise addition of
this token and the argument.
|
protected RecordToken |
_createRecordToken(java.lang.String[] labels,
Token[] values)
Create a new RecordToken.
|
protected java.util.Set<java.lang.String> |
_createSet()
Create a Set implementation appropriate for operations on this RecordToken
Subclasses of RecordToken may return a different implementation.
|
protected Token |
_divide(Token rightArgument)
Return a new token whose value is the field-wise division of
this token and the argument.
|
protected void |
_initializeStorage()
Subclasses of RecordToken may choose a different Map implementation
TreeMap is used in the base class to provide naturally-ordered labels
This may not be desired in some applications.
|
protected BooleanToken |
_isCloseTo(Token rightArgument,
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 rightArgument)
Return true if the specified token is equal to this one.
|
protected Token |
_modulo(Token rightArgument)
Return a new token whose value is the field-wise modulo of
this token and the argument.
|
protected Token |
_multiply(Token rightArgument)
Return a new token whose value is the field-wise
multiplication of this token and the argument.
|
protected Token |
_subtract(Token rightArgument)
Return a new token whose value is the field-wise subtraction
of this token and the argument.
|
boolean |
equals(java.lang.Object object)
Return true if the class of the argument is RecordToken, and
the argument has the same set of labels as this token and the
corresponding fields are equal, as determined by the equals
method of the contained tokens.
|
Token |
get(java.lang.String label)
Return the token with the specified label.
|
Type |
getType()
Return the type of this token.
|
int |
hashCode()
Return a hash code value for this token.
|
java.util.Set<java.lang.String> |
labelSet()
Return the labels of this token as a Set.
|
int |
length()
Return the length of this token.
|
static RecordToken |
merge(RecordToken token1,
RecordToken token2)
Return a new token created by merging the two specified tokens,
where preference is given to the first token when field labels
are the same.
|
static Type |
mergeReturnType(Type type1,
Type type2)
Return the (exact) return type of the merge function above.
|
Token |
one()
Returns a new RecordToken representing the multiplicative identity.
|
java.lang.String |
toString()
Return the value of this token as a string.
|
Token |
zero()
Returns a new RecordToken representing the additive identity.
|
add, addReverse, divide, divideReverse, isCloseTo, isEqualTo, modulo, moduloReverse, multiply, multiplyReverse, notSupportedDifferentClassesMessage, subtract, subtractReverse
isCloseTo, isNil, notSupportedConversionMessage, notSupportedIncomparableConversionMessage, notSupportedIncomparableMessage, notSupportedMessage, notSupportedNullNilStringMessage, pow, zeroReturnType
public static final RecordToken EMPTY_RECORD
protected java.util.Map<java.lang.String,Token> _fields
public RecordToken()
public RecordToken(java.lang.String[] labels, Token[] values) throws IllegalActionException
labels
- An array of labels.values
- An array of Tokens.IllegalActionException
- If the labels or the values array
do not have the same length, or contains null element,
or the labels array contains duplicate elements.public RecordToken(java.lang.String init) throws IllegalActionException
Record labels that contain any non-Java identifier characters must be presented as a string i.e., surrounded with single or double quotes. Quotes within label strings must be escaped using a backslash.
init
- A string expression of a record.IllegalActionException
- If the string does not
contain a parsable record.public RecordToken(java.util.Map<java.lang.String,Token> fieldMap) throws IllegalActionException
fieldMap
- A Map that has keys of type String and
values of type Token.IllegalActionException
- If the map contains null
keys or values, or if it contains non-String keys or non-Token
values.public boolean equals(java.lang.Object object)
equals
in class java.lang.Object
object
- An instance of Object.hashCode()
public Token get(java.lang.String label)
label
- A String label.public Type getType()
public int hashCode()
hashCode
in class java.lang.Object
public java.util.Set<java.lang.String> labelSet()
public int length()
public static RecordToken merge(RecordToken token1, RecordToken token2)
token1
- The higher priority record token.token2
- The lower priority record token.public static Type mergeReturnType(Type type1, Type type2)
type1
- The type of the first argument to the
corresponding function.type2
- The type of the second argument to the
corresponding function.public Token one() throws IllegalActionException
one
in class Token
IllegalActionException
- If multiplicative identity is not
supported by any element token.public java.lang.String toString()
{label = value, label = value, ...}
The record fields are listed in the lexicographical order of the
labels determined by the java.lang.String.compareTo() method.
Record labels that contain any non-Java identifier characters are surrounded with double quotes. Quotes within label strings are escaped using a backslash.
public Token zero() throws IllegalActionException
zero
in class Token
IllegalActionException
- If additive identity is not
supported by any element token.protected Token _add(Token rightArgument) throws IllegalActionException
_add
in class AbstractNotConvertibleToken
rightArgument
- The token to add to this token.IllegalActionException
- If calling the add method on
one of the record fields throws it.protected Token _divide(Token rightArgument) throws IllegalActionException
_divide
in class AbstractNotConvertibleToken
rightArgument
- The token to divide this token by.IllegalActionException
- If calling the divide method on
one of the record fields throws it.protected BooleanToken _isCloseTo(Token rightArgument, double epsilon) throws IllegalActionException
_isCloseTo
in class AbstractNotConvertibleToken
rightArgument
- The token to compare to this token.epsilon
- The value that we use to determine whether two
tokens are close.IllegalActionException
- If throw while checking
the closeness of an element of the record.protected BooleanToken _isEqualTo(Token rightArgument) throws IllegalActionException
_isEqualTo
in class AbstractNotConvertibleToken
rightArgument
- The token to compare to this token.IllegalActionException
- If this method is not
supported by the derived class.protected Token _modulo(Token rightArgument) throws IllegalActionException
_modulo
in class AbstractNotConvertibleToken
rightArgument
- The token to modulo this token by.IllegalActionException
- If calling the modulo method on
one of the record fields throws it.protected Token _multiply(Token rightArgument) throws IllegalActionException
_multiply
in class AbstractNotConvertibleToken
rightArgument
- The token to multiply this token by.IllegalActionException
- If calling the multiply method on
one of the record fields throws it.protected Token _subtract(Token rightArgument) throws IllegalActionException
_subtract
in class AbstractNotConvertibleToken
rightArgument
- The token to subtract from this token.IllegalActionException
- If calling the subtract
method on one of the record fields throws it.protected void _initializeStorage()
protected RecordToken _createRecordToken(java.lang.String[] labels, Token[] values) throws IllegalActionException
labels
- An array of String labels for the RecordToken to be created.values
- An array of Token values for the RecordToken to be created.IllegalActionException
- If thrown while constructing the RecordTokenprotected java.util.Set<java.lang.String> _createSet()