Class Constants


  • public class Constants
    extends java.lang.Object
    A table of named constants that are recognized by the expression parser.

    A named constant in an expression is substituted by its associated value when the expression is evaluated. The constants are stored in a hash table, using their names as key. The value of each constant is wrapped in a data token.

    Since:
    Ptolemy II 2.0
    Version:
    $Id$
    Author:
    Xiaojun Liu
    See Also:
    PtParser
    Pt.AcceptedRating:
    Red (liuxj)
    Pt.ProposedRating:
    Red (liuxj)
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void add​(java.lang.String name, Token value)
      Add a constant with the given name and value to the table.
      static RecordToken constants()
      Return a record representation of the constants.
      static Token get​(java.lang.String name)
      Look up the value of the constant with the given name.
      static Type nameToType​(java.lang.String name)
      Given a name defining a type, return the type, or null if there is no such type.
      static void remove​(java.lang.String name)
      Remove the constant with the given name from the table.
      static java.util.TreeMap types()
      Return a map from names to types, with the names sorted alphabetically.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • add

        public static void add​(java.lang.String name,
                               Token value)
        Add a constant with the given name and value to the table. If a constant with this same name had been previously added, then that value is replaced with the new one. Neither the name nor the value can be null, otherwise a NullPointerException will be thrown.
        Parameters:
        name - The name of the constant.
        value - The value of the constant, wrapped in a data token.
      • constants

        public static RecordToken constants()
        Return a record representation of the constants.
        Returns:
        A record with the constants and their values.
        Since:
        Ptolemy II 2.1
      • get

        public static Token get​(java.lang.String name)
        Look up the value of the constant with the given name.
        Parameters:
        name - The name of the constant.
        Returns:
        The value of the constant, wrapped in a data token, or null if there is no constant with the given name in the table.
      • nameToType

        public static Type nameToType​(java.lang.String name)
        Given a name defining a type, return the type, or null if there is no such type.
        Parameters:
        name - The type name.
      • remove

        public static void remove​(java.lang.String name)
        Remove the constant with the given name from the table. If there is no constant with the given name in the table, the table is not changed.
        Parameters:
        name - The name of the constant to be removed from the table.
      • types

        public static java.util.TreeMap types()
        Return a map from names to types, with the names sorted alphabetically.
        Returns:
        A copy of the table of named types.