Class ConcurrentVariableTable
java.lang.Object
com.singularsys.jep.VariableTable
com.singularsys.jep.misc.parallelparsing.ConcurrentVariableTable
- All Implemented Interfaces:
JepComponent,Serializable
A variable table backed by a ConcurrentHashMap that is safe for concurrent
access. Inside the
addVariable(String) methods it uses the
ConcurrentHashMap.computeIfAbsent(Object, java.util.function.Function)
and ConcurrentHashMap.compute(Object, java.util.function.BiFunction)
to atomically create variables when needed. As a consequence, the
addVariable(String) methods may block while a variable is created in
another thread.- See Also:
-
Field Summary
Fields inherited from class com.singularsys.jep.VariableTable
table, vf -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.Copy constructor, For each variable from the source table create a new variable. -
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.voidclear()Clears all variables from the table.voidClears the values of all non-constant variables.booleancontainsKey(String key) Returns true if the table contains a variable with the given name.booleancontainsVariable(Variable value) Returns true if the table contains the given variable.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.voidInitialize the component.booleanisEmpty()Returns true if the table is empty.keySet()Returns the names of all the variables.Remove a variable from the table.Remove a variable with a given name from the table.voidRemove all variables from the table which are not constants.intsize()The number of variables in the table.values()Deprecated.Methods inherited from class com.singularsys.jep.VariableTable
copyConstantsFrom, copyVariablesFrom, getVariableFactory, setVariableFactory, toString
-
Constructor Details
-
ConcurrentVariableTable
public ConcurrentVariableTable()Default constructor. -
ConcurrentVariableTable
Copy constructor, For each variable from the source table create a new variable.- Parameters:
tbl- source table
-
-
Method Details
-
init
Description copied from interface:JepComponentInitialize 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:
initin interfaceJepComponent- Overrides:
initin classVariableTable- Parameters:
j- the current Jep instance
-
addVariable
Description copied from class:VariableTableAdds a new variable with no value specified. If the variable already exists in the table, that variable instance is returned. Otherwise, a newVariableinstance is created with the variable factory.- Overrides:
addVariablein classVariableTable- Parameters:
name- the variable's name- Returns:
- the variable
-
addVariable
Description copied from class:VariableTableAdds 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.- Overrides:
addVariablein classVariableTable- 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
Description copied from class:VariableTableAdds 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.- Overrides:
addConstantin classVariableTable- Parameters:
name- variable namevalue- variable value- Returns:
- the corresponding Variable object
- Throws:
JepException- if an attempt is made to set the value of an existing constant variable
-
getVariable
Description copied from class:VariableTableGets an existing variable, returns null if variable is not found.- Overrides:
getVariablein classVariableTable- Parameters:
name- variable name- Returns:
- the variable
-
clear
public void clear()Description copied from class:VariableTableClears all variables from the table.- Overrides:
clearin classVariableTable
-
isEmpty
public boolean isEmpty()Description copied from class:VariableTableReturns true if the table is empty.- Overrides:
isEmptyin classVariableTable- Returns:
- true if the table is empty
-
keySet
Description copied from class:VariableTableReturns the names of all the variables.- Overrides:
keySetin classVariableTable- Returns:
- a collection Strings with the variable names.
-
getVariables
Description copied from class:VariableTableReturns 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.- Overrides:
getVariablesin classVariableTable- Returns:
- a collection of all the variables.
-
remove
Description copied from class:VariableTableRemove a variable with a given name from the table.- Overrides:
removein classVariableTable- Parameters:
varname- name of the variable to remove- Returns:
- the removed variable or null if the variable does not exist in the table.
-
remove
Description copied from class:VariableTableRemove a variable from the table.- Overrides:
removein classVariableTable- Parameters:
var- the variable to remove- Returns:
- the removed variable or null if the variable does not exist in the table.
-
values
Deprecated.usegetVariables().A collection of all the variables. Replace withgetVariables()- Overrides:
valuesin classVariableTable- Returns:
- a collection of all the variables.
-
size
public int size()Description copied from class:VariableTableThe number of variables in the table.- Overrides:
sizein classVariableTable- Returns:
- the number of variables
-
containsKey
Description copied from class:VariableTableReturns true if the table contains a variable with the given name.- Overrides:
containsKeyin classVariableTable- Parameters:
key- variable name- Returns:
- true if the table contains the variable
-
containsVariable
Description copied from class:VariableTableReturns true if the table contains the given variable.- Overrides:
containsVariablein classVariableTable- Parameters:
value- the variable- Returns:
- true if the variable is in the table
-
getLightWeightInstance
Description copied from class:VariableTableReturns a new empty VariableTable.- Specified by:
getLightWeightInstancein interfaceJepComponent- Overrides:
getLightWeightInstancein classVariableTable- Returns:
- a new VariableTable
- See Also:
-
clearValues
public void clearValues()Description copied from class:VariableTableClears the values of all non-constant variables. This will set theVariable.setValidValue(boolean)to false.- Overrides:
clearValuesin classVariableTable
-
removeNonConstants
public void removeNonConstants()Description copied from class:VariableTableRemove all variables from the table which are not constants.- Overrides:
removeNonConstantsin classVariableTable
-
getVariables().