public class Variable
extends java.util.Observable
implements java.io.Serializable
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.
Modifier and Type | Field and Description |
---|---|
protected Node.HookKey[] |
keys |
protected java.lang.Object[] |
keyVals |
protected java.lang.String |
name |
Modifier | Constructor and Description |
---|---|
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
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
getHook(Node.HookKey key)
Get the value associated with a key.
|
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?
|
java.util.Collection<Node.HookKey> |
hookKeys()
Return all the hooks set for this variable.
|
boolean |
isConstant()
Returns true if the variable is a constant.
|
java.lang.Object |
removeHook(Node.HookKey key)
Remove a hook from a variable
|
java.lang.Object |
setHook(Node.HookKey key,
java.lang.Object value)
Sets the value associated with a key.
|
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.
|
protected java.lang.String name
protected Node.HookKey[] keys
protected java.lang.Object[] keyVals
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
- 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.Object getHook(Node.HookKey key)
key
- the key to look uppublic java.lang.Object setHook(Node.HookKey key, java.lang.Object value)
key
- the keyvalue
- the valuepublic java.util.Collection<Node.HookKey> hookKeys()
public java.lang.Object removeHook(Node.HookKey key)
key
- public java.lang.String toString()
a: 10If the variable is a constant the string " (Constant)" is appended.
toString
in class java.lang.Object
Copyright © 2018 Singular Systems http://www.singularsys.com/jep