LimeWire Collection Component API

org.limewire.collection
Class NumericBuffer<T extends Number>

java.lang.Object
  extended by org.limewire.collection.Buffer<T>
      extended by 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


Field Summary
 
Fields inherited from class org.limewire.collection.Buffer
buf
 
Constructor Summary
NumericBuffer(Buffer<? extends T> other)
           
NumericBuffer(int size)
           
 
Method Summary
 Number average()
           
protected  T[] createArray(int size)
           
 Number sum()
           
 
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
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NumericBuffer

public NumericBuffer(int size)

NumericBuffer

public NumericBuffer(Buffer<? extends T> other)
Method Detail

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.

LimeWire Collection Component API

Copyright © 2008 Lime Wire LLC. All Rights Reserved.