1 56 package org.objectstyle.cayenne.exp.parser; 57 58 import org.objectstyle.cayenne.exp.Expression; 59 import org.objectstyle.cayenne.util.ConversionUtil; 60 61 67 public class ASTBetween extends ConditionNode { 68 69 ASTBetween(int id) { 70 super(id); 71 } 72 73 public ASTBetween() { 74 super(ExpressionParserTreeConstants.JJTBETWEEN); 75 } 76 77 public ASTBetween(ASTPath path, Object value1, Object value2) { 78 super(ExpressionParserTreeConstants.JJTBETWEEN); 79 jjtAddChild(path, 0); 80 jjtAddChild(new ASTScalar(value1), 1); 81 jjtAddChild(new ASTScalar(value2), 2); 82 } 83 84 protected Object evaluateNode(Object o) throws Exception { 85 int len = jjtGetNumChildren(); 86 if (len != 3) { 87 return Boolean.FALSE; 88 } 89 90 Comparable c1 = ConversionUtil.toComparable(evaluateChild(0, o)); 91 92 if (c1 == null) { 93 return Boolean.FALSE; 94 } 95 96 Comparable c2 = ConversionUtil.toComparable(evaluateChild(1, o)); 97 if (c2 == null) { 98 return Boolean.FALSE; 99 } 100 101 Comparable c3 = ConversionUtil.toComparable(evaluateChild(2, o)); 102 if (c3 == null) { 103 return Boolean.FALSE; 104 } 105 106 return c1.compareTo(c2) >= 0 107 && c1.compareTo(c3) <= 0 ? Boolean.TRUE : Boolean.FALSE; 108 } 109 110 113 public Expression shallowCopy() { 114 return new ASTBetween(id); 115 } 116 117 protected String getExpressionOperator(int index) { 118 return (index == 2) ? "and" : "between"; 119 } 120 121 public int getType() { 122 return Expression.BETWEEN; 123 } 124 } 125 | Popular Tags |