1 7 8 package javax.management; 9 10 11 18 class BinaryRelQueryExp extends QueryEval implements QueryExp { 19 20 21 private static final long serialVersionUID = -5690656271650491000L; 22 23 26 private int relOp; 27 28 31 private ValueExp exp1; 32 33 36 private ValueExp exp2; 37 38 39 42 public BinaryRelQueryExp() { 43 } 44 45 49 public BinaryRelQueryExp(int op, ValueExp v1, ValueExp v2) { 50 relOp = op; 51 exp1 = v1; 52 exp2 = v2; 53 } 54 55 56 59 public int getOperator() { 60 return relOp; 61 } 62 63 66 public ValueExp getLeftValue() { 67 return exp1; 68 } 69 70 73 public ValueExp getRightValue() { 74 return exp2; 75 } 76 77 89 public boolean apply(ObjectName name) throws BadStringOperationException , BadBinaryOpValueExpException , 90 BadAttributeValueExpException , InvalidApplicationException { 91 Object val1 = exp1.apply(name); 92 Object val2 = exp2.apply(name); 93 String sval1; 94 String sval2; 95 double dval1; 96 double dval2; 97 long lval1; 98 long lval2; 99 boolean bval1; 100 boolean bval2; 101 boolean numeric = val1 instanceof NumericValueExp ; 102 boolean bool = val1 instanceof BooleanValueExp ; 103 if (numeric) { 104 if (((NumericValueExp )val1).isLong()) { 105 lval1 = ((NumericValueExp )val1).longValue(); 106 lval2 = ((NumericValueExp )val2).longValue(); 107 108 switch (relOp) { 109 case Query.GT: 110 return lval1 > lval2; 111 case Query.LT: 112 return lval1 < lval2; 113 case Query.GE: 114 return lval1 >= lval2; 115 case Query.LE: 116 return lval1 <= lval2; 117 case Query.EQ: 118 return lval1 == lval2; 119 } 120 } else { 121 dval1 = ((NumericValueExp )val1).doubleValue(); 122 dval2 = ((NumericValueExp )val2).doubleValue(); 123 124 switch (relOp) { 125 case Query.GT: 126 return dval1 > dval2; 127 case Query.LT: 128 return dval1 < dval2; 129 case Query.GE: 130 return dval1 >= dval2; 131 case Query.LE: 132 return dval1 <= dval2; 133 case Query.EQ: 134 return dval1 == dval2; 135 } 136 } 137 138 } else if (bool) { 139 140 bval1 = ((BooleanValueExp )val1).getValue().booleanValue(); 141 bval2 = ((BooleanValueExp )val2).getValue().booleanValue(); 142 143 switch (relOp) { 144 case Query.GT: 145 return bval1 && !bval2; 146 case Query.LT: 147 return !bval1 && bval2; 148 case Query.GE: 149 return bval1 || !bval2; 150 case Query.LE: 151 return !bval1 || bval2; 152 case Query.EQ: 153 return bval1 == bval2; 154 } 155 156 } else { 157 sval1 = ((StringValueExp )val1).getValue(); 158 sval2 = ((StringValueExp )val2).getValue(); 159 160 switch (relOp) { 161 case Query.GT: 162 return sval1.compareTo(sval2) > 0; 163 case Query.LT: 164 return sval1.compareTo(sval2) < 0; 165 case Query.GE: 166 return sval1.compareTo(sval2) >= 0; 167 case Query.LE: 168 return sval1.compareTo(sval2) <= 0; 169 case Query.EQ: 170 return sval1.compareTo(sval2) == 0; 171 } 172 } 173 174 return false; 175 } 176 177 180 public String toString() { 181 return "(" + exp1 + ") " + relOpString() + " (" + exp2 + ")"; 182 } 183 184 private String relOpString() { 185 switch (relOp) { 186 case Query.GT: 187 return ">"; 188 case Query.LT: 189 return "<"; 190 case Query.GE: 191 return ">="; 192 case Query.LE: 193 return "<="; 194 case Query.EQ: 195 return "="; 196 } 197 198 return "="; 199 } 200 201 } 202 | Popular Tags |