01: /*
02: * BEGIN_HEADER - DO NOT EDIT
03: *
04: * The contents of this file are subject to the terms
05: * of the Common Development and Distribution License
06: * (the "License"). You may not use this file except
07: * in compliance with the License.
08: *
09: * You can obtain a copy of the license at
10: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
11: * See the License for the specific language governing
12: * permissions and limitations under the License.
13: *
14: * When distributing Covered Code, include this CDDL
15: * HEADER in each file and include the License file at
16: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
17: * If applicable add the following below this CDDL HEADER,
18: * with the fields enclosed by brackets "[]" replaced with
19: * your own identifying information: Portions Copyright
20: * [year] [name of copyright owner]
21: */
22:
23: /*
24: * @(#)Value.java
25: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
26: *
27: * END_HEADER - DO NOT EDIT
28: */
29: package com.sun.jbi.messaging.stats;
30:
31: /** Simple value sampler that computes basic statistics.
32: * @author Sun Microsystems, Inc.
33: */
34: public class Value {
35: private double sum;
36: private double squaredsum;
37: private long min;
38: private long max;
39: private long count;
40:
41: public Value() {
42: }
43:
44: public void zero() {
45: sum = 0.0;
46: squaredsum = 0.0;
47: min = 0;
48: max = 0;
49: count = 0;
50: }
51:
52: public void addSample(long sample) {
53: if (sample < min || count == 0) {
54: min = sample;
55: }
56: if (sample > max || count == 0) {
57: max = sample;
58: }
59: count++;
60: sum += sample;
61: squaredsum += ((double) sample) * ((double) sample);
62: }
63:
64: public double getAverage() {
65: return (sum / count);
66: }
67:
68: public long getMin() {
69: return (min);
70: }
71:
72: public long getMax() {
73: return (max);
74: }
75:
76: public long getCount() {
77: return (count);
78: }
79:
80: public double getSd() {
81: return (Math.sqrt((1.0 / (count - 1))
82: * (squaredsum - ((sum * sum) / count))));
83: }
84:
85: public String toString() {
86: StringBuilder sb = new StringBuilder();
87:
88: sb.append("Count(" + count + ")");
89: sb.append("Min(" + min + ")");
90: sb.append("Avg(" + getAverage() + ")");
91: sb.append("Max(" + max + ")");
92: sb.append("Std(" + getSd() + ")");
93:
94: return (sb.toString());
95: }
96:
97: }
|