Package com.singularsys.jep
Class Variable
java.lang.Object
com.singularsys.jep.Variable
- All Implemented Interfaces:
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.
- Version:
- 2.3.0 beta 2 Now extends Observable so observers can track if the value has been changed., 4.1.0 Observable removed as deprecated since Java 9
- Author:
- Richard Morris Created on 18-Nov-2003
- See Also:
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptiongetHook
(Node.HookKey key) Get the value associated with a key.getName()
Returns the variable name.getValue()
Returns the variable's value.boolean
Is the value of this variable valid?hookKeys()
Return all the hooks set for this variable.boolean
Returns true if the variable is a constant.removeHook
(Node.HookKey key) Remove a hook from a variablesetHook
(Node.HookKey key, 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
Sets the value of the variable.protected boolean
setValueRaw
(Object object) In general subclasses should override this method rather than setValue.toString()
Returns a string with the variable name followed by its value.
-
Field Details
-
name
-
keys
-
keyVals
-
-
Constructor Details
-
Variable
Constructors are protected. Variables should only be created through the associatedVariableFactory
which are in turned called byVariableTable
. -
Variable
Constructors are protected. Variables should only be created through the associatedVariableFactory
which are in turned called byVariableTable
. -
Variable
Copy constructor- Parameters:
var
-
-
-
Method Details
-
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
Returns the variable's value.- Returns:
- the Variable value as Object.
-
hasValidValue
public boolean hasValidValue()Is the value of this variable valid?- Returns:
- whether the value is valid
-
setValidValue
public void setValidValue(boolean val) Sets whether the value of variable is valid. Constant values are not affected, that is always valid. -
setValue
Sets the value of the variable. Constant values cannot be changed.Calls
setValueRaw(Object)
subclasses should override that method.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, 4.1 removed Observable
-
setValueRaw
In general subclasses should override this method rather than setValue.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
-
getHook
Get the value associated with a key.- Parameters:
key
- the key to look up- Returns:
- the value or null if no key exists
- Since:
- 3.5
-
setHook
Sets the value associated with a key.- Parameters:
key
- the keyvalue
- the value- Returns:
- the old object associated with this key, may be null
- Since:
- 3.5
-
hookKeys
Return all the hooks set for this variable.- Returns:
- a list of all the hooks, an empty list if none set
- Since:
- 3.5
-
removeHook
Remove a hook from a variable- Parameters:
key
-- Returns:
- the value of the removed hook or null if hook not found
- Since:
- 3.5
-
toString
Returns a string with the variable name followed by its 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.
-