org.limewire.collection
Class NumericBuffer<T extends Number>
java.lang.Object
org.limewire.collection.Buffer<T>
org.limewire.collection.NumericBuffer<T>
- All Implemented Interfaces:
- Cloneable, Iterable<T>
public class NumericBuffer<T extends Number>
- extends Buffer<T>
Provides a circular buffer for Numbers. Includes a summation
and average (arithmetic mean) of the elements in the buffer.
NumericBuffer<Float> nb = new NumericBuffer<Float>(10);
nb.add(1f);
nb.add(2f);
nb.add(3f);
nb.add(4f);
System.out.println(nb);
System.out.println("Arithmetic mean (average) is: " + nb.average());
System.out.println("Sum is: " + nb.sum());
Output:
[4.0, 3.0, 2.0, 1.0]
Arithmetic mean (average) is: 2.5
Sum is: 10.0
| Fields inherited from class org.limewire.collection.Buffer |
buf |
| Methods inherited from class org.limewire.collection.Buffer |
add, addFirst, addLast, clear, clone, contains, first, get, getCapacity, getSize, initialize, isEmpty, isFull, iterator, last, remove, remove, removeAll, removeFirst, removeLast, set, size, toString |
NumericBuffer
public NumericBuffer(int size)
NumericBuffer
public NumericBuffer(Buffer<? extends T> other)
createArray
protected T[] createArray(int size)
- Overrides:
createArray in class Buffer<T extends Number>
average
public Number average()
- Returns:
- the average (arithmetic mean) of the elements in this buffer
with the best accuracy possible - double if the elements are float or
double and long otherwise.
sum
public Number sum()
- Returns:
- the sum of the elements in this buffer with the
best accuracy possible - double if the elements are float or double
and long otherwise.
Copyright © 2008 Lime Wire LLC. All Rights Reserved.