1 19 20 21 package org.apache.cayenne.exp.parser; 22 23 import java.math.BigDecimal ; 24 import java.util.Collection ; 25 import java.util.Iterator ; 26 27 import org.apache.cayenne.exp.Expression; 28 import org.apache.cayenne.util.ConversionUtil; 29 30 36 public class ASTMultiply extends SimpleNode { 37 ASTMultiply(int id) { 38 super(id); 39 } 40 41 public ASTMultiply() { 42 super(ExpressionParserTreeConstants.JJTMULTIPLY); 43 } 44 45 public ASTMultiply(Object [] nodes) { 46 super(ExpressionParserTreeConstants.JJTMULTIPLY); 47 int len = nodes.length; 48 for (int i = 0; i < len; i++) { 49 jjtAddChild(wrapChild(nodes[i]), i); 50 } 51 } 52 53 public ASTMultiply(Collection nodes) { 54 super(ExpressionParserTreeConstants.JJTMULTIPLY); 55 int len = nodes.size(); 56 Iterator it = nodes.iterator(); 57 for (int i = 0; i < len; i++) { 58 jjtAddChild(wrapChild(it.next()), i); 59 } 60 } 61 62 protected Object evaluateNode(Object o) throws Exception { 63 int len = jjtGetNumChildren(); 64 if (len == 0) { 65 return null; 66 } 67 68 BigDecimal result = null; 69 for (int i = 0; i < len; i++) { 70 BigDecimal value = ConversionUtil.toBigDecimal(evaluateChild(i, o)); 71 72 if (value == null) { 73 return null; 74 } 75 76 result = (i == 0) ? value : result.multiply(value); 77 } 78 79 return result; 80 } 81 82 85 public Expression shallowCopy() { 86 return new ASTMultiply(id); 87 } 88 89 protected String getExpressionOperator(int index) { 90 return "*"; 91 } 92 93 public int getType() { 94 return Expression.MULTIPLY; 95 } 96 97 public void jjtClose() { 98 super.jjtClose(); 99 flattenTree(); 100 } 101 } 102 | Popular Tags |