org.lsmp.djep.xjep
Class TreeUtils

java.lang.Object
  extended by org.lsmp.djep.xjep.TreeUtils

public class TreeUtils
extends java.lang.Object

A set of Utility functions for working with JEP expression trees. Main methods are

Author:
rich

Field Summary
protected static Complex CI
          Complex i
protected static Complex CMINUSI
          Complex Minus i
protected static Complex CMINUSONE
          Complex Minus One
protected static Complex CONE
          Complex One
protected static Complex CZERO
          Complex Zero
protected static java.lang.Double MINUSONE
          Real Minus One
protected static java.lang.Double NAN
          Real NaN
protected static java.lang.Double NegInf
          Real NaN
protected static java.lang.Double ONE
          Real One
protected static java.lang.Double PosInf
          Real positive infinity
protected static java.lang.Double ZERO
          Real zero.
 
Constructor Summary
TreeUtils()
          Default constructor.
 
Method Summary
 Complex complexValue(Node node)
          Returns the Complex value represented by node
static Node copyChildrenIfNeeded(Node node, Node[] children)
          Sets the children of a node if they have changed for it current children.
 double doubleValue(Node node)
          Returns the double value represented by node
static Node[] getChildrenAsArray(Node node)
          returns the children of a node as an array of nodes.
 java.lang.Object getCI()
           
 java.lang.Object getCMINUSI()
           
 java.lang.Object getCMINUSONE()
           
 java.lang.Object getCONE()
           
 java.lang.Object getCZERO()
           
 java.lang.Object getMINUSONE()
           
 java.lang.String getName(Node node)
          Returns the value represented by node
 java.lang.Object getNAN()
           
 java.lang.Object getNegativeInfinity()
           
 java.lang.Object getNumber(double val)
           
 java.lang.Object getONE()
           
 Operator getOperator(Node node)
          returns the operator for a node or null if it is not an operator node.
 java.lang.Object getPositiveInfinity()
           
 java.lang.Object getValue(Node node)
          Returns the value represented by node
 java.lang.Object getZERO()
           
 int intValue(Node node)
          Returns the int value represented by node
 boolean isBinaryOperator(Node node)
           
 boolean isComplex(Node node)
          returns true if node is an ASTConstant of type Complex
 boolean isConstant(Node node)
          returns true if node is a ASTConstant
 boolean isFunction(Node node)
          returns true if node is an ASTFunNode
 boolean isInfinity(Node node)
          returns true if node is a ASTConstant with a Infinite component TODO do proper treatment of signed infinity
 boolean isInteger(Node node)
          returns true if node is a ASTConstant with Double value representing an integer.
 boolean isMinusOne(Node node)
          returns true if node is a ASTConstant with value Double(-1) or Complex(-1,0)
 boolean isNaN(Node node)
          returns true if node is a ASTConstant with a NaN component
 boolean isNegative(Node node)
          returns true if node is an ASTConstant with a negative Double value
 boolean isOne(Node node)
          returns true if node is a ASTConstant with value Double(1) or Complex(1,0)
 boolean isOperator(Node node)
          returns true if node is an ASTOpNode
 boolean isPositive(Node node)
          returns true if node is an ASTConstant with a positive Double value
 boolean isReal(Node node)
          returns true if node is a ASTConstant with Double value
 boolean isUnaryOperator(Node node)
           
 boolean isVariable(Node node)
          returns true if node is an ASTVarNode
 boolean isZero(Node node)
          returns true if node is a ASTConstant with value Double(0) or Complex(0,0)
 boolean isZero(Node node, double tol)
          returns true if node is a ASTConstant with value Double(0) or Complex(0,0)
 long longValue(Node node)
          Returns the long value represented by node
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ZERO

protected static java.lang.Double ZERO
Real zero. Note that this is a Double, if a different number format is needed then this class should be sub-classed.


ONE

protected static java.lang.Double ONE
Real One


MINUSONE

protected static java.lang.Double MINUSONE
Real Minus One


CZERO

protected static Complex CZERO
Complex Zero


CONE

protected static Complex CONE
Complex One


CI

protected static Complex CI
Complex i


CMINUSONE

protected static Complex CMINUSONE
Complex Minus One


CMINUSI

protected static Complex CMINUSI
Complex Minus i


NAN

protected static java.lang.Double NAN
Real NaN


PosInf

protected static java.lang.Double PosInf
Real positive infinity


NegInf

protected static java.lang.Double NegInf
Real NaN

Constructor Detail

TreeUtils

public TreeUtils()
Default constructor. TODO Should use the NumberFactory to create numbers!

Method Detail

getName

public java.lang.String getName(Node node)
                         throws java.lang.IllegalArgumentException
Returns the value represented by node

Throws:
java.lang.IllegalArgumentException - if given something which is not an ASTConstant

getValue

public java.lang.Object getValue(Node node)
                          throws java.lang.IllegalArgumentException
Returns the value represented by node

Throws:
java.lang.IllegalArgumentException - if given something which is not an ASTConstant

doubleValue

public double doubleValue(Node node)
                   throws java.lang.IllegalArgumentException
Returns the double value represented by node

Throws:
java.lang.IllegalArgumentException - if given something which is not an ASTConstant with a Double value

longValue

public long longValue(Node node)
               throws java.lang.IllegalArgumentException
Returns the long value represented by node

Throws:
java.lang.IllegalArgumentException - if given something which is not an ASTConstant with a Double value

intValue

public int intValue(Node node)
             throws java.lang.IllegalArgumentException
Returns the int value represented by node

Throws:
java.lang.IllegalArgumentException - if given something which is not an ASTConstant with a Double value

complexValue

public Complex complexValue(Node node)
                     throws java.lang.IllegalArgumentException
Returns the Complex value represented by node

Throws:
java.lang.IllegalArgumentException - if given something which is not an ASTConstant with a Complex value

isConstant

public boolean isConstant(Node node)
returns true if node is a ASTConstant


isReal

public boolean isReal(Node node)
returns true if node is a ASTConstant with Double value


isInteger

public boolean isInteger(Node node)
returns true if node is a ASTConstant with Double value representing an integer.


isZero

public boolean isZero(Node node)
returns true if node is a ASTConstant with value Double(0) or Complex(0,0)


isZero

public boolean isZero(Node node,
                      double tol)
returns true if node is a ASTConstant with value Double(0) or Complex(0,0)

Parameters:
tol - tolerance for testing for zero

isOne

public boolean isOne(Node node)
returns true if node is a ASTConstant with value Double(1) or Complex(1,0)


isMinusOne

public boolean isMinusOne(Node node)
returns true if node is a ASTConstant with value Double(-1) or Complex(-1,0)


isInfinity

public boolean isInfinity(Node node)
returns true if node is a ASTConstant with a Infinite component TODO do proper treatment of signed infinity


isNaN

public boolean isNaN(Node node)
returns true if node is a ASTConstant with a NaN component


isNegative

public boolean isNegative(Node node)
returns true if node is an ASTConstant with a negative Double value


isPositive

public boolean isPositive(Node node)
returns true if node is an ASTConstant with a positive Double value


isComplex

public boolean isComplex(Node node)
returns true if node is an ASTConstant of type Complex


isVariable

public boolean isVariable(Node node)
returns true if node is an ASTVarNode


isOperator

public boolean isOperator(Node node)
returns true if node is an ASTOpNode


isBinaryOperator

public boolean isBinaryOperator(Node node)

isUnaryOperator

public boolean isUnaryOperator(Node node)

getOperator

public Operator getOperator(Node node)
returns the operator for a node or null if it is not an operator node.


isFunction

public boolean isFunction(Node node)
returns true if node is an ASTFunNode


copyChildrenIfNeeded

public static Node copyChildrenIfNeeded(Node node,
                                        Node[] children)
                                 throws ParseException
Sets the children of a node if they have changed for it current children.

Throws:
ParseException

getChildrenAsArray

public static Node[] getChildrenAsArray(Node node)
returns the children of a node as an array of nodes.


getCI

public java.lang.Object getCI()

getCMINUSI

public java.lang.Object getCMINUSI()

getCMINUSONE

public java.lang.Object getCMINUSONE()

getCONE

public java.lang.Object getCONE()

getCZERO

public java.lang.Object getCZERO()

getMINUSONE

public java.lang.Object getMINUSONE()

getONE

public java.lang.Object getONE()

getZERO

public java.lang.Object getZERO()

getNAN

public java.lang.Object getNAN()

getPositiveInfinity

public java.lang.Object getPositiveInfinity()

getNegativeInfinity

public java.lang.Object getNegativeInfinity()

getNumber

public java.lang.Object getNumber(double val)


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