ptolemy.data.expr
Class Constants

java.lang.Object
  extended by ptolemy.data.expr.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: Constants.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Xiaojun Liu
See Also:
PtParser
Accepted Rating:
Red (liuxj)
Proposed Rating:
Red (liuxj)

Field Summary
private static java.util.Hashtable _table
           
private static java.util.TreeMap _types
          The treemap containing the named constants.
 
Constructor Summary
private Constants()
           
 
Method Summary
private static void _putProperty(java.lang.String variableName, java.lang.String property)
           
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 void remove(java.lang.String name)
          Remove the constant with the given name from the table.
static java.util.TreeMap types()
          Return a copy of the types.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_table

private static java.util.Hashtable _table

_types

private static java.util.TreeMap _types
The treemap containing the named constants. We use a treemap so that we get sorting in natural order.

Constructor Detail

Constants

private Constants()
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.

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 copy of the types.

Returns:
a copy of the hash table tha name types.

_putProperty

private static void _putProperty(java.lang.String variableName,
                                 java.lang.String property)