Package com.singularsys.jep
Class VariableTable
java.lang.Object
com.singularsys.jep.VariableTable
- All Implemented Interfaces:
JepComponent
,Serializable
- Direct Known Subclasses:
CaseInsensitiveVariableTable
,RealVariableTable
,StandardVariableTable
A table of variables.
- See Also:
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionaddConstant
(String name, Object value) Adds a new variable which is marked as a constant.addVariable
(String name) Adds a new variable with no value specified.addVariable
(String name, Object value) Adds a new variable with specified value.void
clear()
Clears all variables from the table.void
Clears the values of all non-constant variables.boolean
containsKey
(String key) boolean
containsVariable
(Variable value) void
Copies all the constants from a variable table into this table.void
Copies all the variables from a variable table into this table Copies all properties of the variable, including isConstant, validValue flags and all hook keys.Returns a new empty VariableTable.getVariable
(String name) Gets an existing variable, returns null if variable is not found.Returns a list of all the variables in the table.void
Initialize the component.boolean
isEmpty()
keySet()
Returns the names of all the variables.Remove a variable from the table.Remove a variable with a given name from the table.void
Remove all variables from the table which are not constants.void
int
size()
toString()
values()
Deprecated.
-
Field Details
-
table
-
vf
-
-
Constructor Details
-
VariableTable
public VariableTable() -
VariableTable
-
-
Method Details
-
init
Description copied from interface:JepComponent
Initialize the component. This method 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 interfaceJepComponent
- Parameters:
j
- the current Jep instance
-
setVariableFactory
-
getVariableFactory
-
addVariable
Adds a new variable with no value specified. If the variable already exists in the table, that variable instance is returned. Otherwise, a newVariable
instance is created with the variable factory.- Parameters:
name
- the variable's name- Returns:
- the variable
-
addVariable
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 variablevalue
- 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
Adds a new variable which is marked as a constant. Its value will also be marked as valid, in particular a null value is valid for 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
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
Returns the names of all the variables.- Returns:
- a collection Strings with the variable names.
-
getVariables
Returns a list of all the variables in the table. Just returns a view. Does not do a deep copy so changes to this collection will affect the underlying table. -
remove
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
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.A collection of all the variables. Replace withgetVariables()
-
size
public int size() -
containsKey
-
containsVariable
-
toString
-
getLightWeightInstance
Returns a new empty VariableTable.- Specified by:
getLightWeightInstance
in interfaceJepComponent
- Returns:
- a new VariableTable
- See Also:
-
copyConstantsFrom
Copies all the constants from a variable table into this table. Copies all properties of the variable, including isConstant, validValue flags and all hook keys. If there already is a variable with the same name all properties are copied and pre-existing hooks deleted.- Parameters:
vt
- source variable table
-
copyVariablesFrom
Copies all the variables from a variable table into this table Copies all properties of the variable, including isConstant, validValue flags and all hook keys. If there already is a variable with the same name all properties are copied and pre-existing hooks deleted.- Parameters:
vt
- source variable table
-
clearValues
public void clearValues()Clears the values of all non-constant variables. This will set theVariable.setValidValue(boolean)
to false.- Since:
- 3.4.0
-
removeNonConstants
public void removeNonConstants()Remove all variables from the table which are not constants.- Since:
- 3.5
-