Class BitwiseExpression

  • public class BitwiseExpression
    extends Object
    This is generic utility class for handling Bitwise operations. Currently it handles only | and &. 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|MODFIY&DELETE Operators: This utility currently supports | and & 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|MODFIY&DELETE will be treated as EDIT|(MODFIY&DELETE). Valid Expressions: X - single operand expression X|Y|Z , X|Y&Z - precedence is controlled from right-left (X|Y)&Z - precedence is controlled by ( ,) InValid Expressions: X&(Y|Z - MalformedException - "no closed paranthesis" X&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 X&A is inValid because value of operand "A" cannot be fetched
    • Constructor Detail

      • BitwiseExpression

        public BitwiseExpression​(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. Instead it will be implemented by clients and specified through this argument.