Class FunctionTable

java.lang.Object
com.singularsys.jep.FunctionTable
All Implemented Interfaces:
JepComponent, Serializable
Direct Known Subclasses:
BigDecFunctionTable, CaseInsensitiveFunctionTable, NullWrappedFunctionTable, RealFunctionTable, StandardFunctionTable

public class FunctionTable extends Object implements JepComponent
A table holding details of the functions known to Jep. This class has no functions loaded.
See Also:
  • Field Details

  • Constructor Details

    • FunctionTable

      public FunctionTable()
      Constructor with an empty map.
    • FunctionTable

      protected FunctionTable(Map<String,PostfixMathCommandI> oldMap)
      Constructor with a pre-specified map. Subclasses should define similar constructors to allow the shallowCopy() to work.
      Parameters:
      oldMap - map with existing set of functions
      Since:
      4.0
  • Method Details

    • init

      public void init(Jep jep)
      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
      Parameters:
      jep - the current Jep instance
    • copyFunctionsFrom

      public void copyFunctionsFrom(FunctionTable ft)
      Copy all functions from the given function table into this one. Uses the threadSafeMapCopy() method to ensure that the functions are safe to use in a separate thread.
      Parameters:
      ft - the function table to copy from
    • getFunction

      public PostfixMathCommandI getFunction(String name)
      Get the function with the given name.
      Parameters:
      name - function name
      Returns:
      the function or null if not found
    • addFunction

      public PostfixMathCommandI addFunction(String name, PostfixMathCommandI pfmc)
      Add a function to the table.
      Parameters:
      name - name of the function
      pfmc - the implementation of the function
      Returns:
      the previous function with the same name or null if none
      Throws:
      JepRuntimeException - if the function is both a CallbackEvaluationI and a Unary/Binary/Nary/Nullary function
    • clear

      public void clear()
    • entrySet

      public Set<Map.Entry<String,PostfixMathCommandI>> entrySet()
    • isEmpty

      public boolean isEmpty()
    • keySet

      public Set<String> keySet()
    • size

      public int size()
    • values

      public Collection<PostfixMathCommandI> values()
    • containsKey

      public boolean containsKey(String key)
    • containsValue

      public boolean containsValue(PostfixMathCommandI value)
    • remove

      public PostfixMathCommandI remove(String key)
    • getLightWeightInstance

      public JepComponent getLightWeightInstance()
      Returns this. If any functions are not thread-safe then use shallowCopy() instead.
      Specified by:
      getLightWeightInstance in interface JepComponent
      Returns:
      this
    • threadSafeMapCopy

      public Map<String,PostfixMathCommandI> threadSafeMapCopy()
      Return a copy of the internal map with the same set of functions as this one. If any of the pfmc's implement the JepComponent interface then that functions JepComponent.getLightWeightInstance() method will be called to return a thread safe function. This method can be combined with the FunctionTable(Map) constructor to allow subclasses to implement a thread-safe getLightWeightInstance() method.
      Returns:
      Since:
      4.0
    • shallowCopy

      public FunctionTable shallowCopy()
      Returns a new shallow copy of this function table. Calls the threadSafeMapCopy() method to ensure the table is safe to use a separate thread. All subclasses should override this method to create a function table of the matching type. A typical implementation would be
       @Override
       public FunctionTable shallowCopy() {
           Map<String,PostfixMathCommandI> newMap = this.threadSafeMapCopy();
           return new myFunctionTable(newMap);
       }
       
      using the threadSafeMapCopy() method to return a copy of the map of functions and a constructor taking this map which uses the FunctionTable(Map) constructor.
      Returns:
      a new shallow copy of this function table
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • addFunctionIfSet

      protected void addFunctionIfSet(String string, Supplier<PostfixMathCommandI> sup)
      Only add the function if the string is not null and does not start with "!". This depends on syntax for missing resource in JepMessages where the key !property.name! is returned if the resource is missing.
      Parameters:
      string - the name of the function to add or string starting with "!" to omit the function
      sup - supplier of the function to add, this is only called if the function is added
      Since:
      Jep 4.1