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 ASTGTNode extends SimpleNode { 31 36 public ASTGTNode(int id) { 37 super(id); 38 } 39 40 46 public ASTGTNode(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) || (left == null) || (right == null)) { 65 return Boolean.FALSE; 66 } else if (Coercion.isFloatingPoint(left) 67 || Coercion.isFloatingPoint(right)) { 68 double leftDouble = Coercion.coerceDouble(left).doubleValue(); 69 double rightDouble = Coercion.coerceDouble(right).doubleValue(); 70 71 return leftDouble > rightDouble ? Boolean.TRUE : Boolean.FALSE; 72 } else if (Coercion.isNumberable(left) || Coercion.isNumberable(right)) { 73 long leftLong = Coercion.coerceLong(left).longValue(); 74 long rightLong = Coercion.coerceLong(right).longValue(); 75 76 return leftLong > rightLong ? Boolean.TRUE : Boolean.FALSE; 77 } else if (left instanceof String || right instanceof String ) { 78 String leftString = left.toString(); 79 String rightString = right.toString(); 80 81 return leftString.compareTo(rightString) > 0 ? Boolean.TRUE 82 : Boolean.FALSE; 83 } else if (left instanceof Comparable ) { 84 return ((Comparable ) left).compareTo(right) > 0 ? Boolean.TRUE 85 : Boolean.FALSE; 86 } else if (right instanceof Comparable ) { 87 return ((Comparable ) right).compareTo(left) < 0 ? Boolean.TRUE 88 : Boolean.FALSE; 89 } 90 91 throw new Exception ("Invalid comparison : GT "); 92 } 93 } 94 | Popular Tags |