Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.singularsys.jep.functions
Class PostfixMathCommand

    java.lang.Object
      com.singularsys.jep.functions.PostfixMathCommand

All Implemented Interfaces:
  PostfixMathCommandI, java.io.Serializable

Direct Known Subclasses:
  AbstractInc, Assign, Average, BinaryFunction, BitAnd, BitComp, BitOr, BitXor, Ele, ExtendedOperatorSet.Factorial, FromBase, If, LazyLogical, List, LShift, MacroFunction, MinMax, NaryBinaryFunction, NaryFunction, OpEquals, Random, Real, Round, RShift, Str, Sum, TernaryConditional, ToBase, UnaryFunction, URShift

    public abstract class PostfixMathCommand

extends java.lang.Object
implements PostfixMathCommandI, java.io.Serializable

Function classes extend this class. It is an implementation of the PostfixMathCommandI interface.

It includes a numberOfParameters member, that is checked when parsing the expression. This member should be initialized to an appropriate value for all classes extending this class. If an arbitrary number of parameters should be allowed, initialize this member to -1.

The {`asString(int, java.lang.Object)` and similar method are convenience methods for use by subclasses to ease conversion of arguments to particular types.

See Also:
  Serialized Form

Field Summary
`protected int` | `curNumberOfParameters` Number of parameters to be used for the next run() invocation.
`java.lang.String` | `name`
`static java.lang.Double` | `NaN` Double.valueOf(Double.NaN)
`protected int` | `numberOfParameters` Number of parameters a the function requires.

Constructor Summary
`PostfixMathCommand()` Creates a new PostfixMathCommand class.
`PostfixMathCommand(int nParam)` Creates a new PostfixMathCommand class.

Method Summary
`protected java.lang.Object[]` | `asArray(java.util.Stack<java.lang.Object> stack)` Pop the arguments off the stack and put them in an array
`protected boolean` | `asBool(int pos, java.lang.Object value, boolean allowNumbers)` Attempt to convert argument to a boolean
`protected double` | `asDouble(int position, java.lang.Object value)` Converts an argument to a double, with error checking, floating point values will be rounded.
`protected int` | `asInt(int position, java.lang.Object value)` Converts an argument to a int, floating point values will be rounded.
`protected long` | `asLong(int position, java.lang.Object value)` Converts an argument to a long, with error checking, floating point values will be rounded.
`protected int` | `asStrictInt(int position, java.lang.Object value)` Converts an argument to a int, floating point values must represent integers.
`protected java.lang.String` | `asString(int position, java.lang.Object value)` Converts an argument to a string, with error checking.
`boolean` | `checkNumberOfParameters(int n)` Checks the number of parameters of the function.
`protected void` | `checkStack(java.util.Stack<java.lang.Object> inStack)` Check whether the stack is not null, throw a EvaluationException if it is.
`java.lang.String` | `getName()`
`int` | `getNumberOfParameters()` Return the required number of parameters.
`void` | `setCurNumberOfParameters(int n)` Sets the number of current number of parameters used in the next call of run().
`void` | `setName(java.lang.String name)`
`protected java.lang.String` | `toString(java.lang.Object... args)` Return a string representation of the function with its arguments.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Methods inherited from interface com.singularsys.jep.PostfixMathCommandI
`run`

Field Detail

### NaN

    public static final java.lang.Double NaN

  Double.valueOf(Double.NaN)

### numberOfParameters

    protected int numberOfParameters

  Number of parameters a the function requires. Initialize this value to -1 if any number of parameters should be allowed.

### curNumberOfParameters

    protected transient int curNumberOfParameters

  Number of parameters to be used for the next run() invocation. Applies only if the required number of parameters is variable (numberOfParameters = -1).

### name

    public java.lang.String name

Constructor Detail

### PostfixMathCommand

    public PostfixMathCommand()

  Creates a new PostfixMathCommand class.

### PostfixMathCommand

    public PostfixMathCommand(int nParam)

  Creates a new PostfixMathCommand class.

  Parameters:
    `nParam` - number of parameters for the function

Method Detail

### getName

    public java.lang.String getName()

  Specified by:
    `getName` in interface `PostfixMathCommandI`

### setName

    public void setName(java.lang.String name)

  Specified by:
    `setName` in interface `PostfixMathCommandI`

### checkStack

    protected void checkStack(java.util.Stack<java.lang.Object> inStack)
                       throws EvaluationException

  Check whether the stack is not null, throw a EvaluationException if it is.

  Throws:
    `EvaluationException`

### getNumberOfParameters

    public int getNumberOfParameters()

  Return the required number of parameters.

  Specified by:
    `getNumberOfParameters` in interface `PostfixMathCommandI`

### setCurNumberOfParameters

    public void setCurNumberOfParameters(int n)

  Sets 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:
    `setCurNumberOfParameters` in interface `PostfixMathCommandI`

### checkNumberOfParameters

    public boolean checkNumberOfParameters(int n)

  Checks the number of parameters of the function. Functions which set numberOfParameter=-1 should overload this method

  Specified by:
    `checkNumberOfParameters` in interface `PostfixMathCommandI`
  Parameters:
    `n` - number of parameters function will be called with.
  Returns:
    false if an illegal number of parameters is supplied, true otherwise.

### asString

    protected java.lang.String asString(int position,
                                        java.lang.Object value)
                                 throws IllegalParameterException

  Converts an argument to a string, with error checking.

  Parameters:
    `position` - argument number (starting from 0) used in error reporting
    `value` - the argument to convert
  Returns:
    value cast as a String
  Throws:
    `IllegalParameterException` - if the argument cannot be cast to a String

### asInt

    protected int asInt(int position,
                        java.lang.Object value)
                 throws IllegalParameterException

  Converts an argument to a int, floating point values will be rounded.

  Parameters:
    `position` - argument number (starting from 0) used in error reporting
    `value` - the argument to convert
  Returns:
    value as a int
  Throws:
    `IllegalParameterException` - if the argument cannot be cast to a Number

### asStrictInt

    protected int asStrictInt(int position,
                              java.lang.Object value)
                       throws IllegalParameterException

  Converts an argument to a int, floating point values must represent integers.

  Parameters:
    `position` - argument number (starting from 0) used in error reporting
    `value` - the argument to convert
  Returns:
    value as a int
  Throws:
    `IllegalParameterException` - if the argument cannot be cast to a Number or intValue() != doubleValue()

### asLong

    protected long asLong(int position,
                          java.lang.Object value)
                   throws EvaluationException

  Converts an argument to a long, with error checking, floating point values will be rounded.

  Parameters:
    `position` - argument number (starting from 0) used in error reporting
    `value` - the argument to convert
  Returns:
    value as a long
  Throws:
    `IllegalParameterException` - if the argument cannot be cast to a Number
    `EvaluationException`

### asDouble

    protected double asDouble(int position,
                              java.lang.Object value)
                       throws EvaluationException

  Converts an argument to a double, with error checking, floating point values will be rounded.

  Parameters:
    `position` - argument number (starting from 0) used in error reporting
    `value` - the argument to convert
  Returns:
    value as a long
  Throws:
    `IllegalParameterException` - if the argument cannot be cast to a Number
    `EvaluationException`

### asBool

    protected boolean asBool(int pos,
                             java.lang.Object value,
                             boolean allowNumbers)
                      throws EvaluationException

  Attempt to convert argument to a boolean

  Parameters:
    `pos` - position in argument list
    `value` - actual value of object
    `allowNumbers` - if true non zero numbers are true and zero numbers are false
  Returns:
    value as a boolean
  Throws:
    `EvaluationException`

### asArray

    protected java.lang.Object[] asArray(java.util.Stack<java.lang.Object> stack)

  Pop the arguments off the stack and put them in an array

  Parameters:
    `stack` -
  Returns:
    an array of the arguments of the function in correct order

### toString

    protected java.lang.String toString(java.lang.Object... args)

  Return a string representation of the function with its arguments.

  Parameters:
    `args` - the arguments to the function
  Returns:
    string representation of the function with its arguments

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2008 Singular Systems http://www.singularsys.com/jep