com.singularsys.jep.functions
Class Ele

java.lang.Object
  extended by com.singularsys.jep.functions.PostfixMathCommand
      extended by com.singularsys.jep.functions.NaryFunction
          extended by com.singularsys.jep.functions.Ele
All Implemented Interfaces:
LValueI, PostfixMathCommandI, java.io.Serializable

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] b=[[1,2,3],[4,5,6]]; b[2][3]; // returns 6 b[2][3]=7; // sets 3rd element of 2nd row to 7 (only works with the configurable parser)

Author:
Richard Morris
See Also:
Serialized Form

Field Summary
protected  int indexShift
           
 
Fields inherited from class com.singularsys.jep.functions.PostfixMathCommand
curNumberOfParameters, name, NaN, numberOfParameters
 
Constructor Summary
Ele()
          Element access with mathematical convention, first element has index 1
Ele(boolean javaIndex)
          Element access, either java convention (first element has index 0) or mathematical convention (first element has index 1) can be specified.
 
Method Summary
 boolean checkNumberOfParameters(int n)
          Checks the number of parameters of the function.
 java.lang.Object ele(java.lang.Object[] args)
          Find the element of an array.
 java.lang.Object ele(java.lang.Object vec, java.lang.Object indexObject)
          Find the element of a vector
 java.lang.Object ele(java.lang.Object mat, java.lang.Object[] args)
          Find element of a multi-dimensional array
 java.lang.Object ele(java.lang.Object mat, java.lang.Object row, java.lang.Object col)
          Find the element of a matrix
 java.lang.Object eval(java.lang.Object[] args)
          Evaluate the function
 void set(Evaluator pv, Node node, java.lang.Object value)
          Performs appropriate action to set an LValue.
 
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, checkStack, getName, getNumberOfParameters, setCurNumberOfParameters, setName, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

indexShift

protected int indexShift
Constructor Detail

Ele

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


Ele

public Ele(boolean javaIndex)
Element access, either java convention (first element has index 0) or mathematical convention (first element has index 1) can be specified.

Parameters:
javaIndex - whether to use the java convention, if true index start at 0.
Method Detail

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,
                java.lang.Object value)
         throws EvaluationException
Description copied from interface: LValueI
Performs appropriate action to set an LValue.

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
value - the value obtained by evaluating the right hand side.
Throws:
EvaluationException

eval

public java.lang.Object eval(java.lang.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

ele

public java.lang.Object ele(java.lang.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

ele

public java.lang.Object ele(java.lang.Object vec,
                            java.lang.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
Since:
3.4.0

ele

public java.lang.Object ele(java.lang.Object mat,
                            java.lang.Object row,
                            java.lang.Object col)
                     throws EvaluationException
Find the element of a matrix

Parameters:
mat - the matrix represented a a Vector<Vector<Object>>
row - the index
col - the index
Returns:
element of matrix referred to by row/col
Throws:
EvaluationException
Since:
3.4.0

ele

public java.lang.Object ele(java.lang.Object mat,
                            java.lang.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
Since:
3.4.0


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