Path: blob/master/src/java.desktop/share/classes/sun/java2d/marlin/stats/StatLong.java
41161 views
/*1* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.java2d.marlin.stats;2627/**28* Statistics as long values29*/30public class StatLong {3132public final String name;33public long count = 0l;34public long sum = 0l;35public long min = Integer.MAX_VALUE;36public long max = Integer.MIN_VALUE;3738public StatLong(final String name) {39this.name = name;40}4142public void reset() {43count = 0l;44sum = 0l;45min = Integer.MAX_VALUE;46max = Integer.MIN_VALUE;47}4849public void add(final int val) {50count++;51sum += val;52if (val < min) {53min = val;54}55if (val > max) {56max = val;57}58}5960public void add(final long val) {61count++;62sum += val;63if (val < min) {64min = val;65}66if (val > max) {67max = val;68}69}7071@Override72public String toString() {73return toString(new StringBuilder(128)).toString();74}7576public final StringBuilder toString(final StringBuilder sb) {77sb.append(name).append('[').append(count);78sb.append("] sum: ").append(sum).append(" avg: ");79sb.append(trimTo3Digits(((double) sum) / count));80sb.append(" [").append(min).append(" | ").append(max).append("]");81return sb;82}8384/**85* Adjust the given double value to keep only 3 decimal digits86*87* @param value value to adjust88* @return double value with only 3 decimal digits89*/90public static double trimTo3Digits(final double value) {91return ((long) (1e3d * value)) / 1e3d;92}93}94959697