1 package com.airbnb.lottie.utils; 2 3 /** 4 * Class to calculate the average in a stream of numbers on a continuous basis. 5 */ 6 public class MeanCalculator { 7 8 private float sum; 9 private int n; 10 add(float number)11 public void add(float number) { 12 sum += number; 13 n++; 14 if (n == Integer.MAX_VALUE) { 15 sum /= 2f; 16 n /= 2; 17 } 18 } 19 getMean()20 public float getMean() { 21 if (n == 0) { 22 return 0; 23 } 24 return sum / (float) n; 25 } 26 } 27