1 /*
   2  * Copyright (c) 2014, 2015, Dynatrace and/or its affiliates. All rights reserved.
   3  * 
   4  * This file is part of the Lock Contention Tracing Subsystem for the HotSpot
   5  * Virtual Machine, which is developed at Christian Doppler Laboratory on
   6  * Monitoring and Evolution of Very-Large-Scale Software Systems. Please
   7  * contact us at <http://mevss.jku.at/> if you need additional information
   8  * or have any questions.
   9  *
  10  * This code is free software; you can redistribute it and/or modify it
  11  * under the terms of the GNU General Public License version 2 only, as
  12  * published by the Free Software Foundation.
  13  *
  14  * This code is distributed in the hope that it will be useful, but WITHOUT
  15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  16  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  17  * version 2 for more details (a copy is included in the LICENSE file that
  18  * accompanied this code).
  19  *
  20  * You should have received a copy of the GNU General Public License version
  21  * 2 along with this work. If not, see <http://www.gnu.org/licenses/>.
  22  *
  23  */ 
  24 package sun.evtracing.processing.statistics;
  25 
  26 public class NumberStatistic {
  27         public static NumberStatistic merge(NumberStatistic x, NumberStatistic y) {
  28                 NumberStatistic s = new NumberStatistic();
  29                 s.max = Math.max(x.max, y.max);
  30                 s.count = x.count + y.count;
  31                 s.sum = x.sum + y.sum;
  32                 return s;
  33         }
  34 
  35         private long max;
  36         private long sum;
  37         private long count;
  38 
  39         public long getSum() {
  40                 return sum;
  41         }
  42 
  43         public double getAverage() {
  44                 if (count > 0) {
  45                         return sum / count;
  46                 } else {
  47                         return Double.NaN;
  48                 }
  49         }
  50 
  51         public long getMax() {
  52                 return max;
  53         }
  54 
  55         public void add(long value) {
  56                 max = Math.max(max, value);
  57                 sum += value;
  58                 count++;
  59         }
  60 }