1 16 package org.apache.commons.jexl.parser; 17 18 import org.apache.commons.jexl.JexlContext; 19 import org.apache.commons.jexl.util.Coercion; 20 21 30 public class ASTLENode extends SimpleNode { 31 36 public ASTLENode(int id) { 37 super(id); 38 } 39 40 46 public ASTLENode(Parser p, int id) { 47 super(p, id); 48 } 49 50 51 public Object jjtAccept(ParserVisitor visitor, Object data) { 52 return visitor.visit(this, data); 53 } 54 55 56 public Object value(JexlContext jc) throws Exception { 57 60 61 Object left = ((SimpleNode) jjtGetChild(0)).value(jc); 62 Object right = ((SimpleNode) jjtGetChild(1)).value(jc); 63 64 if (left == right) { 65 return Boolean.TRUE; 66 } else if ((left == null) || (right == null)) { 67 return Boolean.FALSE; 68 } else if (Coercion.isFloatingPoint(left) 69 || Coercion.isFloatingPoint(right)) { 70 double leftDouble = Coercion.coerceDouble(left).doubleValue(); 71 double rightDouble = Coercion.coerceDouble(right).doubleValue(); 72 73 return leftDouble <= rightDouble ? Boolean.TRUE : Boolean.FALSE; 74 } else if (Coercion.isNumberable(left) || Coercion.isNumberable(right)) { 75 long leftLong = Coercion.coerceLong(left).longValue(); 76 long rightLong = Coercion.coerceLong(right).longValue(); 77 78 return leftLong <= rightLong ? Boolean.TRUE : Boolean.FALSE; 79 } else if (left instanceof String || right instanceof String ) { 80 String leftString = left.toString(); 81 String rightString = right.toString(); 82 83 return leftString.compareTo(rightString) <= 0 ? Boolean.TRUE 84 : Boolean.FALSE; 85 } else if (left instanceof Comparable ) { 86 return ((Comparable ) left).compareTo(right) <= 0 ? Boolean.TRUE 87 : Boolean.FALSE; 88 } else if (right instanceof Comparable ) { 89 return ((Comparable ) right).compareTo(left) >= 0 ? Boolean.TRUE 90 : Boolean.FALSE; 91 } 92 93 throw new Exception ("Invalid comparison : LE "); 94 } 95 96 } 97 | Popular Tags |