@@ -0,0 +1,2094 @@
+/*%0D%0A * Copyright 2006 The Apache Software Foundation.%0D%0A *%0D%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0D%0A * you may not use this file except in compliance with the License.%0D%0A * You may obtain a copy of the License at%0D%0A *%0D%0A *   http://www.apache.org/licenses/LICENSE-2.0%0D%0A *%0D%0A * Unless required by applicable law or agreed to in writing, software%0D%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0D%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0D%0A * See the License for the specific language governing permissions and%0D%0A * limitations under the License.%0D%0A * %0D%0A */%0D%0A%0D%0Apackage org.apache.jorphan.math;%0D%0A%0D%0A/**%0D%0A * Class to calculate various items that don't require all previous results to be saved:%0D%0A * - mean = average%0D%0A * - standard deviation%0D%0A * - minimum%0D%0A * - maximum%0D%0A */%0D%0Apublic class Calculator %7B%0D%0A%0D%0A%09private double sum = 0;%0D%0A%0D%0A%09private double sumOfSquares = 0;%0D%0A%0D%0A%09private double mean = 0;%0D%0A%0D%0A%09private double deviation = 0;%0D%0A%0D%0A%09private int count = 0;%0D%0A%0D%0A%09private long bytes = 0;%0D%0A%09%0D%0A%09private long maximum = Long.MIN_VALUE;%0D%0A%09%0D%0A%09private long minimum = Long.MAX_VALUE;%0D%0A%09%0D%0A%09public void clear() %7B%0D%0A%09%09maximum = Long.MIN_VALUE;%0D%0A%09%09minimum = Long.MAX_VALUE;%0D%0A%09%09sum = 0;%0D%0A%09%09sumOfSquares = 0;%0D%0A%09%09mean = 0;%0D%0A%09%09deviation = 0;%0D%0A%09%09count = 0;%0D%0A%09%7D%0D%0A%0D%0A%09public void addValue(long newValue) %7B%0D%0A%09%09count++;%0D%0A%09%09minimum=Math.min(newValue, minimum);%0D%0A%09%09maximum=Math.max(newValue, maximum);%0D%0A%09%09double currentVal = newValue;%0D%0A%09%09sum += currentVal;%0D%0A%09%09sumOfSquares += currentVal * currentVal;%0D%0A%09%09// Calculate each time, as likely to be called for each add%0D%0A%09%09mean = sum / count;%0D%0A%09%09deviation = Math.sqrt((sumOfSquares / count) - (mean * mean));%0D%0A%09%7D%0D%0A%0D%0A%0D%0A%09public void addBytes(long newValue) %7B%0D%0A%09%09bytes += newValue;%0D%0A%09%7D%0D%0A%0D%0A%09public long getTotalBytes() %7B%0D%0A%09%09return bytes;%0D%0A%09%7D%0D%0A%0D%0A%0D%0A%09public double getMean() %7B%0D%0A%09%09return mean;%0D%0A%09%7D%0D%0A%0D%0A%09public double getStandardDeviation() %7B%0D%0A%09%09return deviation;%0D%0A%09%7D%0D%0A%0D%0A%09public long getMin() %7B%0D%0A%09%09return minimum;%0D%0A%09%7D%0D%0A%0D%0A%09public long getMax() %7B%0D%0A%09%09return maximum;%0D%0A%09%7D%0D%0A%0D%0A%09public int getCount() %7B%0D%0A%09%09return count;%0D%0A%09%7D%0D%0A%7D

Add cheaper calculator (no need to save results)