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