Class BinaryOperatorExpression
- java.lang.Object
-
- org.vedantatree.expressionoasis.expressions.BinaryOperatorExpression
-
- All Implemented Interfaces:
Expression
- Direct Known Subclasses:
AddExpression
,AndExpression
,ArgumentExpression
,ArrayIndexExpression
,BWAndExpression
,BWOrExpression
,BWSignedLeftShiftExpression
,BWSignedRightShiftExpression
,BWUnsignedRightShiftExpression
,BWXorExpression
,ConditionTernaryExpression
,ContainsExpression
,DivideExpression
,EndsWithExpression
,EQExpression
,GTEExpression
,LTEExpression
,MaxExpression
,MinExpression
,MultiplyExpression
,OrExpression
,PropertyExpression
,RemainderExpression
,ResultTernaryExpression
,StartsWithExpression
,SubtractExpression
public abstract class BinaryOperatorExpression extends Object implements Expression
This class defines the abstract implemenation for binary operator expression.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
BinaryOperatorExpression.TypePair
This is the class for making pair of valid types for a binary operator.
-
Field Summary
Fields Modifier and Type Field Description protected Expression
leftOperandExpression
Left operand expression for this binary operator expression.protected Expression
rightOperandExpression
Right operand expression for this binary operator expression.
-
Constructor Summary
Constructors Constructor Description BinaryOperatorExpression()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
accept(ExpressionVisitor visitor)
Allows an expression visitor to visit this expression and it's sub-expressions (implements Visitor design pattern).protected static void
addTypePair(Class clazz, Type leftType, Type rightType, Type resultType)
Adds the type mapping for the given operator.protected static BinaryOperatorExpression.TypePair
createTypePair(Type leftType, Type rightType)
Creates the type pair for given types pairExpression
getLeftOperandExpression()
Gets the value of leftOperandExpression.Type
getReturnType()
Gets the return type of the expression.Expression
getRightOperandExpression()
Gets the value of rightOperandExpression.ValueObject
getValue()
Executes and returns the value of this expression.void
initialize(ExpressionContext expressionContext, Object parameters, boolean validate)
Initializes the child expressions.String
toString()
void
uninitialize(ExpressionContext expressionContext)
Uninitializes the binary expression.protected void
validate(ExpressionContext expressionContext)
Validates the expression.
-
-
-
Field Detail
-
leftOperandExpression
protected Expression leftOperandExpression
Left operand expression for this binary operator expression.
-
rightOperandExpression
protected Expression rightOperandExpression
Right operand expression for this binary operator expression.
-
-
Method Detail
-
initialize
public void initialize(ExpressionContext expressionContext, Object parameters, boolean validate) throws ExpressionEngineException
Initializes the child expressions.- Specified by:
initialize
in interfaceExpression
- Parameters:
expressionContext
- contextual information, may help in initializationparameters
- for example, sub expressions and identifiers- Throws:
ExpressionEngineException
- if there is any problem during execution- See Also:
org.vedantatree.expressionoasis.expressions.Expression#initialize(org.vedantatree.expressionoasis.ExpressionContext, java.lang.Object)
-
getReturnType
public Type getReturnType() throws ExpressionEngineException
Description copied from interface:Expression
Gets the return type of the expression.- Specified by:
getReturnType
in interfaceExpression
- Returns:
- the type of expression
- Throws:
ExpressionEngineException
- If there is any problem during execution- See Also:
Expression.getReturnType()
-
getLeftOperandExpression
public Expression getLeftOperandExpression()
Gets the value of leftOperandExpression.- Returns:
- Returns the leftOperandExpression.
-
getRightOperandExpression
public Expression getRightOperandExpression()
Gets the value of rightOperandExpression.- Returns:
- Returns the rightOperandExpression.
-
uninitialize
public void uninitialize(ExpressionContext expressionContext)
Uninitializes the binary expression.- Specified by:
uninitialize
in interfaceExpression
- Parameters:
expressionContext
- contextual information, may help in un-initialization- See Also:
Expression.uninitialize(org.vedantatree.expressionoasis.ExpressionContext)
-
createTypePair
protected static final BinaryOperatorExpression.TypePair createTypePair(Type leftType, Type rightType)
Creates the type pair for given types pair- Parameters:
leftType
-rightType
-- Returns:
-
addTypePair
protected static final void addTypePair(Class clazz, Type leftType, Type rightType, Type resultType)
Adds the type mapping for the given operator. User can add as many mapping as required for operator. Like in case of '+' operator, one possible mapping is left type = integer, right type = string, result type = string. Because if we add integer to string, it will result in a string value.- Parameters:
clazz
- class of the operator like +, - etcleftType
- type of left operandrightType
- type of right operandresultType
- type of result
-
validate
protected void validate(ExpressionContext expressionContext) throws ExpressionEngineException
Validates the expression.- Parameters:
expressionContext
-- Throws:
ExpressionEngineException
-
toString
public String toString()
- Overrides:
toString
in classObject
- See Also:
Object.toString()
-
accept
public void accept(ExpressionVisitor visitor)
Allows an expression visitor to visit this expression and it's sub-expressions (implements Visitor design pattern).- Specified by:
accept
in interfaceExpression
- Parameters:
visitor
- a visitor object that this expression must visit when accept is called.- See Also:
Expression.accept(org.vedantatree.expressionoasis.ExpressionVisitor)
-
getValue
public ValueObject getValue() throws ExpressionEngineException
Description copied from interface:Expression
Executes and returns the value of this expression. If expression is not at node level, it will further evaluate its related expression which may represents operands or operators and return the final outcome.- Specified by:
getValue
in interfaceExpression
- Returns:
- the value of expression (after expression evaluation)
- Throws:
ExpressionEngineException
- if there is any problem during execution
-
-