Package com.biglybt.core.util
Class Average
- java.lang.Object
-
- com.biglybt.core.util.Average
-
- Direct Known Subclasses:
PausableAverage
public class Average extends java.lang.Object
This class is used to compute average (mostly for speed transfer).
-
-
Field Summary
Fields Modifier and Type Field Description private long
lastUpdate
private int
nbElements
private int
period
private int
refreshRate
It uses a simple array of longs to store values in a cycling way.private long[]
values
-
Constructor Summary
Constructors Modifier Constructor Description protected
Average(int _refreshRate, int _period)
Private constructor for an Average
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addValue(long value)
Public method to add a value to the average, the time it is added is the time this method is called.void
clear()
void
cloneFrom(Average other)
long
getAverage()
This method can be called to get the current average value.long
getAverage(int average_period)
private java.lang.Object[]
getCloneDetails()
double
getDoubleAverage()
java.lang.String
getDoubleAverageAsString(int precision)
protected long
getEffectiveTime()
static Average
getInstance(int refreshRate, int period)
The way to get a new Average Object, it does some parameter checking.long
getPointValue()
long
getSum()
protected long
getSum(int slots)
private void
update(long timeFactor)
This method is used to update the buffer tha stores the values, in fact it mostly does clean-up over this buffer, erasing all values that have not been updated.
-
-
-
Field Detail
-
refreshRate
private final int refreshRate
It uses a simple array of longs to store values in a cycling way. The array has 2 more elements than really needed to compute the average. One is the next one to be filled, and its value is always 0, and the other one is the one currently filled, which value is not taken into account for the average.
-
period
private final int period
-
nbElements
private final int nbElements
-
lastUpdate
private long lastUpdate
-
values
private long[] values
-
-
Method Detail
-
getInstance
public static Average getInstance(int refreshRate, int period)
The way to get a new Average Object, it does some parameter checking. refreshRate must be greater than 100, and period*1000 must be greater than refreshRate- Parameters:
refreshRate
- in msperiod
- in s- Returns:
- the newlly created Average, or null if parameters are wrong
-
clear
public void clear()
-
cloneFrom
public void cloneFrom(Average other)
-
getCloneDetails
private java.lang.Object[] getCloneDetails()
-
update
private void update(long timeFactor)
This method is used to update the buffer tha stores the values, in fact it mostly does clean-up over this buffer, erasing all values that have not been updated.- Parameters:
timeFactor
- which is the currentTime divided by the refresh Rate
-
addValue
public void addValue(long value)
Public method to add a value to the average, the time it is added is the time this method is called.- Parameters:
value
- the value to be added to the Average
-
getAverage
public long getAverage()
This method can be called to get the current average value.- Returns:
- the current Average computed.
-
getDoubleAverage
public double getDoubleAverage()
-
getDoubleAverageAsString
public java.lang.String getDoubleAverageAsString(int precision)
-
getAverage
public long getAverage(int average_period)
-
getPointValue
public long getPointValue()
-
getSum
public final long getSum()
-
getSum
protected final long getSum(int slots)
-
getEffectiveTime
protected long getEffectiveTime()
-
-