Class ChainedNaryFunction
java.lang.Object
com.singularsys.jep.functions.PostfixMathCommand
com.singularsys.extensions.chained.ChainedNaryFunction
- All Implemented Interfaces:
ChainedFunctionI,DirtyFunction,JepComponent,PostfixMathCommandI,Serializable
public class ChainedNaryFunction
extends PostfixMathCommand
implements ChainedFunctionI, JepComponent, DirtyFunction
Converts a
NaryFunction so it can be used in a chain.
A nary function that takes n arguments is converted to an nary function with n-1 arguments.
A unary function with two arguments f(x,y) will be converted to a unary function F(x)
can be used in the middle of a chain as
[1..10] . F(5) . fold([x,y]=>x+y)
The apply(Evaluator, Node, Object) method will first
evaluate the child of the node then call the nary function f(x,y)
with the first argument from the child and the second argument from the chain.- See Also:
-
Field Summary
Fields inherited from class com.singularsys.jep.functions.PostfixMathCommand
curNumberOfParameters, description, name, NaN, numberOfParameters -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionEvaluate a chained function using an additional argument.booleancheckNumberOfParameters(int n) Checks the number of parameters of the function.Return a description of the function from the properties file.getInner()Gets a light-weight instance suitable for using in multiple threads.voidInitialize the component.voidThrows an exception because this method should never be called under normal circumstances.voidsetCurNumberOfParameters(int n) Sets the number of current number of parameters used in the next call of run().Methods inherited from class com.singularsys.jep.functions.PostfixMathCommand
asArray, asBool, asDouble, asInt, asLong, asStrictInt, asString, asType, getDescription, getDescriptionWithType, getName, getNumberOfParameters, setDescription, setName, toString, toString
-
Constructor Details
-
ChainedNaryFunction
-
-
Method Details
-
checkNumberOfParameters
public boolean checkNumberOfParameters(int n) Description copied from class:PostfixMathCommandChecks the number of parameters of the function. Functions which set numberOfParameter=-1 should overload this method- Specified by:
checkNumberOfParametersin interfacePostfixMathCommandI- Overrides:
checkNumberOfParametersin classPostfixMathCommand- Parameters:
n- number of parameters function will be called with.- Returns:
- false if an illegal number of parameters is supplied, true otherwise.
-
setCurNumberOfParameters
public void setCurNumberOfParameters(int n) Description copied from class:PostfixMathCommandSets the number of current number of parameters used in the next call of run(). This method is only called when the reqNumberOfParameters is -1.- Specified by:
setCurNumberOfParametersin interfacePostfixMathCommandI- Overrides:
setCurNumberOfParametersin classPostfixMathCommand- Parameters:
n- number of parameter for next call of function
-
run
Description copied from class:PostfixMathCommandThrows an exception because this method should never be called under normal circumstances. Each function should use its ownrun()method for evaluating the function. This includes popping off the parameters from the stack, and pushing the result back on the stack.- Specified by:
runin interfacePostfixMathCommandI- Overrides:
runin classPostfixMathCommand- Parameters:
s- arguments for function- Throws:
EvaluationException- if function cannot be evaluated
-
apply
Description copied from interface:ChainedFunctionIEvaluate a chained function using an additional argument.- Specified by:
applyin interfaceChainedFunctionI- Parameters:
ev- the evaluatornode- top node of functionlhs- additional argument from previous element in the chain- Returns:
- Throws:
EvaluationException
-
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
-
getLightWeightInstance
Description copied from interface:JepComponentGets a light-weight instance suitable for using in multiple threads.- Specified by:
getLightWeightInstancein interfaceJepComponent- Returns:
- either a new instance, null or 'this'.
-
getInner
-
getDescription
Description copied from class:PostfixMathCommandReturn a description of the function from the properties file. The property name is the class name followed by ".description". The property is found using theJepMessagesclass, which can be configured to add additional properties files. IfPostfixMathCommand.setDescription(String)has been called, return the description set by that method instead.- Specified by:
getDescriptionin interfacePostfixMathCommandI- Overrides:
getDescriptionin classPostfixMathCommand- Returns:
- the description of the function
-