Example usage for java.util DoubleSummaryStatistics getSum

List of usage examples for java.util DoubleSummaryStatistics getSum

Introduction

In this page you can find the example usage for java.util DoubleSummaryStatistics getSum.

Prototype

public final double getSum() 

Source Link

Document

Returns the sum of values recorded, or zero if no values have been recorded.

Usage

From source file:Main.java

public static void main(String[] args) {
    DoubleSummaryStatistics stats = new DoubleSummaryStatistics();
    stats.accept(100.0);/*ww  w  .  ja  v  a 2 s . co m*/
    stats.accept(300.0);
    stats.accept(230.0);
    stats.accept(532.0);
    stats.accept(422.0);

    long count = stats.getCount();
    double sum = stats.getSum();
    double min = stats.getMin();
    double avg = stats.getAverage();
    double max = stats.getMax();

    System.out.printf("count=%d, sum=%.2f,  min=%.2f,  average=%.2f, max=%.2f%n", count, sum, min, max, avg);
}

From source file:org.apache.metron.indexing.dao.metaalert.MetaScores.java

public MetaScores(List<Double> scores) {
    // A meta alert could be entirely alerts with no values.
    DoubleSummaryStatistics stats = scores.stream().mapToDouble(a -> a).summaryStatistics();
    metaScores.put("max", stats.getMax());
    metaScores.put("min", stats.getMin());
    metaScores.put("average", stats.getAverage());
    metaScores.put("count", stats.getCount());
    metaScores.put("sum", stats.getSum());

    // median isn't in the stats summary
    double[] arr = scores.stream().mapToDouble(d -> d).toArray();
    metaScores.put("median", new Median().evaluate(arr));
}

From source file:org.opennms.web.controller.trend.TrendController.java

private Map<String, String> variableReplacements(final List<Double> values) {
    final Map<String, String> replacements = new HashMap<>();

    final DoubleSummaryStatistics doubleSummaryStatistics = values.stream().mapToDouble(Double::doubleValue)
            .summaryStatistics();//from w  w w. j a v a 2  s .  c o m

    replacements.put("${doubleMax}", String.format("%.2f", doubleSummaryStatistics.getMax()));
    replacements.put("${intMax}", String.format("%d", (int) doubleSummaryStatistics.getMax()));

    replacements.put("${doubleMin}", String.format("%.2f", doubleSummaryStatistics.getMin()));
    replacements.put("${intMin}", String.format("%d", (int) doubleSummaryStatistics.getMin()));

    replacements.put("${doubleAvg}", String.format("%.2f", doubleSummaryStatistics.getAverage()));
    replacements.put("${intAvg}", String.format("%d", (int) doubleSummaryStatistics.getAverage()));

    replacements.put("${doubleSum}", String.format("%.2f", doubleSummaryStatistics.getSum()));
    replacements.put("${intSum}", String.format("%d", (int) doubleSummaryStatistics.getSum()));

    for (int i = 0; i < values.size(); i++) {
        double current = values.get(i);

        replacements.put("${doubleValue[" + i + "]}", String.format("%.2f", current));
        replacements.put("${intValue[" + i + "]}", String.format("%d", (int) current));

        if (i > 0) {
            double previous = values.get(i - 1);
            double change = current - previous;

            replacements.put("${doubleValueChange[" + i + "]}", String.format("%+.2f", change));
            replacements.put("${intValueChange[" + i + "]}", String.format("%+d", (int) change));
        } else {
            replacements.put("${doubleValueChange[" + i + "]}", "NaN");
            replacements.put("${intValueChange[" + i + "]}", "NaN");
        }
    }

    if (values.size() > 0) {
        replacements.put("${doubleLastValueChange}",
                replacements.get("${doubleValueChange[" + (values.size() - 1) + "]}"));
        replacements.put("${intLastValueChange}",
                replacements.get("${intValueChange[" + (values.size() - 1) + "]}"));

        replacements.put("${doubleLastValue}", replacements.get("${doubleValue[" + (values.size() - 1) + "]}"));
        replacements.put("${intLastValue}", replacements.get("${intValue[" + (values.size() - 1) + "]}"));
    } else {
        replacements.put("${doubleLastValueChange}", "NaN");
        replacements.put("${intLastValueChange}", "NaN");

        replacements.put("${doubleLastValue}", "NaN");
        replacements.put("${intLastValue}", "NaN");
    }

    return replacements;
}