Class 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
    • Constructor Detail

      • 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 instance
        copyConstants - if true copy the constants, if false leave empty