Class ArgumentExpander


  • public abstract class ArgumentExpander
    extends java.lang.Object
    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
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ArgumentExpander

        public ArgumentExpander()
    • Method Detail

      • doStack

        public void doStack​(java.util.Stack<java.lang.Object> stack,
                            int neles)
                     throws EvaluationException
        Pop neles elements off the stack and then call doArg on each.
        Parameters:
        stack - input arguments to function
        neles - number of elements to pop
        Throws:
        EvaluationException - on error
      • doArg

        public void doArg​(java.lang.Object arg)
                   throws EvaluationException
        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

        protected abstract void doSingleArg​(java.lang.Object arg)
                                     throws EvaluationException
        Process an individual element after Lists/Arrays have been expanded.
        Parameters:
        arg - one data item
        Throws:
        EvaluationException - on error