1 43 44 package org.exolab.jms.selector; 45 46 import javax.jms.Message ; 47 48 49 61 class BetweenExpression implements Expression { 62 63 66 private final Expression _num1; 67 68 71 private final Expression _num2; 72 73 76 private final Expression _num3; 77 78 81 private static final String CONTEXT = "between expression"; 82 83 84 94 public BetweenExpression(final Expression num1, final Expression num2, 95 final Expression num3) { 96 _num1 = num1; 97 _num2 = num2; 98 _num3 = num3; 99 } 100 101 108 public final SObject evaluate(final Message msg) 109 throws TypeMismatchException { 110 SBool result = null; 111 SNumber val1 = TypeCaster.castToNumber(_num1.evaluate(msg), CONTEXT); 112 if (val1 != null) { 113 SNumber val2 = TypeCaster.castToNumber(_num2.evaluate(msg), 114 CONTEXT); 115 if (val2 != null) { 116 SNumber val3 = TypeCaster.castToNumber(_num3.evaluate(msg), 117 CONTEXT); 118 if (val3 != null) { 119 if (val1.greaterEqual(val2).value() 120 && val1.lessEqual(val3).value()) { 121 result = SBool.TRUE; 122 } else { 123 result = SBool.FALSE; 124 } 125 } 126 } 127 } 128 return result; 129 } 130 131 136 public final String toString() { 137 StringBuffer result = new StringBuffer (); 138 result.append('('); 139 result.append(_num1.toString()); 140 result.append(" between "); 141 result.append(_num2.toString()); 142 result.append(" and "); 143 result.append(_num3.toString()); 144 result.append(')'); 145 return result.toString(); 146 } 147 148 } | Popular Tags |