Package ptolemy.data

Class UpdatedArrayToken


  • public class UpdatedArrayToken
    extends ArrayToken
    A token that contains an array of tokens that is equal to another specified ArrayToken except at one location, where it has a new value. This implementation keeps a reference to the other specified token and records only the diff between this modified array and the original one.

    This technique is inspired by a similar technique of storing diffs described by Michael Isard in a talk at Berkeley in February, 2012.

    Since:
    Ptolemy II 10.0
    Version:
    $Id$
    Author:
    Edward A. Lee
    Pt.AcceptedRating:
    Red (cxh) nil token code
    Pt.ProposedRating:
    Yellow (cxh)
    • Constructor Detail

      • UpdatedArrayToken

        public UpdatedArrayToken​(ArrayToken baseToken,
                                 int index,
                                 Token newValue)
                          throws IllegalActionException
        Construct an UpdatedArrayToken that is equal to the specified baseToken, except at index, where its value is newValue. The type of the resulting array type is the least upper bound of the types of the elements, which is not necessarily the same as the type of the base token.
        Parameters:
        baseToken - The base array.
        index - The index of the new value.
        newValue - The updated value.
        Throws:
        IllegalActionException - If the index is out of range for the base token.
    • Method Detail

      • getElement

        public Token getElement​(int index)
        Return the element at the specified index.
        Overrides:
        getElement in class ArrayToken
        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.
      • length

        public int length()
        Return the length of the contained token array.
        Overrides:
        length in class ArrayToken
        Returns:
        The length of the contained token array.