1 28 29 package com.caucho.jmx.query; 30 31 import javax.management.*; 32 33 36 abstract public class AbstractExp extends QueryEval implements QueryExp { 37 40 protected boolean eq(ValueExp v1, ValueExp v2) 41 throws BadBinaryOpValueExpException 42 { 43 if (v1 instanceof StringValueExp && 44 v2 instanceof StringValueExp) 45 return toString(v1).equals(toString(v2)); 46 else if (v1 instanceof BooleanValueExp && 47 v2 instanceof BooleanValueExp) 48 return toBoolean(v1) == toBoolean(v2); 49 else if (v1 instanceof NumericValueExp && 50 v2 instanceof NumericValueExp) 51 return toDouble(v1) == toDouble(v2); 52 else 53 throw new BadBinaryOpValueExpException(v1); 54 } 55 58 protected boolean lt(ValueExp v1, ValueExp v2) 59 throws BadBinaryOpValueExpException 60 { 61 if (v1 instanceof StringValueExp && 62 v2 instanceof StringValueExp) 63 return toString(v1).compareTo(toString(v2)) < 0; 64 else if (v1 instanceof BooleanValueExp && 65 v2 instanceof BooleanValueExp) { 66 boolean b1 = toBoolean(v1); 67 boolean b2 = toBoolean(v2); 68 69 return ! b1 && b2; 70 } 71 else if (v1 instanceof NumericValueExp && 72 v2 instanceof NumericValueExp) 73 return toDouble(v1) < toDouble(v2); 74 else 75 throw new BadBinaryOpValueExpException(v1); 76 } 77 78 81 public static String toString(ValueExp exp) 82 throws BadBinaryOpValueExpException 83 { 84 if (exp instanceof StringValueExp) 85 return ((StringValueExp) exp).getValue(); 86 else if (exp instanceof AbstractValueExp) 87 return ((AbstractValueExp) exp).getString(); 88 else 89 throw new BadBinaryOpValueExpException(exp); 90 } 91 92 95 public static long toLong(ValueExp exp) 96 throws BadBinaryOpValueExpException 97 { 98 if (exp instanceof StringValueExp) 99 return Long.parseLong(((StringValueExp) exp).getValue()); 100 else if (exp instanceof AbstractValueExp) 101 return ((AbstractValueExp) exp).getLong(); 102 else 103 throw new BadBinaryOpValueExpException(exp); 104 } 105 108 public static boolean toBoolean(ValueExp exp) 109 throws BadBinaryOpValueExpException 110 { 111 if (exp instanceof StringValueExp) { 112 String value = ((StringValueExp) exp).getValue(); 113 114 return value != null && ! value.equals(""); 115 } 116 else if (exp instanceof AbstractValueExp) 117 return ((AbstractValueExp) exp).getBoolean(); 118 else 119 throw new BadBinaryOpValueExpException(exp); 120 } 121 122 125 public static double toDouble(ValueExp exp) 126 throws BadBinaryOpValueExpException 127 { 128 if (exp instanceof StringValueExp) 129 return Double.parseDouble(((StringValueExp) exp).getValue()); 130 else if (exp instanceof AbstractValueExp) 131 return ((AbstractValueExp) exp).getDouble(); 132 else 133 throw new BadBinaryOpValueExpException(exp); 134 } 135 } 136 | Popular Tags |