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 43 public class ASTEQNode extends SimpleNode { 44 49 public ASTEQNode(int id) { 50 super(id); 51 } 52 53 59 public ASTEQNode(Parser p, int id) { 60 super(p, id); 61 } 62 63 64 public Object jjtAccept(ParserVisitor visitor, Object data) { 65 return visitor.visit(this, data); 66 } 67 68 69 public Object value(JexlContext pc) throws Exception { 70 Object left = ((SimpleNode) jjtGetChild(0)).value(pc); 71 Object right = ((SimpleNode) jjtGetChild(1)).value(pc); 72 73 if (left == null && right == null) { 74 77 return Boolean.TRUE; 78 } else if (left == null || right == null) { 79 82 return Boolean.FALSE; 83 } else if (left.getClass().equals(right.getClass())) { 84 return left.equals(right) ? Boolean.TRUE : Boolean.FALSE; 85 } else if (left instanceof Float || left instanceof Double 86 || right instanceof Float || right instanceof Double ) { 87 Double l = Coercion.coerceDouble(left); 88 Double r = Coercion.coerceDouble(right); 89 90 return l.equals(r) ? Boolean.TRUE : Boolean.FALSE; 91 } else if (left instanceof Number || right instanceof Number 92 || left instanceof Character || right instanceof Character ) { 93 return Coercion.coerceLong(left).equals(Coercion.coerceLong(right)) ? Boolean.TRUE 94 : Boolean.FALSE; 95 } else if (left instanceof Boolean || right instanceof Boolean ) { 96 return Coercion.coerceBoolean(left).equals( 97 Coercion.coerceBoolean(right)) ? Boolean.TRUE 98 : Boolean.FALSE; 99 } else if (left instanceof java.lang.String || right instanceof String ) { 100 return left.toString().equals(right.toString()) ? Boolean.TRUE 101 : Boolean.FALSE; 102 } 103 104 return left.equals(right) ? Boolean.TRUE : Boolean.FALSE; 105 } 106 } 107 | Popular Tags |