cosmic.util
Class SequenceAverager

java.lang.Object
  |
  +--cosmic.util.SequenceAverager

public class SequenceAverager
extends java.lang.Object

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

mFullSequenceTotal

private double mFullSequenceTotal
The total of the full sequence


mFullSequenceLength

private int mFullSequenceLength
The length of the full sequence


mAverageSequence

private java.util.LinkedList mAverageSequence
The sequence to be averaged over


mAverageSequenceLength

private int mAverageSequenceLength
The length of the sequence over which averages should be calculated


mSequenceHistory

private java.util.LinkedList mSequenceHistory
The history of the sequence prior to the sequence currently being averaged over


mNumValuesAddedSinceLastGetAverage

private int mNumValuesAddedSinceLastGetAverage
The number of values added since the last time getAverage() was called


mLastCalculatedTotal

private double mLastCalculatedTotal
The total calculated before averaging when getAverage() was last called

Constructor Detail

SequenceAverager

public SequenceAverager(int sequenceLength)
SequenceAverager constructor

Method Detail

addToSequence

public void addToSequence(int value)
Adds a value to the sequence

Returns:
void

addToSequence

public void addToSequence(double value)
Adds a value to the sequence

Returns:
void

getAverage

public 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)

Returns:
Average over set sequence

getEntireSequenceAverage

public double getEntireSequenceAverage()
Efficiently gets the average over the entire sequence

Returns:
The average over the entire sequence

getAverageOverSequence

public 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)

Parameters:
sequenceStart - (0 <= sequenceStart <= sequenceEnd)
sequenceEnd - (sequenceStart <= sequenceEnd < getSequenceLength())
Returns:
Average over specified sequence

getEntireSequenceLength

public int getEntireSequenceLength()
Gets the length of the entire sequence

Returns:
Length of the entire sequence

getEntireSequenceTotal

public double getEntireSequenceTotal()
Gets the total of the entire sequence

Returns:
Total of the entire sequence

getSequenceLength

public int getSequenceLength()
Gets the length of the sequence

Returns:
Sequence length