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