Code example for ArrayDeque

Methods: addFirstpollLastsize

0
	public void add(double value) {
		if (Double.isNaN(value)) {
			return; 
		} 
 
		if (buffer.size() > sizeLimit) {
			Double last = buffer.pollLast();
			if (last != null) {
				sum -= last;
			} 
		} 
		sum += value;
		buffer.addFirst(value);
	} 
 
	/** 
	 * Get current average 
	 * @return 
	 */ 
	public double getAvg() { 
		return sum / buffer.size();