1 28 29 package com.caucho.jms.selector; 30 31 import javax.jms.InvalidSelectorException ; 32 import javax.jms.JMSException ; 33 import javax.jms.Message ; 34 35 38 public class BetweenSelector extends Selector { 39 private Selector _left; 40 private Selector _low; 41 private Selector _high; 42 43 BetweenSelector(Selector left, Selector low, Selector high) 44 throws JMSException 45 { 46 _left = left; 47 _low = low; 48 _high = high; 49 50 if (! _left.isUnknown() && ! _left.isNumber()) 51 throw new InvalidSelectorException (L.l("'{0}' must have a numeric value for comparison.", 52 this)); 53 if (! _low.isUnknown() && ! _low.isNumber()) 54 throw new InvalidSelectorException (L.l("'{0}' must have a numeric value for comparison.", 55 this)); 56 if (! _high.isUnknown() && ! _high.isNumber()) 57 throw new InvalidSelectorException (L.l("'{0}' must have a numeric value for comparison.", 58 this)); 59 } 60 61 65 Object evaluate(Message message) 66 throws JMSException 67 { 68 Object lobj = _left.evaluate(message); 69 70 if (! (lobj instanceof Number )) 71 return NULL; 72 73 Object lowObj = _low.evaluate(message); 74 Object highObj = _high.evaluate(message); 75 76 if (! (lowObj instanceof Number ) || ! (highObj instanceof Number )) 77 return NULL; 78 79 if (isInteger(lobj) && isInteger(lowObj) && isInteger(highObj)) { 80 long lvalue = toLong(lobj); 81 long low = toLong(lowObj); 82 long high = toLong(highObj); 83 84 return toBoolean(low <= lvalue && lvalue <= high); 85 } 86 else { 87 double lvalue = toDouble(lobj); 88 double low = toDouble(lowObj); 89 double high = toDouble(highObj); 90 91 return toBoolean(low <= lvalue && lvalue <= high); 92 } 93 } 94 } 95 | Popular Tags |