Class ArgumentExpander
java.lang.Object
com.singularsys.extensions.statistical.ArgumentExpander
Base class for methods which expand Lists, arrays and other collections in their argument list.
Subclasses can be used by PostfixMathCommands to expand their arguments.
The following pattern can be used which allows thread safe use.
public class Sum extends PostfixMathCommand {
class Processor extends ArgumentExpander {
double total; // stores intermediate results
@Override
protected void doSingleArg(Object arg) throws EvaluationException {
if(total==null)
total= ((Double)arg).doubleValue();
else {
total += ((Double)arg).doubleValue();
}
}
}
public void run(Stack<Object> stack) throws EvaluationException {
Processor p = new Processor();
p.doStack(stack, this.curNumberOfParameters);
stack.push(p.total);
}
}
- Author:
- Richard Morris
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidProcess an argument, arrays and Iterable objects are expanded.protected abstract voiddoSingleArg(Object arg) Process an individual element after Lists/Arrays have been expanded.voidPop neles elements off the stack and then call doArg on each.
-
Constructor Details
-
ArgumentExpander
public ArgumentExpander()
-
-
Method Details
-
doStack
Pop neles elements off the stack and then call doArg on each.- Parameters:
stack- input arguments to functionneles- number of elements to pop- Throws:
EvaluationException- on error
-
doArg
Process an argument, arrays and Iterable objects are expanded. doSingleArg is called for each array element and each member of an iterable. If the argument is not an array/iterable doSingleArg is called on the argument.- Parameters:
arg- an argument to the PFMC, may be a vector or matrix- Throws:
EvaluationException- on error
-
doSingleArg
Process an individual element after Lists/Arrays have been expanded.- Parameters:
arg- one data item- Throws:
EvaluationException- on error
-