agirstatool/src/org/april/agirstatool/core/Stat.java

132 lines
2.1 KiB
Java

/*
* Copyright (C) 2020 Christian Pierre MOMON <christian.momon@devinsy.fr>
*
* This file is part of AgirStatool, simple key value database.
*
* AgirStatool is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* AgirStatool is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with AgirStatool. If not, see <http://www.gnu.org/licenses/>.
*/
package org.april.agirstatool.core;
/**
* The Class Stat.
*/
public class Stat
{
int count;
double total;
double min;
double max;
/**
* Instantiates a new stat.
*/
public Stat()
{
this.count = 0;
this.total = 0;
this.min = 0;
this.max = 0;
}
/**
* Adds the value.
*
* @param value
* the value
*/
public void addValue(final double value)
{
if (this.count == 0)
{
this.total = value;
this.min = value;
this.max = value;
}
else
{
//
if (value < this.min)
{
this.min = value;
}
//
this.total += value;
//
if (value > this.max)
{
this.max = value;
}
}
this.count += 1;
}
public int getCount()
{
return this.count;
}
public double getMax()
{
return this.max;
}
/**
* Gets the mean.
*
* @return the mean
*/
public double getMean()
{
double result;
result = this.total / this.count;
//
return result;
}
public double getMin()
{
return this.min;
}
public double getTotal()
{
return this.total;
}
public void setCount(final int count)
{
this.count = count;
}
public void setMax(final double max)
{
this.max = max;
}
public void setMin(final double min)
{
this.min = min;
}
public void setTotal(final double total)
{
this.total = total;
}
}