Package com.singularsys.jep.functions

# Class Ele

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

All Implemented Interfaces:
  `LValueI`, `PostfixMathCommandI`, `Serializable`

Direct Known Subclasses:
  `ExpandingEle`, `ThreadSafeEle`

public class Ele extends NaryFunction implements LValueI
Function which allows array access using the a[3] notation on left and right-hand side. The first element is indexed with 1.

    a=[4,3,2,1];
    a[2];   // Returns 2
    a[2]=5; // Sets the 2nd element of a to 5. So a is now [4,5,2,1]
    // Two dimensional matrices only work with the configurable parser
    b=[[1,2,3],[4,5,6]];
    b[2][3]; // returns 6
    b[2][3]=7; // sets 3rd element of 2nd row to 7

Since:
  Jep 4.1 can work with `List<?>`.
Author:
  Richard Morris
See Also:
  - Serialized Form

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected final int`
  `indexShift`

  ### Fields inherited from class com.singularsys.jep.functions.PostfixMathCommand

  `curNumberOfParameters, description, name, NaN, numberOfParameters`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Ele()`
  Element access with mathematical convention, first element has an index of 1.
  `Ele(boolean javaIndex)`
  Element access, either java convention (first element has an index of 0) or mathematical convention (first element has an index of 1) can be specified.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `checkNumberOfParameters(int n)`
  Checks the number of parameters of the function.
  `Object`
  `ele(Object[] args)`
  Find the element of an array.
  `Object`
  `ele(Object vec, Object indexObject)`
  Find the element of a vector
  `Object`
  `ele(Object mat, Object[] args)`
  Find element of a multi-dimensional array
  `Object`
  `ele(Object mat, Object row, Object col)`
  Find the element of a matrix
  `Object`
  `eval(Object[] args)`
  Evaluate the function
  `protected int`
  `findIndex(Object indexObject)`
  Find the index from the indexObject.
  `protected Variable`
  `getVariable(Evaluator pv, ASTVarNode node)`
  Find the variable associated with a node.
  `void`
  `set(Evaluator pv, Node node, Object value)`
  Sets an element of an vector valued variable.

  ### Methods inherited from class com.singularsys.jep.functions.NaryFunction

  `run`

  ### Methods inherited from class com.singularsys.jep.functions.PostfixMathCommand

  `asArray, asBool, asDouble, asInt, asLong, asStrictInt, asString, asType, getDescription, getDescription, getDescriptionWithType, getName, getNumberOfParameters, setCurNumberOfParameters, setDescription, setName, toString, toString`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Field Details

  - ### indexShift

    protected final int indexShift

- ## Constructor Details

  - ### Ele

    public Ele()
    Element access with mathematical convention, first element has an index of 1.

  - ### Ele

    public Ele(boolean javaIndex)
    Element access, either java convention (first element has an index of 0) or mathematical convention (first element has an index of 1) can be specified.
    Parameters:
      `javaIndex` - whether to use the java convention, if true index start at 0.

- ## Method Details

  - ### checkNumberOfParameters

    public boolean checkNumberOfParameters(int n)
    Description copied from class: `PostfixMathCommand`
    Checks the number of parameters of the function. Functions which set numberOfParameter=-1 should overload this method
    Specified by:
      `checkNumberOfParameters` in interface `PostfixMathCommandI`
    Overrides:
      `checkNumberOfParameters` in class `PostfixMathCommand`
    Parameters:
      `n` - number of parameters function will be called with.
    Returns:
      false if an illegal number of parameters is supplied, true otherwise.

  - ### set

    public void set(Evaluator pv, Node node, Object value) throws EvaluationException
    Sets an element of an vector valued variable. For the expression `u[2] = 5` the left hand node is ASTOpNode for the Ele pfmc the method will be called like `set(pv,lhs,5);` The value of the variable will be replaced by a new `Vector<Object>` with the appropriate element replaced.
    Specified by:
      `set` in interface `LValueI`
    Parameters:
      `pv` - a pointer to the evaluator. The pv.eval() method can be used to evaluate the children of the node.
      `node` - The top node for the LValue, root should be the ASTOpNode for the Ele pfmc.
      `value` - the value obtained by evaluating the right-hand side.
    Throws:
      `EvaluationException` - if the calculation cannot be performed

  - ### eval

    public Object eval(Object[] args) throws EvaluationException
    Description copied from class: `NaryFunction`
    Evaluate the function
    Specified by:
      `eval` in class `NaryFunction`
    Parameters:
      `args` - arguments to the function
    Returns:
      value returned by the function
    Throws:
      `EvaluationException` - if the calculation cannot be performed

  - ### ele

    public Object ele(Object[] args) throws EvaluationException
    Find the element of an array. Calls `ele(Object, Object)`, `ele(Object, Object, Object)` or `ele(Object, Object[])` depending on number of arguments.
    Parameters:
      `args` - First element is the vector or matrix, subsequent elements are indices
    Returns:
      the element referred to by the indices
    Throws:
      `EvaluationException` - if the calculation cannot be performed

  - ### ele

    public Object ele(Object vec, Object indexObject) throws EvaluationException
    Find the element of a vector
    Parameters:
      `vec` - the vector
      `indexObject` - the index either as a vector with a single value or as a single value.
    Returns:
      element of vec referred to by the index.
    Throws:
      `EvaluationException` - if the calculation cannot be performed
    Since:
      3.4.0

  - ### findIndex

    protected int findIndex(Object indexObject) throws EvaluationException, IllegalParameterException
    Find the index from the indexObject. If indexObject is a vector with a single value, that value is used as the index. Otherwise indexObject is converted to an integer and used as the index.
    Parameters:
      `indexObject` - the index either as a vector with a single value or as a single value.
    Returns:
      the index
    Throws:
      `EvaluationException` - if the calculation cannot be performed
      `IllegalParameterException` - if the parameter is not valid

  - ### ele

    public Object ele(Object mat, Object row, Object col) throws EvaluationException
    Find the element of a matrix
    Parameters:
      `mat` - the matrix represented a Vector<Vector<Object>>
      `row` - the index
      `col` - the index
    Returns:
      element of matrix referred to by row/col
    Throws:
      `EvaluationException` - if the calculation cannot be performed
    Since:
      3.4.0

  - ### ele

    public Object ele(Object mat, Object[] args) throws EvaluationException
    Find element of a multi-dimensional array
    Parameters:
      `mat` - the array
      `args` - array of indices
    Returns:
      element in mat referred to by indices
    Throws:
      `EvaluationException` - if the calculation cannot be performed
    Since:
      3.4.0

  - ### getVariable

    protected Variable getVariable(Evaluator pv, ASTVarNode node)
    Find the variable associated with a node. Overridden by subclasses which require thread-safety.
    Parameters:
      `pv` - the evaluator
      `node` - the node
    Returns:
      the variable
    Since:
      3.5