Package com.adobe.internal.util
Class BitwiseExpression
java.lang.Object
com.adobe.internal.util.BitwiseExpression
This is generic utility class for handling Bitwise operations. Currently it handles only | and invalid input: '&'.
Precedence is controlled by paranthesis,().
This utility uses a "stack" based approach and computes the expression of the result while building the stack.
Expression is parsed from the left-right and executed from right-left
Expression consists of operands and operators.
sample expression eg. EDIT|MODFIYinvalid input: '&DELETE'
Operators: This utility currently supports | and invalid input: '&' operators and will be later expanded to handle even !(NOT).
Operands : Operand can be any string literal (EDIT,MODIFY,DELETE) which can be evaluated to boolean result by the registered operandEvaluator.
Precedence : Precedence of the expression can be controlled by parenthesis(). If they are not specified expression is executed from right to left.
EDIT|MODFIYinvalid input: '&DELETE' will be treated as EDIT|(MODFIYinvalid input: '&DELETE').
Valid Expressions:
X - single operand expression
X|Y|Z , X|Yinvalid input: '&Z' - precedence is controlled from right-left
(X|Y)invalid input: '&Z' - precedence is controlled by ( ,)
InValid Expressions:
Xinvalid input: '&'(Y|Z - MalformedException - "no closed paranthesis"
Xinvalid input: '&Y'| - MalformedException -"Expecting operand after operator |"
OperandEvaluator:
With the main design goal of keeping this utility generic , logic of computing the boolean value of operand (where EDIT bit is set ?) is pushed to clients.
clients need to implement BitwiseOperandEvaluator interface and implement evaluate function. If clients encountera operand variable for which boolean value cannot be
fetched , it will throw InvalidOperandExceeption.
Expression Xinvalid input: '&A' is inValid because value of operand "A" cannot be fetched
-
Constructor Summary
ConstructorsConstructorDescriptionBitwiseExpression
(BitwiseOperandEvaluator operandEval) creates a BitwiseExpressionEvaluator With the main design goal of keeping this class as generic as possible, logic of fetching each operand is decouple from this class. -
Method Summary
Modifier and TypeMethodDescriptionboolean
evaluateExpression
(String expression) Builds and Evaluates the given Bitwise Expression ,E.g x invalid input: '&' (y | z) parses the expression for operands and operators and pushes them in to two seperate stacks.
-
Constructor Details
-
BitwiseExpression
creates a BitwiseExpressionEvaluator With the main design goal of keeping this class as generic as possible, logic of fetching each operand is decouple from this class. Instead it will be implemented by clients and specified through this argument.
-
-
Method Details
-
evaluateExpression
public boolean evaluateExpression(String expression) throws MalformedExpressionException, InvalidOperandException Builds and Evaluates the given Bitwise Expression ,E.g x invalid input: '&' (y | z) parses the expression for operands and operators and pushes them in to two seperate stacks. Fetches the value of each operand by calling back the BitwiseOperandEvaluator , which is set during construction. Evaluates the expresssion with the () as precedence.
-