bb.science
Class Samples

java.lang.Object
  extended by bb.science.Samples

public class Samples
extends Object

Simply stores double values via the add method. Typically, these are samples from some sort of measurement.

No restriction is placed on the values stored except this: add only accepts normal (non-NaN and non-infinite) doubles. This restriction means that the result returned by values may be safely supplied to other classes (e.g. the statistical routines inside Math2).

This class is not multithread safe.

Author:
Brent Boyer
See Also:
StatsOverTime

Nested Class Summary
static class Samples.UnitTest
          See the Overview page of the project's javadocs for a general description of this unit test class.
 
Field Summary
private static int integerMaxDiv2
           
private  int n
          Stores the number of data values recorded by this instance.
private static int sizeInitial_default
          Specifies the default value for the initial size of the values buffer.
private  double[] values
          Buffer which holds the data values.
 
Constructor Summary
Samples()
          Constructor which allocates an initial buffer with size sizeInitial_default.
Samples(int sizeInitial)
          Constructor which allocates an initial buffer with size specified by sizeInitial.
 
Method Summary
 void add(double d)
          Adds d to the internal array which stores all the values.
private  void increaseBuffer()
          Increases the capacity of the values buffer.
 int size()
          Returns the number of values that have been added to this instance.
 double[] values()
          Returns a new array which holds all the values that have been added to this instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sizeInitial_default

private static final int sizeInitial_default
Specifies the default value for the initial size of the values buffer.

See Also:
Constant Field Values

integerMaxDiv2

private static final int integerMaxDiv2
See Also:
Constant Field Values

values

private double[] values
Buffer which holds the data values.


n

private int n
Stores the number of data values recorded by this instance. Hence, n - 1 is the last valid index of values.

Constructor Detail

Samples

public Samples()
Constructor which allocates an initial buffer with size sizeInitial_default.


Samples

public Samples(int sizeInitial)
        throws IllegalArgumentException
Constructor which allocates an initial buffer with size specified by sizeInitial.

Throws:
IllegalArgumentException - if sizeInitial <= 0
Method Detail

add

public void add(double d)
         throws IllegalArgumentException,
                IllegalStateException
Adds d to the internal array which stores all the values. This array will be resized if necessary in order to hold d.

Throws:
IllegalArgumentException - if d is not normal;
IllegalStateException - if the buffer's length = Integer.MAX_VALUE

increaseBuffer

private void increaseBuffer()
                     throws IllegalStateException
Increases the capacity of the values buffer. The current implementation doubles the capacity (within an upper bound of Integer.MAX_VALUE).

Throws:
IllegalStateException - if the buffer's length = Integer.MAX_VALUE

size

public int size()
Returns the number of values that have been added to this instance.


values

public double[] values()
Returns a new array which holds all the values that have been added to this instance.

The implementation here returns an array which has the values in the order that they were added.

Contract: the result is never null, but will be zero-length if no values have ever been added.