Package com.singularsys.jep.misc.parallelparsing

# Class ConcurrentVariableTable

java.lang.Object
com.singularsys.jep.VariableTable
com.singularsys.jep.misc.parallelparsing.ConcurrentVariableTable

All Implemented Interfaces:
  `JepComponent`, `Serializable`

public class ConcurrentVariableTable extends VariableTable
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:
  - Serialized Form

- ## Field Summary

  ### Fields inherited from class com.singularsys.jep.VariableTable

  `table, vf`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ConcurrentVariableTable()`
  Default constructor.
  `ConcurrentVariableTable(VariableTable tbl)`
  Copy constructor, For each variable from the source table create a new variable.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Variable`
  `addConstant(String name, Object value)`
  Adds a new variable which is marked as a constant.
  `Variable`
  `addVariable(String name)`
  Adds a new variable with no value specified.
  `Variable`
  `addVariable(String name, Object value)`
  Adds a new variable with specified value.
  `void`
  `clear()`
  Clears all variables from the table.
  `void`
  `clearValues()`
  Clears the values of all non-constant variables.
  `boolean`
  `containsKey(String key)`
  Returns true if the table contains a variable with the given name.
  `boolean`
  `containsVariable(Variable value)`
  Returns true if the table contains the given variable.
  `JepComponent`
  `getLightWeightInstance()`
  Returns a new empty VariableTable.
  `Variable`
  `getVariable(String name)`
  Gets an existing variable, returns null if variable is not found.
  `Collection<Variable>`
  `getVariables()`
  Returns a list of all the variables in the table.
  `void`
  `init(Jep j)`
  Initialize the component.
  `boolean`
  `isEmpty()`
  Returns true if the table is empty.
  `Set<String>`
  `keySet()`
  Returns the names of all the variables.
  `Variable`
  `remove(Variable var)`
  Remove a variable from the table.
  `Variable`
  `remove(String varname)`
  Remove a variable with a given name from the table.
  `void`
  `removeNonConstants()`
  Remove all variables from the table which are not constants.
  `int`
  `size()`
  The number of variables in the table.
  `Collection<Variable>`
  `values()`
  Deprecated.
  use `getVariables()`.

  ### Methods inherited from class com.singularsys.jep.VariableTable

  `copyConstantsFrom, copyVariablesFrom, getVariableFactory, setVariableFactory, toString`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### ConcurrentVariableTable

    public ConcurrentVariableTable()
    Default constructor.

  - ### ConcurrentVariableTable

    public ConcurrentVariableTable(VariableTable tbl)
    Copy constructor, For each variable from the source table create a new variable.
    Parameters:
      `tbl` - source table

- ## Method Details

  - ### init

    public void init(Jep j)
    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 interface `JepComponent`
    Overrides:
      `init` in class `VariableTable`
    Parameters:
      `j` - the current Jep instance

  - ### addVariable

    public Variable addVariable(String name)
    Description copied from class: `VariableTable`
    Adds a new variable with no value specified. If the variable already exists in the table, that variable instance is returned. Otherwise, a new `Variable` instance is created with the variable factory.
    Overrides:
      `addVariable` in class `VariableTable`
    Parameters:
      `name` - the variable's name
    Returns:
      the variable

  - ### addVariable

    public Variable addVariable(String name, Object value) throws JepException
    Description copied from class: `VariableTable`
    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.
    Overrides:
      `addVariable` in class `VariableTable`
    Parameters:
      `name` - the name of the variable
      `value` - 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

    public Variable addConstant(String name, Object value) throws JepException
    Description copied from class: `VariableTable`
    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.
    Overrides:
      `addConstant` in class `VariableTable`
    Parameters:
      `name` - variable name
      `value` - variable value
    Returns:
      the corresponding Variable object
    Throws:
      `JepException` - if an attempt is made to set the value of an existing constant variable

  - ### getVariable

    public Variable getVariable(String name)
    Description copied from class: `VariableTable`
    Gets an existing variable, returns null if variable is not found.
    Overrides:
      `getVariable` in class `VariableTable`
    Parameters:
      `name` - variable name
    Returns:
      the variable

  - ### clear

    public void clear()
    Description copied from class: `VariableTable`
    Clears all variables from the table.
    Overrides:
      `clear` in class `VariableTable`

  - ### isEmpty

    public boolean isEmpty()
    Description copied from class: `VariableTable`
    Returns true if the table is empty.
    Overrides:
      `isEmpty` in class `VariableTable`
    Returns:
      true if the table is empty

  - ### keySet

    public Set<String> keySet()
    Description copied from class: `VariableTable`
    Returns the names of all the variables.
    Overrides:
      `keySet` in class `VariableTable`
    Returns:
      a collection Strings with the variable names.

  - ### getVariables

    public Collection<Variable> getVariables()
    Description copied from class: `VariableTable`
    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.
    Overrides:
      `getVariables` in class `VariableTable`
    Returns:
      a collection of all the variables.

  - ### remove

    public Variable remove(String varname)
    Description copied from class: `VariableTable`
    Remove a variable with a given name from the table.
    Overrides:
      `remove` in class `VariableTable`
    Parameters:
      `varname` - name of the variable to remove
    Returns:
      the removed variable or null if the variable does not exist in the table.

  - ### remove

    public Variable remove(Variable var)
    Description copied from class: `VariableTable`
    Remove a variable from the table.
    Overrides:
      `remove` in class `VariableTable`
    Parameters:
      `var` - the variable to remove
    Returns:
      the removed variable or null if the variable does not exist in the table.

  - ### values

    @Deprecated public Collection<Variable> values()
    Deprecated.
    use `getVariables()`.
    A collection of all the variables. Replace with `getVariables()`
    Overrides:
      `values` in class `VariableTable`
    Returns:
      a collection of all the variables.

  - ### size

    public int size()
    Description copied from class: `VariableTable`
    The number of variables in the table.
    Overrides:
      `size` in class `VariableTable`
    Returns:
      the number of variables

  - ### containsKey

    public boolean containsKey(String key)
    Description copied from class: `VariableTable`
    Returns true if the table contains a variable with the given name.
    Overrides:
      `containsKey` in class `VariableTable`
    Parameters:
      `key` - variable name
    Returns:
      true if the table contains the variable

  - ### containsVariable

    public boolean containsVariable(Variable value)
    Description copied from class: `VariableTable`
    Returns true if the table contains the given variable.
    Overrides:
      `containsVariable` in class `VariableTable`
    Parameters:
      `value` - the variable
    Returns:
      true if the variable is in the table

  - ### getLightWeightInstance

    public JepComponent getLightWeightInstance()
    Description copied from class: `VariableTable`
    Returns a new empty VariableTable.
    Specified by:
      `getLightWeightInstance` in interface `JepComponent`
    Overrides:
      `getLightWeightInstance` in class `VariableTable`
    Returns:
      a new VariableTable
    See Also:
      - `VariableTable.copyConstantsFrom(VariableTable)`
      - `VariableTable.copyVariablesFrom(VariableTable)`

  - ### clearValues

    public void clearValues()
    Description copied from class: `VariableTable`
    Clears the values of all non-constant variables. This will set the `Variable.setValidValue(boolean)` to false.
    Overrides:
      `clearValues` in class `VariableTable`

  - ### removeNonConstants

    public void removeNonConstants()
    Description copied from class: `VariableTable`
    Remove all variables from the table which are not constants.
    Overrides:
      `removeNonConstants` in class `VariableTable`