com.endeca.navigation.analytics
Class ExprBinary

java.lang.Object
  extended by com.endeca.navigation.analytics.ExprBinary
All Implemented Interfaces:
Expr, QueryNode

public class ExprBinary
extends Object
implements Expr

An ExprBinary is a type of Expr that represents a binary scalar expression. These expressions provide a full range of mathematical functions, such as addition and subtraction operators.

For example, this code subtracts one from an integer property named "Year":

LookupList lookup = new LookupList();
lookup.add(new ExprBinary(ExprBinary.MINUS, new ExprKey("Year"), new ExprConstant("1")));
In the example, the ExprBinary object is set in a LookupList object.


Nested Class Summary
static class ExprBinary.ExprBinaryOp
          Enumeration of Endeca mathematical operators.
 
Field Summary
static ExprBinary.ExprBinaryOp DIVIDE
          Division operator.
static ExprBinary.ExprBinaryOp LOG
          Logarithm operator.
static ExprBinary.ExprBinaryOp MINUS
          Subtraction operator.
static ExprBinary.ExprBinaryOp MOD
          Modulo (remainder) operator.
static ExprBinary.ExprBinaryOp MULTIPLY
          Multiplication operator.
static ExprBinary.ExprBinaryOp PLUS
          Addition operator.
static ExprBinary.ExprBinaryOp POWER
          Exponentiation operator.
static ExprBinary.ExprBinaryOp ROUND
          Round operator.
static ExprBinary.ExprBinaryOp TRUNC
          Truncation operator.
 
Constructor Summary
ExprBinary(ExprBinary.ExprBinaryOp function, Expr lhs, Expr rhs)
          Creates a new ExprBinary expression node.
 
Method Summary
 ExprBinary.ExprBinaryOp getFunction()
          Gets the mathematical function for this ExprBinary.
 Expr getLhs()
          Gets the left-hand side of this ExprBinary expression node..
 Expr getRhs()
          Gets the right-hand side of this ExprBinary expression node..
 void setFunction(ExprBinary.ExprBinaryOp function)
          Sets the mathematical function for this ExprBinary.
 void setLhs(Expr expr)
          Sets the left-hand side of this binary expression.
 void setRhs(Expr expr)
          Sets the right-hand side of this binary expression.
 String toString()
          Returns the string form of this ExprBinary.
 String toWire()
          Returns the wire form of this ExprBinary.
 void validateSyntax()
          Validates the syntax of this ExprBinary.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PLUS

public static final ExprBinary.ExprBinaryOp PLUS
Addition operator. Adds the right-hand and left-hand sides of the expression.


MINUS

public static final ExprBinary.ExprBinaryOp MINUS
Subtraction operator. Subtracts the right-hand side of the expression from the left-hand side.


MULTIPLY

public static final ExprBinary.ExprBinaryOp MULTIPLY
Multiplication operator. Multiplies the left-hand side of the expression by the value in the right-hand side.


DIVIDE

public static final ExprBinary.ExprBinaryOp DIVIDE
Division operator. Divides the left-hand side of the expression by the value in the right-hand side.


LOG

public static final ExprBinary.ExprBinaryOp LOG
Logarithm operator. Returns the logarithm of the right-hand side, where the value in the left-hand side is the base.


MOD

public static final ExprBinary.ExprBinaryOp MOD
Modulo (remainder) operator. Returns the remainder of the division of the left-hand side by the value in the right-hand side.


POWER

public static final ExprBinary.ExprBinaryOp POWER
Exponentiation operator. Returns the value of the left-hand side raised to the power of the value in the right-hand side.


ROUND

public static final ExprBinary.ExprBinaryOp ROUND
Round operator. Rounds the number in the left-hand side to the number of decimal places specified by the integer in the right-hand side.


TRUNC

public static final ExprBinary.ExprBinaryOp TRUNC
Truncation operator. Truncates the number in the left-hand side to the number of decimal places specified by the integer in the right-hand side.

Constructor Detail

ExprBinary

public ExprBinary(ExprBinary.ExprBinaryOp function,
                  Expr lhs,
                  Expr rhs)
Creates a new ExprBinary expression node. The ExprBinary will compute the specified function on the specified lhs and rhs parameters.

Parameters:
function - a mathematical function (of type ExprBinary.ExprBinaryOp) that specifies the type of operation to be made. See the setFunction method for a list of the function names.
lhs - an object of type Expr that will be the left-hand side of this binary expression.
rhs - an object of type Expr that will be the right-hand side of this binary expression.
Method Detail

setLhs

public void setLhs(Expr expr)
Sets the left-hand side of this binary expression. expr must be of type Expr, such as an ExprKey object.

Parameters:
expr - an object of type Expr that will be the left-hand side of this binary expression.

getLhs

public Expr getLhs()
Gets the left-hand side of this ExprBinary expression node..

Returns:
An expression object of type Expr that is the left-hand side of this ExprBinary.

setRhs

public void setRhs(Expr expr)
Sets the right-hand side of this binary expression. expr must be of type Expr, such as an ExprConstant object.

Parameters:
expr - an object of type Expr that will be the right-hand side of this binary expression.

getRhs

public Expr getRhs()
Gets the right-hand side of this ExprBinary expression node..

Returns:
An expression object of type Expr that is the right-hand side of this ExprBinary.

setFunction

public void setFunction(ExprBinary.ExprBinaryOp function)
Sets the mathematical function for this ExprBinary. These functions specify the type of mathematical operation to be performed using the left-hand and right-hand sides of the expression.

Parameters:
function - a mathematical function (of type ExprBinary.ExprBinaryOp) that specifies the type of operation to be made. The functions are: ExprBinary.DIVIDE, ExprBinary.LOG, ExprBinary.MINUS, ExprBinary.MOD, ExprBinary.MULTIPLY, ExprBinary.PLUS, ExprBinary.POWER, ExprBinary.ROUND, and ExprBinary.TRUNC.

getFunction

public ExprBinary.ExprBinaryOp getFunction()
Gets the mathematical function for this ExprBinary.

Returns:
The mathematical function (of type ExprBinary.ExprBinaryOp) for this ExprBinary. See the setFunction method for a list of the function names.

toString

public String toString()
Returns the string form of this ExprBinary. The format for the DIVIDE, MINUS, MULTIPLY, and PLUS operators is:
"lhs-expression sign rhs-expression"
where sign is / (for DIVIDE), - (for MINUS), * (for MULTIPY), or + (for PLUS).

The format for the other operators is:

"op(lhs-expression, rhs-expression)"
where op is LOG, MOD, POWER, BROUND, or BTRUNC.

Specified by:
toString in interface QueryNode
Overrides:
toString in class Object
Returns:
A string representation of this ExprBinary in the specified format.

toWire

public String toWire()
Returns the wire form of this ExprBinary. This method is not intended for public use because the wire format is subject to change.

Specified by:
toWire in interface QueryNode
Returns:
A wire format representation of this ExprBinary.

validateSyntax

public void validateSyntax()
                    throws SyntaxException
Validates the syntax of this ExprBinary. An ExprBinary is valid if both the right-hand side and left-hand side subexpressions are non-null and valid, and the function is not null.

Specified by:
validateSyntax in interface QueryNode
Throws:
SyntaxException - if the syntax requirements are not satisfied.


© 2010 Endeca Technologies, Inc.
Endeca Confidential