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 Variable

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

All Implemented Interfaces:
  java.io.Serializable

    public class Variable

extends java.util.Observable
implements java.io.Serializable

Information about a variable. Each variable has a name, and a value. There is a flag to indicate whether it is a constant or not (constants cannot have their value changed). There is also a flag to indicate whether the value of the variable is valid. If the variable is initialized without a value then its value is said to be invalid.

This class extends java.util.Observable allowing observers to track if the variable value has been changed. Use `addObserver(Observer o)` to add an observer. When the variable value is changed the Observer's `update(o, arg)` method is called, the first argument is the Variable object and the second is the object representing the new value.

Version:
  2.3.0 beta 2 Now extends Observable so observers can track if the value has been changed.
Author:
  Rich Morris Created on 18-Nov-2003
See Also:
  Serialized Form

Field Summary
`protected java.lang.String` | `name`

Constructor Summary
`protected` | `Variable(java.lang.String name)` Constructors are protected.
`protected` | `Variable(java.lang.String name, java.lang.Object value)` Constructors are protected.
`protected` | `Variable(Variable var)` Copy constructor

Method Summary
`java.lang.String` | `getName()` Returns the variable name.
`java.lang.Object` | `getValue()` Returns the variable's value.
`boolean` | `hasValidValue()` Is the value of this variable valid?
`boolean` | `isConstant()` Returns true if the variable is a constant.
`void` | `setIsConstant(boolean b)` Setting this property to true ensures that the value will not be changed.
`void` | `setValidValue(boolean val)` Sets whether the value of variable is valid.
`boolean` | `setValue(java.lang.Object object)` Sets the value of the variable.
`protected boolean` | `setValueRaw(java.lang.Object object)` In general subclasses should override this method rather than setValue.
`java.lang.String` | `toString()` Returns a string with the variable name followed by it's value.

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

### name

    protected java.lang.String name

Constructor Detail

### Variable

    protected Variable(java.lang.String name)

  Constructors are protected. Variables should only be created through the associated `VariableFactory` which are in turned called by `VariableTable`.

### Variable

    protected Variable(java.lang.String name,
                       java.lang.Object value)

  Constructors are protected. Variables should only be created through the associated `VariableFactory` which are in turned called by `VariableTable`.

### Variable

    protected Variable(Variable var)

  Copy constructor

  Parameters:
    `var` -

Method Detail

### getName

    public java.lang.String getName()

  Returns the variable name.

  Returns:
    the variable name.

### isConstant

    public boolean isConstant()

  Returns true if the variable is a constant.

### setIsConstant

    public void setIsConstant(boolean b)

  Setting this property to true ensures that the value will not be changed.

  Parameters:
    `b` - true if the variable is a constant.

### getValue

    public java.lang.Object getValue()

  Returns the variable's value.

  Returns:
    the Variable value as Object.

### hasValidValue

    public boolean hasValidValue()

  Is the value of this variable valid?

### setValidValue

    public void setValidValue(boolean val)

  Sets whether the value of variable is valid.

### setValue

    public boolean setValue(java.lang.Object object)

  Sets the value of the variable. Constant values cannot be changed.

  This method calls java.util.Observable.notifyObservers() to indicate to anyone interested that the value has been changed. Note subclasses should override setValueRaw rather than this method so they do not need to handle the Observable methods.

  This method sets the validValue flag to true.

  Returns:
    false if tried to change a constant value.
  Since:
    2.3.0 beta 2 added Observable

### setValueRaw

    protected boolean setValueRaw(java.lang.Object object)

  In general subclasses should override this method rather than setValue. This is because setValue notifies any observers and then calls this method.

  This method sets the validValue flag to true.

  Parameters:
    `object` -
  Returns:
    false if tried to change a constant value.
  Since:
    2.3.0 beta 2

### toString

    public java.lang.String toString()

  Returns a string with the variable name followed by it's value. For example for the variable "a" with the value 10, the following string is returned:

      a: 10

  If the variable is a constant the string " (Constant" is appended.

  Overrides:
    `toString` in class `java.lang.Object`
  Returns:
    A string with the variable name and value.

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