jdk/src/share/classes/java/util/DoubleSummaryStatistics.java
author psandoz
Wed, 04 Sep 2013 09:34:25 +0200
changeset 19806 dda89341ee2d
parent 19214 e5901820c3c1
child 20758 d8845d3fb428
permissions -rw-r--r--
8023463: Improvements to HashMap/LinkedHashMap use of bins/buckets and trees (red/black) 8012913: LinkedHashMap key/value/entry spliterators should report ORDERED Reviewed-by: mduigou, forax, bchristi, alanb Contributed-by: Doug Lea <dl@cs.oswego.edu>, Paul Sandoz <paul.sandoz@oracle.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16922
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
     1
/*
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
     2
 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
     4
 *
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    10
 *
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    15
 * accompanied this code).
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    16
 *
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    20
 *
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    23
 * questions.
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    24
 */
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    25
package java.util;
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    26
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    27
import java.util.function.DoubleConsumer;
19214
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 16922
diff changeset
    28
import java.util.stream.Collector;
16922
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    29
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    30
/**
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    31
 * A state object for collecting statistics such as count, min, max, sum, and
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    32
 * average.
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    33
 *
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    34
 * <p>This class is designed to work with (though does not require)
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    35
 * {@linkplain java.util.stream streams}. For example, you can compute
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    36
 * summary statistics on a stream of doubles with:
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    37
 * <pre> {@code
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    38
 * DoubleSummaryStatistics stats = doubleStream.collect(DoubleSummaryStatistics::new,
19214
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 16922
diff changeset
    39
 *                                                      DoubleSummaryStatistics::accept,
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 16922
diff changeset
    40
 *                                                      DoubleSummaryStatistics::combine);
16922
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    41
 * }</pre>
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    42
 *
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    43
 * <p>{@code DoubleSummaryStatistics} can be used as a
19214
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 16922
diff changeset
    44
 * {@linkplain java.util.stream.Stream#collect(Collector) reduction}
16922
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    45
 * target for a {@linkplain java.util.stream.Stream stream}. For example:
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    46
 *
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    47
 * <pre> {@code
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    48
 * DoubleSummaryStatistics stats = people.stream()
19214
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 16922
diff changeset
    49
 *     .collect(Collectors.summarizingDouble(Person::getWeight));
16922
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    50
 *}</pre>
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    51
 *
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    52
 * This computes, in a single pass, the count of people, as well as the minimum,
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    53
 * maximum, sum, and average of their weights.
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    54
 *
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    55
 * @implNote This implementation is not thread safe. However, it is safe to use
19214
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 16922
diff changeset
    56
 * {@link java.util.stream.Collectors#summarizingDouble(java.util.function.ToDoubleFunction)
16922
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    57
 * Collectors.toDoubleStatistics()} on a parallel stream, because the parallel
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    58
 * implementation of {@link java.util.stream.Stream#collect Stream.collect()}
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    59
 * provides the necessary partitioning, isolation, and merging of results for
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    60
 * safe and efficient parallel execution.
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    61
 * @since 1.8
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    62
 */
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    63
public class DoubleSummaryStatistics implements DoubleConsumer {
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    64
    private long count;
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    65
    private double sum;
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    66
    private double min = Double.POSITIVE_INFINITY;
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    67
    private double max = Double.NEGATIVE_INFINITY;
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    68
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    69
    /**
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    70
     * Construct an empty instance with zero count, zero sum,
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    71
     * {@code Double.POSITIVE_INFINITY} min, {@code Double.NEGATIVE_INFINITY}
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    72
     * max and zero average.
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    73
     */
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    74
    public DoubleSummaryStatistics() { }
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    75
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    76
    /**
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    77
     * Records another value into the summary information.
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    78
     *
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    79
     * @param value the input value
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    80
     */
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    81
    @Override
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    82
    public void accept(double value) {
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    83
        ++count;
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    84
        sum += value;
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    85
        min = Math.min(min, value);
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    86
        max = Math.max(max, value);
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    87
    }
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    88
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    89
    /**
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    90
     * Combines the state of another {@code DoubleSummaryStatistics} into this
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    91
     * one.
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    92
     *
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    93
     * @param other another {@code DoubleSummaryStatistics}
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    94
     * @throws NullPointerException if {@code other} is null
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    95
     */
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    96
    public void combine(DoubleSummaryStatistics other) {
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    97
        count += other.count;
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    98
        sum += other.sum;
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
    99
        min = Math.min(min, other.min);
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   100
        max = Math.max(max, other.max);
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   101
    }
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   102
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   103
    /**
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   104
     * Return the count of values recorded.
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   105
     *
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   106
     * @return the count of values
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   107
     */
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   108
    public final long getCount() {
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   109
        return count;
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   110
    }
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   111
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   112
    /**
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   113
     * Returns the sum of values recorded, or zero if no values have been
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   114
     * recorded. The sum returned can vary depending upon the order in which
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   115
     * values are recorded. This is due to accumulated rounding error in
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   116
     * addition of values of differing magnitudes. Values sorted by increasing
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   117
     * absolute magnitude tend to yield more accurate results.  If any recorded
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   118
     * value is a {@code NaN} or the sum is at any point a {@code NaN} then the
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   119
     * sum will be {@code NaN}.
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   120
     *
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   121
     * @return the sum of values, or zero if none
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   122
     */
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   123
    public final double getSum() {
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   124
        return sum;
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   125
    }
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   126
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   127
    /**
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   128
     * Returns the minimum recorded value, {@code Double.NaN} if any recorded
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   129
     * value was NaN or {@code Double.POSITIVE_INFINITY} if no values were
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   130
     * recorded. Unlike the numerical comparison operators, this method
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   131
     * considers negative zero to be strictly smaller than positive zero.
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   132
     *
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   133
     * @return the minimum recorded value, {@code Double.NaN} if any recorded
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   134
     * value was NaN or {@code Double.POSITIVE_INFINITY} if no values were
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   135
     * recorded
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   136
     */
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   137
    public final double getMin() {
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   138
        return min;
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   139
    }
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   140
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   141
    /**
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   142
     * Returns the maximum recorded value, {@code Double.NaN} if any recorded
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   143
     * value was NaN or {@code Double.NEGATIVE_INFINITY} if no values were
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   144
     * recorded. Unlike the numerical comparison operators, this method
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   145
     * considers negative zero to be strictly smaller than positive zero.
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   146
     *
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   147
     * @return the maximum recorded value, {@code Double.NaN} if any recorded
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   148
     * value was NaN or {@code Double.NEGATIVE_INFINITY} if no values were
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   149
     * recorded
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   150
     */
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   151
    public final double getMax() {
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   152
        return max;
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   153
    }
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   154
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   155
    /**
19214
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 16922
diff changeset
   156
     * Returns the arithmetic mean of values recorded, or zero if no values have been
16922
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   157
     * recorded. The average returned can vary depending upon the order in
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   158
     * which values are recorded. This is due to accumulated rounding error in
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   159
     * addition of values of differing magnitudes. Values sorted by increasing
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   160
     * absolute magnitude tend to yield more accurate results. If any recorded
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   161
     * value is a {@code NaN} or the sum is at any point a {@code NaN} then the
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   162
     * average will be {@code NaN}.
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   163
     *
19214
e5901820c3c1 8015318: Extend Collector with 'finish' operation
briangoetz
parents: 16922
diff changeset
   164
     * @return the arithmetic mean of values, or zero if none
16922
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   165
     */
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   166
    public final double getAverage() {
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   167
        return getCount() > 0 ? getSum() / getCount() : 0.0d;
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   168
    }
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   169
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   170
    /**
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   171
     * {@inheritDoc}
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   172
     *
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   173
     * Returns a non-empty string representation of this object suitable for
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   174
     * debugging. The exact presentation format is unspecified and may vary
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   175
     * between implementations and versions.
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   176
     */
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   177
    @Override
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   178
    public String toString() {
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   179
        return String.format(
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   180
            "%s{count=%d, sum=%f, min=%f, average=%f, max=%f}",
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   181
            this.getClass().getSimpleName(),
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   182
            getCount(),
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   183
            getSum(),
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   184
            getMin(),
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   185
            getAverage(),
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   186
            getMax());
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   187
    }
6c918c972850 8010953: Add primitive summary statistics utils
mduigou
parents:
diff changeset
   188
}