1 19 20 package org.apache.cayenne.exp.parser; 21 22 import org.apache.cayenne.exp.Expression; 23 import org.apache.cayenne.util.ConversionUtil; 24 25 31 public class ASTLessOrEqual extends ConditionNode { 32 33 36 ASTLessOrEqual(int id) { 37 super(id); 38 } 39 40 public ASTLessOrEqual() { 41 super(ExpressionParserTreeConstants.JJTLESSOREQUAL); 42 } 43 44 public ASTLessOrEqual(ASTPath path, Object value) { 45 super(ExpressionParserTreeConstants.JJTLESSOREQUAL); 46 jjtAddChild(path, 0); 47 jjtAddChild(new ASTScalar(value), 1); 48 } 49 50 protected Object evaluateNode(Object o) throws Exception { 51 int len = jjtGetNumChildren(); 52 if (len != 2) { 53 return Boolean.FALSE; 54 } 55 56 Comparable c1 = ConversionUtil.toComparable(evaluateChild(0, o)); 57 if (c1 == null) { 58 return Boolean.FALSE; 59 } 60 61 Comparable c2 = ConversionUtil.toComparable(evaluateChild(1, o)); 62 if (c2 == null) { 63 return Boolean.FALSE; 64 } 65 66 return c1.compareTo(c2) <= 0 ? Boolean.TRUE : Boolean.FALSE; 67 } 68 69 72 public Expression shallowCopy() { 73 return new ASTLessOrEqual(id); 74 } 75 76 protected String getExpressionOperator(int index) { 77 return "<="; 78 } 79 80 public int getType() { 81 return Expression.LESS_THAN_EQUAL_TO; 82 } 83 } 84 | Popular Tags |