KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > xmlEngine > FunctionSumValue


1 /*
2  ************************************************************************************
3  * Copyright (C) 2001-2006 Openbravo S.L.
4  * Licensed under the Apache Software License version 2.0
5  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6  * Unless required by applicable law or agreed to in writing, software distributed
7  * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
8  * CONDITIONS OF ANY KIND, either express or implied. See the License for the
9  * specific language governing permissions and limitations under the License.
10  ************************************************************************************
11 */

12 package org.openbravo.xmlEngine;
13
14 import org.apache.log4j.Logger ;
15
16 class FunctionSumValue extends FunctionValue {
17   double sum;
18
19   static Logger log4jFunctionSumValue = Logger.getLogger(FunctionSumValue.class);
20
21   public FunctionSumValue(FunctionTemplate functionTemplate, XmlDocument xmlDocument) {
22     super(functionTemplate, xmlDocument);
23   }
24
25   public String JavaDoc print() {
26     if (functionTemplate.formatOutput != null) {
27       return functionTemplate.formatOutput.format(sum);
28     } else {
29       return Double.toString(sum);
30     }
31   }
32
33   public String JavaDoc printSimple() {
34     if (functionTemplate.formatSimple != null) {
35       return functionTemplate.formatSimple.format(sum);
36     } else {
37       return Double.toString(sum);
38     }
39   }
40
41   public void acumulate() {
42     log4jFunctionSumValue.debug("Accumulate: " + fieldValue.print());
43     if (fieldValue.print() != "") {
44       sum += Double.valueOf(fieldValue.printSimple()).doubleValue();
45     }
46   }
47
48   public void init() {
49     sum = 0;
50   }
51
52 }
53
Popular Tags