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 ASTLessOrEqual extends ConditionNode { 68 69 72 ASTLessOrEqual(int id) { 73 super(id); 74 } 75 76 public ASTLessOrEqual() { 77 super(ExpressionParserTreeConstants.JJTLESSOREQUAL); 78 } 79 80 public ASTLessOrEqual(ASTPath path, Object value) { 81 super(ExpressionParserTreeConstants.JJTLESSOREQUAL); 82 jjtAddChild(path, 0); 83 jjtAddChild(new ASTScalar(value), 1); 84 } 85 86 protected Object evaluateNode(Object o) throws Exception { 87 int len = jjtGetNumChildren(); 88 if (len != 2) { 89 return Boolean.FALSE; 90 } 91 92 Comparable c1 = ConversionUtil.toComparable(evaluateChild(0, o)); 93 if (c1 == null) { 94 return Boolean.FALSE; 95 } 96 97 Comparable c2 = ConversionUtil.toComparable(evaluateChild(1, o)); 98 if (c2 == null) { 99 return Boolean.FALSE; 100 } 101 102 return c1.compareTo(c2) <= 0 ? Boolean.TRUE : Boolean.FALSE; 103 } 104 105 108 public Expression shallowCopy() { 109 return new ASTLessOrEqual(id); 110 } 111 112 protected String getExpressionOperator(int index) { 113 return "<="; 114 } 115 116 public int getType() { 117 return Expression.LESS_THAN_EQUAL_TO; 118 } 119 } 120 | Popular Tags |