|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.util.Observable com.singularsys.jep.Variable
public class Variable
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.
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. |
boolean |
setValue(java.lang.Object object,
java.util.Observer observer)
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 |
---|
protected java.lang.String name
Constructor Detail |
---|
protected Variable(java.lang.String name)
VariableFactory
which are in turned called by VariableTable
.
protected Variable(java.lang.String name, java.lang.Object value)
VariableFactory
which are in turned called by VariableTable
.
protected Variable(Variable var)
var
- Method Detail |
---|
public java.lang.String getName()
public boolean isConstant()
public void setIsConstant(boolean b)
b
- true if the variable is a constant.public java.lang.Object getValue()
public boolean hasValidValue()
public void setValidValue(boolean val)
public boolean setValue(java.lang.Object object)
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.
public final boolean setValue(java.lang.Object object, java.util.Observer observer)
object
- observer
-
protected boolean setValueRaw(java.lang.Object object)
This method sets the validValue flag to true.
object
-
public java.lang.String toString()
a: 10If the variable is a constant the string " (Constant)" is appended.
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |