Package com.singularsys.jep
Class FunctionTable
java.lang.Object
com.singularsys.jep.FunctionTable
- All Implemented Interfaces:
JepComponent,Serializable
- Direct Known Subclasses:
BigDecFunctionTable,CaseInsensitiveFunctionTable,NullWrappedFunctionTable,RealFunctionTable,StandardFunctionTable
A table holding details of the functions known to Jep.
This class has no functions loaded.
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionConstructor with an empty map.protectedFunctionTable(Map<String, PostfixMathCommandI> oldMap) Constructor with a pre-specified map. -
Method Summary
Modifier and TypeMethodDescriptionaddFunction(String name, PostfixMathCommandI pfmc) Add a function to the table.protected voidaddFunctionIfSet(String string, Supplier<PostfixMathCommandI> sup) Only add the function if the string is not null and does not start with "!".voidclear()booleancontainsKey(String key) booleancontainsValue(PostfixMathCommandI value) voidCopy all functions from the given function table into this one.entrySet()getFunction(String name) Get the function with the given name.Returnsthis.voidInitialize the component.booleanisEmpty()keySet()Returns a new shallow copy of this function table.intsize()Return a copy of the internal map with the same set of functions as this one.toString()values()
-
Field Details
-
table
-
-
Constructor Details
-
FunctionTable
public FunctionTable()Constructor with an empty map. -
FunctionTable
Constructor with a pre-specified map. Subclasses should define similar constructors to allow theshallowCopy()to work.- Parameters:
oldMap- map with existing set of functions- Since:
- 4.0
-
-
Method Details
-
init
Description copied from interface:JepComponentInitialize 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:
initin interfaceJepComponent- Parameters:
jep- the current Jep instance
-
copyFunctionsFrom
Copy all functions from the given function table into this one. Uses thethreadSafeMapCopy()method to ensure that the functions are safe to use in a separate thread.- Parameters:
ft- the function table to copy from
-
getFunction
Get the function with the given name.- Parameters:
name- function name- Returns:
- the function or null if not found
-
addFunction
Add a function to the table.- Parameters:
name- name of the functionpfmc- 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
-
isEmpty
public boolean isEmpty() -
keySet
-
size
public int size() -
values
-
containsKey
-
containsValue
-
remove
-
getLightWeightInstance
Returnsthis. If any functions are not thread-safe then useshallowCopy()instead.- Specified by:
getLightWeightInstancein interfaceJepComponent- Returns:
this
-
threadSafeMapCopy
Return a copy of the internal map with the same set of functions as this one. If any of the pfmc's implement theJepComponentinterface then that functionsJepComponent.getLightWeightInstance()method will be called to return a thread safe function. This method can be combined with theFunctionTable(Map)constructor to allow subclasses to implement a thread-safegetLightWeightInstance()method.- Returns:
- Since:
- 4.0
-
shallowCopy
Returns a new shallow copy of this function table. Calls thethreadSafeMapCopy()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 thethreadSafeMapCopy()method to return a copy of the map of functions and a constructor taking this map which uses theFunctionTable(Map)constructor.- Returns:
- a new shallow copy of this function table
-
toString
-
addFunctionIfSet
Only add the function if the string is not null and does not start with "!". This depends on syntax for missing resource inJepMessageswhere 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 functionsup- supplier of the function to add, this is only called if the function is added- Since:
- Jep 4.1
-