• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.mobileer.oboetester;
18 
19 import java.util.ArrayList;
20 
21 class DoubleStatistics {
22     ArrayList<Double> mValues = new ArrayList<Double>();
23     private double mMin = Double.MAX_VALUE;
24     private double mMax = Double.MIN_VALUE;
25     private double mSum = 0.0;
26 
27     // Number of measurements.
count()28     public int count() {
29         return mValues.size();
30     }
31 
add(double value)32     public void add(double value) {
33         mValues.add(value);
34         mMin = Math.min(value, mMin);
35         mMax = Math.max(value, mMax);
36         mSum += value;
37     }
38 
calculateMeanAbsoluteDeviation(double mean)39     public double calculateMeanAbsoluteDeviation(double mean) {
40         double deviationSum = 0.0;
41         for (double value : mValues) {
42             deviationSum += Math.abs(value - mean);
43         }
44         return deviationSum / mValues.size();
45     }
46 
47     // This will crash if there are no values added.
calculateMean()48     public double calculateMean() {
49         return mSum / mValues.size();
50     }
51 
getMin()52     public double getMin() {
53         return mMin;
54     }
55 
getMax()56     public double getMax() {
57         return mMax;
58     }
59 
getSum()60     public double getSum() {
61         return mSum;
62     }
63 
64     // This will crash if there are no values added.
getLast()65     public double getLast() {
66         return mValues.get(mValues.size() - 1);
67     }
68 }
69