ptolemy.data
Class OrderedRecordToken

java.lang.Object
  extended by ptolemy.data.Token
      extended by ptolemy.data.AbstractNotConvertibleToken
          extended by ptolemy.data.RecordToken
              extended by ptolemy.data.OrderedRecordToken
All Implemented Interfaces:
java.io.Serializable

public class OrderedRecordToken
extends RecordToken

A token that contains a set of label/token pairs. Operations on record tokens result in new record tokens containing only the common fields, where the operation specifies how to combine the data in the common fields. Thus, for example, if two record tokens are added or subtracted, then common records (those with the same labels) will be added or subtracted, and the disjoint records will not appear in the result.

This implementation maintains the order of the entries as they were added.

Since:
Ptolemy II 8.0
Version:
$Id: OrderedRecordToken.java 57046 2010-01-27 23:35:53Z cxh $, $Id: OrderedRecordToken.java 57046 2010-01-27 23:35:53Z cxh $
Author:
Ben Leinfelder
See Also:
Serialized Form
Accepted Rating:
red (leinfelder)
Proposed Rating:
yellow (leinfelder)

Field Summary
 
Fields inherited from class ptolemy.data.RecordToken
_fields, EMPTY_RECORD
 
Fields inherited from class ptolemy.data.Token
NIL
 
Constructor Summary
OrderedRecordToken()
          Construct an OrderedRecordToke with now fields.
OrderedRecordToken(java.util.Map fieldMap)
          Construct an OrderedRecordToken with the labels and values specified by a given Map object.
OrderedRecordToken(java.lang.String init)
          Construct a RecordToken from the specified string.
OrderedRecordToken(java.lang.String[] labels, Token[] values)
          Construct an OrderedRecordToken with the specified labels and values.
 
Method Summary
protected  RecordToken _createRecordToken(java.lang.String[] labels, Token[] values)
          Create a new RecordToken.
protected  java.util.Set _createSet()
          Create a Set implementation appropriate for operations on this RecordToken.
protected  void _initializeStorage()
          Intialize the storage used by this token.
protected  BooleanToken _isEqualTo(Token rightArgument)
          Return true if the specified token is equal to this one.
 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.
 java.lang.String toString()
          Return the value of this token as a string.
 
Methods inherited from class ptolemy.data.RecordToken
_add, _divide, _isCloseTo, _modulo, _multiply, _subtract, get, getType, hashCode, labelSet, length, merge, mergeReturnType, one, zero
 
Methods inherited from class ptolemy.data.AbstractNotConvertibleToken
add, addReverse, divide, divideReverse, isCloseTo, isEqualTo, modulo, moduloReverse, multiply, multiplyReverse, notSupportedDifferentClassesMessage, subtract, subtractReverse
 
Methods inherited from class ptolemy.data.Token
isCloseTo, isNil, notSupportedConversionMessage, notSupportedIncomparableConversionMessage, notSupportedIncomparableMessage, notSupportedMessage, notSupportedNullNilStringMessage, pow, zeroReturnType
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

OrderedRecordToken

public OrderedRecordToken()
Construct an OrderedRecordToke with now fields.

See Also:
RecordToken

OrderedRecordToken

public OrderedRecordToken(java.util.Map fieldMap)
                   throws IllegalActionException
Construct an OrderedRecordToken with the labels and values specified by a given Map object. The object cannot contain any null keys or values.

Parameters:
fieldMap - A Map that has keys of type String and values of type Token.
Throws:
IllegalActionException - If the map contains null keys or values, or if it contains non-String keys or non-Token values.

OrderedRecordToken

public OrderedRecordToken(java.lang.String init)
                   throws IllegalActionException
Construct a RecordToken from the specified string.

Parameters:
init - A string expression of a record.
Throws:
IllegalActionException - If the string does not contain a parsable record.

OrderedRecordToken

public OrderedRecordToken(java.lang.String[] labels,
                          Token[] values)
                   throws IllegalActionException
Construct an OrderedRecordToken with the specified labels and values. The labels and values arrays must have the same length, and have one to one correspondence with each other. That is, the i'th entry in the labels array is the label for the i'th value in the values array. If both arrays are empty, this creates an empty record token.

Parameters:
labels - An array of labels.
values - An array of Tokens.
Throws:
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.
Method Detail

toString

public java.lang.String toString()
Return the value of this token as a string. The syntax is similar to the ML record: {label = value, label = value, ...} The record fields are listed in the their original order

Overrides:
toString in class RecordToken
Returns:
A String beginning with "{" that contains label and value pairs separated by commas, ending with "}".

equals

public 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. Order matters

Overrides:
equals in class RecordToken
Parameters:
object - An instance of Object.
Returns:
True if the argument is equal to this token.
See Also:
RecordToken.hashCode()

_createRecordToken

protected RecordToken _createRecordToken(java.lang.String[] labels,
                                         Token[] values)
                                  throws IllegalActionException
Description copied from class: RecordToken
Create a new RecordToken. Subclasses of RecordToken may return a different subclass instance.

Overrides:
_createRecordToken in class RecordToken
Parameters:
labels - An array of String labels for the RecordToken to be created.
values - An array of Token values for the RecordToken to be created.
Returns:
a new RecordToken.
Throws:
IllegalActionException - If thrown while constructing the RecordToken
See Also:
RecordToken

_initializeStorage

protected void _initializeStorage()
Intialize the storage used by this token. OrderedRecordToken uses a LinkedHashMap so that the original order of the record is maintained.

Overrides:
_initializeStorage in class RecordToken

_createSet

protected java.util.Set _createSet()
Create a Set implementation appropriate for operations on this RecordToken. Here we are using an ordered set.

Overrides:
_createSet in class RecordToken
Returns:
a new Set.

_isEqualTo

protected BooleanToken _isEqualTo(Token rightArgument)
                           throws IllegalActionException
Return true if the specified token is equal to this one. Equal means that both tokens have the same labels with the same values. This method is different from equals() in that _isEqualTo() looks for equalities of values irrespective of their types. It is assumed that the type of the argument is RecordToken.

Overrides:
_isEqualTo in class RecordToken
Parameters:
rightArgument - The token to compare to this token.
Returns:
True if the argument is equal to this.
Throws:
IllegalActionException - If this method is not supported by the derived class.