// 
// Decompiled by Procyon v0.6.0
// 

package com.hypixel.hytale.metrics.metric;

public class AverageCollector
{
    private double val;
    private long n;
    
    public AverageCollector() {
        this.val = 0.0;
        this.n = 0L;
    }
    
    public double get() {
        return this.val;
    }
    
    public long size() {
        return this.n;
    }
    
    public double addAndGet(final double v) {
        this.add(v);
        return this.get();
    }
    
    public void add(final double v) {
        ++this.n;
        this.val = this.val - this.val / this.n + v / this.n;
    }
    
    public void remove(final double v) {
        if (this.n == 1L) {
            this.n = 0L;
            this.val = 0.0;
        }
        else if (this.n > 1L) {
            this.val = (this.val - v / this.n) / (1.0 - 1.0 / this.n);
            --this.n;
        }
    }
    
    public void clear() {
        this.val = 0.0;
        this.n = 0L;
    }
    
    public static double add(final double val, final double v, final int n) {
        return val - val / n + v / n;
    }
    
    public void set(final double v) {
        this.n = 1L;
        this.val = v;
    }
}
