1 7 8 package javax.management; 9 10 11 18 class BetweenQueryExp extends QueryEval implements QueryExp { 19 20 21 private static final long serialVersionUID = -2933597532866307444L; 22 23 26 private ValueExp exp1; 27 28 31 private ValueExp exp2; 32 33 36 private ValueExp exp3; 37 38 39 42 public BetweenQueryExp() { 43 } 44 45 49 public BetweenQueryExp(ValueExp v1, ValueExp v2, ValueExp v3) { 50 exp1 = v1; 51 exp2 = v2; 52 exp3 = v3; 53 } 54 55 56 59 public ValueExp getCheckedValue() { 60 return exp1; 61 } 62 63 66 public ValueExp getLowerBound() { 67 return exp2; 68 } 69 70 73 public ValueExp getUpperBound() { 74 return exp3; 75 } 76 77 89 public boolean apply(ObjectName name) throws BadStringOperationException , BadBinaryOpValueExpException , 90 BadAttributeValueExpException , InvalidApplicationException { 91 ValueExp val1 = exp1.apply(name); 92 ValueExp val2 = exp2.apply(name); 93 ValueExp val3 = exp3.apply(name); 94 String sval1; 95 String sval2; 96 String sval3; 97 double dval1; 98 double dval2; 99 double dval3; 100 long lval1; 101 long lval2; 102 long lval3; 103 boolean numeric = val1 instanceof NumericValueExp ; 104 105 if (numeric) { 106 if (((NumericValueExp )val1).isLong()) { 107 lval1 = ((NumericValueExp )val1).longValue(); 108 lval2 = ((NumericValueExp )val2).longValue(); 109 lval3 = ((NumericValueExp )val3).longValue(); 110 return lval2 <= lval1 && lval1 <= lval3; 111 } else { 112 dval1 = ((NumericValueExp )val1).doubleValue(); 113 dval2 = ((NumericValueExp )val2).doubleValue(); 114 dval3 = ((NumericValueExp )val3).doubleValue(); 115 return dval2 <= dval1 && dval1 <= dval3; 116 } 117 118 } else { 119 sval1 = ((StringValueExp )val1).toString(); 120 sval2 = ((StringValueExp )val2).toString(); 121 sval3 = ((StringValueExp )val3).toString(); 122 return sval2.compareTo(sval1) <= 0 && sval1.compareTo(sval3) <= 0; 123 } 124 } 125 126 129 public String toString() { 130 return "(" + exp1 + ") between (" + exp2 + ") and (" + exp3 + ")"; 131 } 132 133 } 134 135 | Popular Tags |