Class CaseInsensitiveFunctionTable

java.lang.Object
com.singularsys.jep.FunctionTable
com.singularsys.jep.misc.CaseInsensitiveFunctionTable
All Implemented Interfaces:
JepComponent, Serializable

public class CaseInsensitiveFunctionTable extends FunctionTable
A version of a function table which is case-insensitive.

Note that this table does not include any functions by default. You will need to add any functions you need.

 jep = new Jep();
 jep.setComponent(new CaseInsensitiveFunctionTable());
 jep.addFunction("if",new If());
 jep.parse("if(1>0,2,3)");
 System.out.println(jep.evaluate());
 

If you want to include all the functions in an existing table you can use

 FunctionTable oldFT = jep.getFunctionTable();
 jep.setComponent(new CaseInsensitiveFunctionTable());
 for(Entry<String, PostfixMathCommandI> ent:oldFT.entrySet()) {
     jep.addFunction(ent.getKey(), ent.getValue());
 }
 
See Also:
  • Constructor Details

    • CaseInsensitiveFunctionTable

      public CaseInsensitiveFunctionTable()
    • CaseInsensitiveFunctionTable

      protected CaseInsensitiveFunctionTable(Map<String,PostfixMathCommandI> tbl)
  • Method Details

    • getFunction

      public PostfixMathCommandI getFunction(String name)
      Description copied from class: FunctionTable
      Get the function with the given name.
      Overrides:
      getFunction in class FunctionTable
      Parameters:
      name - function name
      Returns:
      the function or null if not found
    • addFunction

      public PostfixMathCommandI addFunction(String name, PostfixMathCommandI pfmc)
      Description copied from class: FunctionTable
      Add a function to the table.
      Overrides:
      addFunction in class FunctionTable
      Parameters:
      name - name of the function
      pfmc - the implementation of the function
      Returns:
      the previous function with the same name or null if none
    • containsKey

      public boolean containsKey(String key)
      Overrides:
      containsKey in class FunctionTable
    • shallowCopy

      public FunctionTable shallowCopy()
      Description copied from class: FunctionTable
      Returns a new shallow copy of this function table. Calls the FunctionTable.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 FunctionTable.threadSafeMapCopy() method to return a copy of the map of functions and a constructor taking this map which uses the FunctionTable(Map) constructor.
      Overrides:
      shallowCopy in class FunctionTable
      Returns:
      a new shallow copy of this function table