001: package com.quadcap.jni;
002:
003: /* Copyright 2000 - 2003 Quadcap Software. All rights reserved.
004: *
005: * This software is distributed under the Quadcap Free Software License.
006: * This software may be used or modified for any purpose, personal or
007: * commercial. Open Source redistributions are permitted. Commercial
008: * redistribution of larger works derived from, or works which bundle
009: * this software requires a "Commercial Redistribution License"; see
010: * http://www.quadcap.com/purchase.
011: *
012: * Redistributions qualify as "Open Source" under one of the following terms:
013: *
014: * Redistributions are made at no charge beyond the reasonable cost of
015: * materials and delivery.
016: *
017: * Redistributions are accompanied by a copy of the Source Code or by an
018: * irrevocable offer to provide a copy of the Source Code for up to three
019: * years at the cost of materials and delivery. Such redistributions
020: * must allow further use, modification, and redistribution of the Source
021: * Code under substantially the same terms as this license.
022: *
023: * Redistributions of source code must retain the copyright notices as they
024: * appear in each source code file, these license terms, and the
025: * disclaimer/limitation of liability set forth as paragraph 6 below.
026: *
027: * Redistributions in binary form must reproduce this Copyright Notice,
028: * these license terms, and the disclaimer/limitation of liability set
029: * forth as paragraph 6 below, in the documentation and/or other materials
030: * provided with the distribution.
031: *
032: * The Software is provided on an "AS IS" basis. No warranty is
033: * provided that the Software is free of defects, or fit for a
034: * particular purpose.
035: *
036: * Limitation of Liability. Quadcap Software shall not be liable
037: * for any damages suffered by the Licensee or any third party resulting
038: * from use of the Software.
039: */
040:
041: import java.util.HashMap;
042:
043: /**
044: * A simple statistics object
045: *
046: * @author Stan Bailes
047: */
048: public class Stat {
049: HashMap prev = new HashMap();
050: String name;
051: double max = Double.MIN_VALUE;
052: double min = Double.MAX_VALUE;
053: double sum = 0;
054: // double sumsq = 0;
055: long count = 0;
056:
057: public Stat(String s) {
058: name = s;
059: }
060:
061: public void add(double d) {
062: if (d > max)
063: max = d;
064: if (d < min)
065: min = d;
066: sum += d;
067: // sumsq += (d * d);
068: count++;
069: }
070:
071: /**
072: * Return the arithmetic mean (the "average") of the sample
073: */
074: public final double getMean() {
075: if (count == 0)
076: return 0;
077: return sum / (double) count;
078: }
079:
080: /**
081: * Throw out the high and the low before computing the average.
082: */
083: public double getAdjustedMean() {
084: if (count <= 2)
085: return getMean();
086: return ((sum - max) - min) / (count - 2);
087: }
088:
089: public final long getCount() {
090: return count;
091: }
092:
093: public double getMin() {
094: return min;
095: }
096:
097: public double getMax() {
098: return max;
099: }
100:
101: public String getName() {
102: return name;
103: }
104:
105: public void setName(String name) {
106: this .name = name;
107: }
108:
109: public double getTotal() {
110: return sum;
111: }
112:
113: public void addPrev(String s) {
114: Long x = (Long) prev.get(s);
115: if (x == null)
116: x = new Long(1);
117: else
118: x = new Long(x.longValue() + 1);
119: prev.put(s, x);
120: }
121:
122: public String toString() {
123: return "[" + name + "] (" + prev + ")";
124: }
125: }
|