KickJava   Java API By Example, From Geeks To Geeks.

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


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 FunctionMedValue extends FunctionValue {
17   int count;
18   double sum;
19
20   static Logger log4jFunctionMedValue = Logger.getLogger(FunctionMedValue.class);
21
22   public FunctionMedValue(FunctionTemplate functionTemplate, XmlDocument xmlDocument) {
23     super(functionTemplate, xmlDocument);
24   }
25
26   public String JavaDoc print() {
27     if (functionTemplate.formatOutput != null) {
28       return functionTemplate.formatOutput.format(sum/count);
29     } else {
30       return Double.toString(sum/count);
31     }
32   }
33
34   public String JavaDoc printSimple() {
35     if (functionTemplate.formatSimple != null) {
36       return functionTemplate.formatSimple.format(sum/count);
37     } else {
38       return Double.toString(sum/count);
39     }
40   }
41
42   public void acumulate() {
43     count ++;
44     if (fieldValue.print() != "") {
45       sum += Double.valueOf(fieldValue.printSimple()).doubleValue();
46     }
47   }
48
49   public void init() {
50     sum = 0;
51     count = 0;
52   }
53
54 }
55
Popular Tags