1 package com.teamkonzept.lib.math; 2 3 public class BinaryLogicalOperator extends BinaryOperator{ 4 5 final static int AND = 0; 6 final static int OR = 1; 7 8 int type; 9 10 public BinaryLogicalOperator(int type, int parenlevel, int position) 11 throws UnsupportedOperatorException{ 12 super(parenlevel, getPriority(type, position), position); 13 this.type = type; 14 } 15 16 21 public Object evaluate(Object left, Object right) 22 throws BadOperandTypeException{ 23 if ( !(left instanceof Boolean ) ) 24 throw new BadOperandTypeException(left, "Boolean"); 25 if ( !(right instanceof Boolean ) ) 26 throw new BadOperandTypeException(right, "Boolean"); 27 if ( type == AND ) 28 return new Boolean (((Boolean )left).booleanValue() 29 && ((Boolean )right).booleanValue()); 30 else 31 return new Boolean (((Boolean )left).booleanValue() 32 || ((Boolean )right).booleanValue()); 33 } 34 35 static int getPriority(int op, int position) 36 throws UnsupportedOperatorException{ 37 switch ( op ){ 38 case AND: 39 return LOGICAL_AND_PRIORITY; 40 case OR: 41 return LOGICAL_OR_PRIORITY; 42 default: 43 throw new UnsupportedOperatorException(BinaryLogicalOperator.class, 44 op, position); 45 } 46 } 47 48 } 49 | Popular Tags |