bb.science
Class Bins.Intervals

java.lang.Object
  extended by bb.science.Bins.Intervals
Enclosing class:
Bins

public static class Bins.Intervals
extends Object

Specifies how a given set of intervals are laid out.

The left (start) boundary of the leftmost (smallest) interval is given by begin. The right (end) boundary of the rightmost (largest) interval is given by end. In between these bounds, a total of number intervals are present, each approximately of the same size width.

Using the interval boundary convention discussed in the class javadocs, the boundaries are {begin, begin + 1*width, ..., begin + (number - 1)*width}. Written out explicitly, the intervals are


                [begin, begin + 1*width),
                [begin + 1*width, begin + 2*width),
                ...,
                [begin + (number - 1)*width, end]
 
where end == number*width.

This class is multithread safe: it is immutable (both its immediate state, as well as the deep state of its fields).


Field Summary
private  double begin
           
private  double end
           
private  int number
           
private  double width
           
 
Constructor Summary
private Bins.Intervals(double begin, double end, int number)
          Constructor.
 
Method Summary
private  double boundary(int i)
          Returns the ith interval boundary's left value (i.e. the smallest value that is inside the interval).
 boolean equals(Object obj)
          Determines equality based on whether or not obj is an Intervals instance whose every field equals that of this instance.
 double getBegin()
          Accessor for begin.
 double getEnd()
          Accessor for end.
 int getNumber()
          Accessor for number.
 double getWidth()
          Accessor for width.
 int hashCode()
           
private  int index(double d)
          Returns the index of the interval which contains d.
private static Bins.Intervals make(double[] values, double offset, double width)
          Specifies that minimal set of intervals which satisifes these conditions: every element of values is inside one of the intervals every interval in the set has the same size, equal to the width param every interval's boundary points are separated from offset by an integral multiple of width.
private static Bins.Intervals make(double[] values, int number)
          Specifies that set of intervals which satisifes these conditions: every element of values is inside one of the intervals the number of intervals in the set equals the number param the left (starting) boundary of the leftmost (smallest) interval equals the minimum element of values the right (ending) boundary of the rightmost (largest) interval equals the maximum element of values This method finds the min and max elements of values, which it uses for begin and end.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

begin

private final double begin

end

private final double end

number

private final int number

width

private final double width
Constructor Detail

Bins.Intervals

private Bins.Intervals(double begin,
                       double end,
                       int number)
                throws IllegalArgumentException,
                       IllegalStateException
Constructor.

Throws:
IllegalArgumentException - if begin is not normal; end is not normal; begin is not < end; number <= 0
IllegalStateException - if some internal problem occurs
Method Detail

make

private static Bins.Intervals make(double[] values,
                                   double offset,
                                   double width)
                            throws IllegalArgumentException,
                                   IllegalStateException
Specifies that minimal set of intervals which satisifes these conditions:
  1. every element of values is inside one of the intervals
  2. every interval in the set has the same size, equal to the width param
  3. every interval's boundary points are separated from offset by an integral multiple of width. In code: boundaryPoint = offset + (i * width) for some int i.

This method finds the min and max elements of values, which it uses to compute appropriate values for begin and end. Note that offset need not lie inside the intervals (i.e. inside [begin, end]).

This method is useful when you want control over where the interval boundary points fall. A common requirement might be that the boundaries are always integers. In this case, supply offset = 0 and width = 1.

Throws:
IllegalArgumentException - if values == null; values.length == 0; any element of values is NaN; offset is not normal; width is not normal and positive
IllegalStateException - if some internal problem occurs

make

private static Bins.Intervals make(double[] values,
                                   int number)
                            throws IllegalArgumentException,
                                   IllegalStateException
Specifies that set of intervals which satisifes these conditions:
  1. every element of values is inside one of the intervals
  2. the number of intervals in the set equals the number param
  3. the left (starting) boundary of the leftmost (smallest) interval equals the minimum element of values
  4. the right (ending) boundary of the rightmost (largest) interval equals the maximum element of values

This method finds the min and max elements of values, which it uses for begin and end.

Throws:
IllegalArgumentException - if values == null; values.length == 0; any element of values is NaN; number <= 0
IllegalStateException - if some internal problem occurs

getBegin

public double getBegin()
Accessor for begin.


getEnd

public double getEnd()
Accessor for end.


getNumber

public int getNumber()
Accessor for number.


getWidth

public double getWidth()
Accessor for width.


equals

public final boolean equals(Object obj)
Determines equality based on whether or not obj is an Intervals instance whose every field equals that of this instance.

Overrides:
equals in class Object

hashCode

public final int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object

boundary

private double boundary(int i)
                 throws IllegalArgumentException
Returns the ith interval boundary's left value (i.e. the smallest value that is inside the interval).

Contract: the result is >= begin and < end

Throws:
IllegalArgumentException - if i is < 0 or >= number

index

private int index(double d)
           throws IllegalArgumentException
Returns the index of the interval which contains d.

Contract: the result is guaranteed to be >= 0 and < number.

Throws:
IllegalArgumentException - if d is not normal