Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.singularsys.jep
Class VariableTable

    java.lang.Object
      java.util.Observable
          com.singularsys.jep.VariableTable

All Implemented Interfaces:
  JepComponent, java.io.Serializable

Direct Known Subclasses:
  CaseInsensitiveVariableTable, StandardVariableTable

    public class VariableTable

extends java.util.Observable
implements JepComponent

A table of variables. This class implements Observable and observers will be notified when new variables are added, or removed, but not when their values are changed. Use `Variable.addObserver()` to monitor individual variables.

See Also:
  `for a base class for monotoring a VariableTable.`, Serialized Form

Field Summary
`protected java.util.HashMap<java.lang.String,Variable>` | `table`
`protected VariableFactory` | `vf`

Constructor Summary
`VariableTable()`
`VariableTable(VariableTable tbl)`

Method Summary
`Variable` | `addConstant(java.lang.String name, java.lang.Object value)` Adds a new variable which is marked as a constant.
`Variable` | `addVariable(java.lang.String name)` Adds a new variable with no value specified.
`Variable` | `addVariable(java.lang.String name, java.lang.Object value)` Adds a new variable with specified value.
`void` | `clear()` Clears all variables from the table.
`boolean` | `containsKey(java.lang.String key)`
`boolean` | `containsVariable(Variable value)`
`void` | `copyConstantsFrom(VariableTable vt)` Copies all the constants from a variable table into this table
`void` | `copyVariablesFrom(VariableTable vt)` Copies all the variables from a variable table into this table
`JepComponent` | `getLightWeightInstance()` Returns a new empty VariableTable.
`Variable` | `getVariable(java.lang.String name)` Gets an existing variable, returns null if variable is not found.
`VariableFactory` | `getVariableFactory()`
`java.util.Collection<Variable>` | `getVariables()` Returns all the variable in the table.
`void` | `init(Jep j)` Initialize the component.
`boolean` | `isEmpty()`
`java.util.Set<java.lang.String>` | `keySet()` Returns the names of all the variables.
`Variable` | `remove(java.lang.String varname)` Remove a variable with a given name from the table.
`Variable` | `remove(Variable var)` Remove a variable from the table.
`void` | `setVariableFactory(VariableFactory vf)`
`int` | `size()`
`java.lang.String` | `toString()`
`java.util.Collection<Variable>` | `values()` Deprecated.

Methods inherited from class java.util.Observable
`addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### table

    protected java.util.HashMap<java.lang.String,Variable> table

### vf

    protected transient VariableFactory vf

Constructor Detail

### VariableTable

    public VariableTable()

### VariableTable

    public VariableTable(VariableTable tbl)

Method Detail

### init

    public void init(Jep j)

  Description copied from interface: `JepComponent`
  Initialize the component. This methods is called whenever a component is added to Jep. Hence it allows components to keep track of the other components they may rely on.

  Specified by:
    `init` in interface `JepComponent`
  Parameters:
    `j` - the current Jep instance

### setVariableFactory

    public void setVariableFactory(VariableFactory vf)

### getVariableFactory

    public VariableFactory getVariableFactory()

### addVariable

    public Variable addVariable(java.lang.String name)

  Adds a new variable with no value specified. If the variable already exists in the table, that variable instance is returned. Otherwise a new `Variable` instance is created with the variable factory.

  Parameters:
    `name` - the variable's name
  Returns:
    the variable

### addVariable

    public Variable addVariable(java.lang.String name,
                                java.lang.Object value)
                         throws JepException

  Adds a new variable with specified value. If the variable already exists, its value is updated with the new value. If the variable exists and is a constant, the value is not updated and no error is reported. If the variable does not exist, it is created using the variable factory of the jep instance specified with the init(Jep j) method.

  Parameters:
    `name` - the name of the variable
    `value` - the value for the variable to be set to
  Returns:
    the variable added or updated
  Throws:
    `JepException` - if an attempt is made to set the value of a constant variable

### addConstant

    public Variable addConstant(java.lang.String name,
                                java.lang.Object value)
                         throws JepException

  Adds a new variable which is marked as a constant.

  Parameters:
    `name` -
    `value` -
  Returns:
    the corresponding Variable object
  Throws:
    `JepException` - if an attempt is made to set the value of an existing constant variable

### getVariable

    public Variable getVariable(java.lang.String name)

  Gets an existing variable, returns null if variable is not found.

  Parameters:
    `name` -
  Returns:
    the variable

### clear

    public void clear()

  Clears all variables from the table.

### isEmpty

    public boolean isEmpty()

### keySet

    public java.util.Set<java.lang.String> keySet()

  Returns the names of all the variables.

  Returns:
    a collection Strings with the variable names.

### getVariables

    public java.util.Collection<Variable> getVariables()

  Returns all the variable in the table.

### remove

    public Variable remove(java.lang.String varname)

  Remove a variable with a given name from the table.

  Parameters:
    `varname` - name of the variable to remove
  Returns:
    the removed variable or null if the variable does not exist in the table.

### remove

    public Variable remove(Variable var)

  Remove a variable from the table.

  Parameters:
    `var` - the variable to remove
  Returns:
    the removed variable or null if the variable does not exist in the table.

### values

    @Deprecated
    public java.util.Collection<Variable> values()

  Deprecated.

  A collection of all the variables

### size

    public int size()

### containsKey

    public boolean containsKey(java.lang.String key)

### containsVariable

    public boolean containsVariable(Variable value)

### toString

    public java.lang.String toString()

  Overrides:
    `toString` in class `java.lang.Object`

### getLightWeightInstance

    public JepComponent getLightWeightInstance()

  Returns a new empty VariableTable.

  Specified by:
    `getLightWeightInstance` in interface `JepComponent`
  Returns:
    a new VariableTable
  See Also:
    `copyConstantsFrom(VariableTable)`, `copyVariablesFrom(VariableTable)`

### copyConstantsFrom

    public void copyConstantsFrom(VariableTable vt)

  Copies all the constants from a variable table into this table

  Parameters:
    `vt` - source variable table

### copyVariablesFrom

    public void copyVariablesFrom(VariableTable vt)

  Copies all the variables from a variable table into this table

  Parameters:
    `vt` - source variable table

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2008 Singular Systems http://www.singularsys.com/jep