LimeWire collection component api

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

java.lang.Object
  extended by org.limewire.collection.Buffer<T>
      extended by org.limewire.collection.NumericBuffer<T>
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Iterable<T>

public class NumericBuffer<T extends java.lang.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
 java.lang.Number average()
           
protected  T[] createArray(int size)
           
 java.lang.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 java.lang.Number>

average

public java.lang.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 java.lang.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 © 2009 Lime Wire LLC. All Rights Reserved.