|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--cosmic.util.SequenceAverager
A class for efficiently averaging over a set number of the most recent values in a continuous sequence. Author: James.A.Marshall@imperial.ac.uk
Field Summary | |
private java.util.LinkedList |
mAverageSequence
The sequence to be averaged over |
private int |
mAverageSequenceLength
The length of the sequence over which averages should be calculated |
private int |
mFullSequenceLength
The length of the full sequence |
private double |
mFullSequenceTotal
The total of the full sequence |
private double |
mLastCalculatedTotal
The total calculated before averaging when getAverage() was last called |
private int |
mNumValuesAddedSinceLastGetAverage
The number of values added since the last time getAverage() was called |
private java.util.LinkedList |
mSequenceHistory
The history of the sequence prior to the sequence currently being averaged over |
Constructor Summary | |
SequenceAverager(int sequenceLength)
SequenceAverager constructor |
Method Summary | |
void |
addToSequence(double value)
Adds a value to the sequence |
void |
addToSequence(int value)
Adds a value to the sequence |
double |
getAverage()
Efficiently gets the average over the specified last number of values (If the sequence is not long enough the average over the entire available sequence is returned) |
double |
getAverageOverSequence(int sequenceStart,
int sequenceEnd)
Gets the average over the specified sequence (this method involves iteration over the entire list and is consequently inefficient) |
double |
getEntireSequenceAverage()
Efficiently gets the average over the entire sequence |
int |
getEntireSequenceLength()
Gets the length of the entire sequence |
double |
getEntireSequenceTotal()
Gets the total of the entire sequence |
int |
getSequenceLength()
Gets the length of the sequence |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private double mFullSequenceTotal
private int mFullSequenceLength
private java.util.LinkedList mAverageSequence
private int mAverageSequenceLength
private java.util.LinkedList mSequenceHistory
private int mNumValuesAddedSinceLastGetAverage
private double mLastCalculatedTotal
Constructor Detail |
public SequenceAverager(int sequenceLength)
Method Detail |
public void addToSequence(int value)
public void addToSequence(double value)
public double getAverage()
public double getEntireSequenceAverage()
public double getAverageOverSequence(int sequenceStart, int sequenceEnd)
sequenceStart
- (0 <= sequenceStart <= sequenceEnd)sequenceEnd
- (sequenceStart <= sequenceEnd < getSequenceLength())
public int getEntireSequenceLength()
public double getEntireSequenceTotal()
public int getSequenceLength()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |