Package com.singularsys.jep.misc.publishingvariable

# Class PublishingVariableTable

java.lang.Object
com.singularsys.jep.VariableTable
com.singularsys.jep.misc.DecoratingVariableTable
com.singularsys.jep.misc.publishingvariable.PublishingVariableTable

All Implemented Interfaces:
  `JepComponent`, `Serializable`

public class PublishingVariableTable extends DecoratingVariableTable
A VariableTable which publishes changes to its content. This uses the `Flow` system of publishers and subscribers. Changes to the table, such as adding and removing variables, and changing the value of a variable are published as `VariableTableAction`s.

Two statics factories can be used for creating SubmissionPublishers, `createDefaultPublisher()` and `createCurrentThreadPublisher()`.

See Also:
  - Serialized Form

- ## Field Summary

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

  `table, vf`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `PublishingVariableTable(SubmissionPublisher<VariableTableAction> publisher)`
  Constructor with a specified publisher.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Variable`
  `addConstant(String name, Object value)`
  Adds a constant to the table.
  `Variable`
  `addVariable(String name)`
  Adds a variable to the table.
  `Variable`
  `addVariable(String name, Object value)`
  Adds a variable to the table.
  `void`
  `clear()`
  Clears all variables from the table, removes all subscribers and publishes a `VariableTableAction.Actions.CLEAR_TABLE` to indicate the table has been cleared.
  `static SubmissionPublisher<VariableTableAction>`
  `createCurrentThreadPublisher()`
  Creates a SubmissionPublisher with an `Executor` which uses the current thread, and the default buffer capacity.
  `static SubmissionPublisher<VariableTableAction>`
  `createDefaultPublisher()`
  Create a default `SubmissionPublisher`.
  `static PublishingVariableTable`
  `decoratorInstance(VariableTable base, SubmissionPublisher<VariableTableAction> pub)`
  Creates a decorating instance This used the default `SubmissionPublisher`
  `JepComponent`
  `getLightWeightInstance()`
  Creates a new PublishingVariableTable with a null publisher.
  `SubmissionPublisher<VariableTableAction>`
  `getPublisher()`
  Get the publisher for this variable table.
  `Variable`
  `remove(String name)`
  Remove a variable with a given name from the table.
  `void`
  `removeNonConstants()`
  Clears all non constant variables from the table, removes all subscribers and publishes a `VariableTableAction.Actions.CLEAR_NON_CONSTANT` to indicate the table has been cleared.
  `void`
  `setPublisher(SubmissionPublisher<VariableTableAction> publisher)`
  Set the publisher for this variable table.
  `void`
  `setPublisherForAllVariables(SubmissionPublisher<VariableTableAction> publisher)`
  Set the publisher for all variables in this variable table.

  ### Methods inherited from class com.singularsys.jep.misc.DecoratingVariableTable

  `clearValues, containsKey, containsVariable, copyConstantsFrom, copyVariablesFrom, getBase, getVariable, getVariableFactory, getVariables, init, isEmpty, keySet, remove, setVariableFactory, size, toString, values`

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

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

- ## Constructor Details

  - ### PublishingVariableTable

    public PublishingVariableTable(SubmissionPublisher<VariableTableAction> publisher)
    Constructor with a specified publisher.
    Parameters:
      `publisher` - the publisher

- ## Method Details

  - ### decoratorInstance

    public static PublishingVariableTable decoratorInstance(VariableTable base, SubmissionPublisher<VariableTableAction> pub)
    Creates a decorating instance This used the default `SubmissionPublisher`
    Parameters:
      `base` - base VariableTable
    Returns:
      a new PublishingVariableTable

  - ### addVariable

    public Variable addVariable(String name)
    Adds a variable to the table.
    Overrides:
      `addVariable` in class `DecoratingVariableTable`
    Parameters:
      `name` - variable name, will be converted to lower case
    Returns:
      the variable
    Throws:
      `IllegalStateException` - if the publisher is closed.

  - ### addVariable

    public Variable addVariable(String name, Object value) throws JepException
    Adds a variable to the table.
    Overrides:
      `addVariable` in class `DecoratingVariableTable`
    Parameters:
      `name` - variable name, will be converted to lower case
      `value` - initial value
    Returns:
      the variable
    Throws:
      `IllegalStateException` - if the publisher is closed.
      `JepException` - if an attempt is made to set the value of a constant variable

  - ### addConstant

    public Variable addConstant(String name, Object value) throws JepException
    Adds a constant to the table.
    Overrides:
      `addConstant` in class `DecoratingVariableTable`
    Parameters:
      `name` - variable name
      `value` - variable value
    Returns:
      the corresponding Variable object
    Throws:
      `IllegalStateException` - if the publisher is closed.
      `JepException` - if an attempt is made to set the value of an existing constant variable

  - ### remove

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

  - ### clear

    public void clear()
    Clears all variables from the table, removes all subscribers and publishes a `VariableTableAction.Actions.CLEAR_TABLE` to indicate the table has been cleared.
    Overrides:
      `clear` in class `DecoratingVariableTable`

  - ### removeNonConstants

    public void removeNonConstants()
    Clears all non constant variables from the table, removes all subscribers and publishes a `VariableTableAction.Actions.CLEAR_NON_CONSTANT` to indicate the table has been cleared.
    Overrides:
      `removeNonConstants` in class `DecoratingVariableTable`

  - ### getPublisher

    public SubmissionPublisher<VariableTableAction> getPublisher()
    Get the publisher for this variable table.
    Returns:
      the publisher

  - ### setPublisher

    public void setPublisher(SubmissionPublisher<VariableTableAction> publisher)
    Set the publisher for this variable table. This will not change the publisher for any existing variables in the table which can be achieved using the `setPublisherForAllVariables(SubmissionPublisher)` method. Nor will it change the publisher for new variables, for that use the `PublishingVariableFactory.setPublisher(SubmissionPublisher)`.
    Parameters:
      `publisher` -

  - ### setPublisherForAllVariables

    public void setPublisherForAllVariables(SubmissionPublisher<VariableTableAction> publisher)
    Set the publisher for all variables in this variable table. This will not change the publisher for this variable table, which can be achieved using the `setPublisher(SubmissionPublisher)`, nor will it change the publisher for new variables, for that use the `PublishingVariableFactory.setPublisher(SubmissionPublisher)`.
    Parameters:
      `publisher` -

  - ### getLightWeightInstance

    public JepComponent getLightWeightInstance()
    Creates a new PublishingVariableTable with a null publisher.
    Specified by:
      `getLightWeightInstance` in interface `JepComponent`
    Overrides:
      `getLightWeightInstance` in class `DecoratingVariableTable`
    Returns:
      a new VariableTable
    See Also:
      - `VariableTable.copyConstantsFrom(VariableTable)`
      - `VariableTable.copyVariablesFrom(VariableTable)`

  - ### createDefaultPublisher

    public static SubmissionPublisher<VariableTableAction> createDefaultPublisher()
    Create a default `SubmissionPublisher`.
    Returns:
      the publisher

  - ### createCurrentThreadPublisher

    public static SubmissionPublisher<VariableTableAction> createCurrentThreadPublisher()
    Creates a SubmissionPublisher with an `Executor` which uses the current thread, and the default buffer capacity.
    Returns:
      the publisher