public abstract class ArgumentExpander
extends java.lang.Object
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); } }
Constructor and Description |
---|
ArgumentExpander() |
Modifier and Type | Method and Description |
---|---|
void |
doArg(java.lang.Object arg)
Process an argument, arrays and Iterable objects are expanded.
|
protected abstract void |
doSingleArg(java.lang.Object arg)
Process an individual element after Lists/Arrays have been expanded.
|
void |
doStack(java.util.Stack<java.lang.Object> stack,
int neles)
Pop neles elements off the stack and then call doArg on each.
|
public void doStack(java.util.Stack<java.lang.Object> stack, int neles) throws EvaluationException
stack
- neles
- number of elements to popEvaluationException
public void doArg(java.lang.Object arg) throws EvaluationException
arg
- EvaluationException
protected abstract void doSingleArg(java.lang.Object arg) throws EvaluationException
arg
- EvaluationException
Copyright © 2018 Singular Systems http://www.singularsys.com/jep