1 16 package org.apache.commons.jexl.parser; 17 18 import org.apache.commons.jexl.util.Coercion; 19 import org.apache.commons.jexl.JexlContext; 20 21 27 public class ASTDivNode extends SimpleNode { 28 33 public ASTDivNode(int id) { 34 super(id); 35 } 36 37 43 public ASTDivNode(Parser p, int id) { 44 super(p, id); 45 } 46 47 48 public Object jjtAccept(ParserVisitor visitor, Object data) { 49 return visitor.visit(this, data); 50 } 51 52 53 public Object value(JexlContext jc) throws Exception { 54 Object left = ((SimpleNode) jjtGetChild(0)).value(jc); 55 Object right = ((SimpleNode) jjtGetChild(1)).value(jc); 56 57 60 if (left == null && right == null) { 61 return new Byte ((byte) 0); 62 } 63 64 Double l = Coercion.coerceDouble(left); 65 Double r = Coercion.coerceDouble(right); 66 67 70 if (r.doubleValue() == 0.0) { 71 return new Double (0.0); 72 } 73 74 return new Double (l.doubleValue() / r.doubleValue()); 75 76 } 77 } 78 | Popular Tags |