Package com.singularsys.jep.misc

# Class LightWeightComponentSet

java.lang.Object
com.singularsys.jep.ComponentSet
com.singularsys.jep.misc.LightWeightComponentSet

public class LightWeightComponentSet extends ComponentSet

A lightweight set of components reusing components from an existing Jep instance. This class will reuse the NumberFactory, VariableFactory, FunctionTable, OperatorTable, and PrintVisitor components of the supplied Jep. It will have a NullParser so it can not be used for parsing expressions. New copies of the VariableTable, StandardEvaluator and NodeFactory are used. The VariableTable will be filled with the copies of the variables in the supplied instances' variable table.

To construct a lightweight jep instance use

     Jep j = new Jep();
     LightWeightComponentSet lwcs = new LightWeightComponentSet(j);
     Jep j2 = new Jep(lwcs);

Such instance typically use 1kB compared to 56kB bytes for a Jep instance with a StandardParser and 14kB bytes with a configurable parser.

As this reuses the function table and PostfixMathCommands in it there may be cases where the pfmc are not optimized for use in multiple threads `Random` is the only example of this. While safe to use in multiple threads efficiency is improved if each thread has its own copy. If this is an issue the `MediumWeightComponentSet` class can be use or the `shallowCopy()` methods of FunctionTable/OperatorTable can be used.

     Jep j = new Jep();
     LightWeightComponentSet lwcs = new LightWeightComponentSet(j);
     FunctionTable ft = lwcs.getFunctionTable().shallowCopy();
     // use new instances of the pfmc's
     lwcs.setFunctionTable(ft);

As of Jep version 3.5 the LightWeightComponentSet uses a Null Print Visitor so cannot print.

See Also:
  - `MediumWeightComponentSet`

- ## Field Summary

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

  `auxComps, evaluator, funTab, nodeFac, numFac, opTab, parser, pv, varFac, varTab`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `LightWeightComponentSet(Jep jep)`
  Create a lightweight instance with copies of all variables
  `LightWeightComponentSet(Jep jep, boolean copyConstants)`
  Create a lightweight instance either with an empty variable table or one with just the constants.
  `LightWeightComponentSet(Jep baseJep, JepComponent... replacements)`
  Create a lightweight instance with copies of all components from the base Jep instance

- ## Method Summary

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

  `addAuxComponent, addComponents, findOrElse, getAuxComponents, getAuxComps, getBaseComponents, getComponents, getEvaluator, getFunctionTable, getNodeFactory, getNumberFactory, getOperatorTable, getParser, getPrintVisitor, getVariableFactory, getVariableTable, setAuxComps, setEvaluator, setFunctionTable, setNodeFactory, setNumberFactory, setOperatorTable, setParser, setPrintVisitor, setVariableFactory, setVariableTable`

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

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

- ## Constructor Details

  - ### LightWeightComponentSet

    public LightWeightComponentSet(Jep jep)
    Create a lightweight instance with copies of all variables

  - ### LightWeightComponentSet

    public LightWeightComponentSet(Jep jep, boolean copyConstants)
    Create a lightweight instance either with an empty variable table or one with just the constants.
    Parameters:
      `jep` - the source to copy components from
      `copyConstants` - if true copy the constants, if false leave empty

  - ### LightWeightComponentSet

    public LightWeightComponentSet(Jep baseJep, JepComponent... replacements)
    Create a lightweight instance with copies of all components from the base Jep instance
    Parameters:
      `baseJep` - the source to copy components from
      `replacements` - components to use in preference to those in the baseJep