1 56 57 package org.objectstyle.cayenne.exp.parser; 58 59 import java.math.BigDecimal ; 60 import java.util.Collection ; 61 import java.util.Iterator ; 62 63 import org.objectstyle.cayenne.exp.Expression; 64 import org.objectstyle.cayenne.util.ConversionUtil; 65 66 72 public class ASTMultiply extends SimpleNode { 73 ASTMultiply(int id) { 74 super(id); 75 } 76 77 public ASTMultiply() { 78 super(ExpressionParserTreeConstants.JJTMULTIPLY); 79 } 80 81 public ASTMultiply(Object [] nodes) { 82 super(ExpressionParserTreeConstants.JJTMULTIPLY); 83 int len = nodes.length; 84 for (int i = 0; i < len; i++) { 85 jjtAddChild(wrapChild(nodes[i]), i); 86 } 87 } 88 89 public ASTMultiply(Collection nodes) { 90 super(ExpressionParserTreeConstants.JJTMULTIPLY); 91 int len = nodes.size(); 92 Iterator it = nodes.iterator(); 93 for (int i = 0; i < len; i++) { 94 jjtAddChild(wrapChild(it.next()), i); 95 } 96 } 97 98 protected Object evaluateNode(Object o) throws Exception { 99 int len = jjtGetNumChildren(); 100 if (len == 0) { 101 return null; 102 } 103 104 BigDecimal result = null; 105 for (int i = 0; i < len; i++) { 106 BigDecimal value = ConversionUtil.toBigDecimal(evaluateChild(i, o)); 107 108 if (value == null) { 109 return null; 110 } 111 112 result = (i == 0) ? value : result.multiply(value); 113 } 114 115 return result; 116 } 117 118 121 public Expression shallowCopy() { 122 return new ASTMultiply(id); 123 } 124 125 protected String getExpressionOperator(int index) { 126 return "*"; 127 } 128 129 public int getType() { 130 return Expression.MULTIPLY; 131 } 132 133 public void jjtClose() { 134 super.jjtClose(); 135 flattenTree(); 136 } 137 } 138 | Popular Tags |