1 package com.teamkonzept.lib.math; 2 3 4 public class UnaryLogicalOperator extends UnaryOperator{ 5 6 final static int NOT = 0; 7 8 int type; 9 10 public UnaryLogicalOperator(int type, int parenlevel, int position) 11 throws UnsupportedOperatorException{ 12 super(parenlevel, getPriority(type, position), position); 13 this.type = type; 14 } 15 16 public Object evaluate(Object target)throws BadOperandTypeException{ 17 if ( !(target instanceof Boolean ) ) 18 throw new BadOperandTypeException(target, "Boolean"); 19 return new Boolean (!((Boolean )target).booleanValue()); 20 } 21 22 static int getPriority(int op, int position) 23 throws UnsupportedOperatorException{ 24 switch ( op ){ 25 case NOT: 26 return LOGICAL_NOT_PRIORITY; 27 default: 28 throw new UnsupportedOperatorException(UnaryLogicalOperator.class, 29 op, position); 30 } 31 } 32 33 34 } 35 | Popular Tags |