1 43 44 package org.exolab.jms.selector; 45 46 import java.util.HashSet ; 47 import java.util.Iterator ; 48 import java.util.TreeSet ; 49 50 import javax.jms.Message ; 51 52 53 65 class InExpression extends IdentifierExpression { 66 67 70 private final HashSet _values; 71 72 73 79 public InExpression(final Identifier ident, final HashSet values) { 80 super(ident); 81 _values = values; 82 } 83 84 94 public final SObject evaluate(final Message msg) 95 throws TypeMismatchException { 96 SBool result = null; 97 98 SString value = TypeCaster.castToString(identifier().evaluate(msg), 99 "in expression"); 100 if (value != null) { 101 if (_values.contains(value.getObject())) { 102 result = SBool.TRUE; 103 } else { 104 result = SBool.FALSE; 105 } 106 } 107 return result; 108 } 109 110 115 public final String toString() { 116 StringBuffer result = new StringBuffer (); 117 result.append('('); 118 result.append(identifier().toString()); 119 result.append(" in ("); 120 int i = 0; 121 TreeSet sorted = new TreeSet (_values); 122 for (Iterator iter = sorted.iterator(); iter.hasNext(); i++) { 126 if (i > 0) { 127 result.append(", "); 128 } 129 result.append("'"); 130 result.append((String ) iter.next()); 131 result.append("'"); 132 } 133 result.append("))"); 134 return result.toString(); 135 } 136 137 } | Popular Tags |