suramadu.util.stats
Class HistogramBin

java.lang.Object
  extended bysuramadu.util.stats.HistogramBin
All Implemented Interfaces:
java.lang.Comparable, Range

public class HistogramBin
extends java.lang.Object
implements java.lang.Comparable, Range

This class represents a single bin in a histogram. It contains the complete definition of the criteria for being a member of this bin. By calling this classes isMember() method, it can be immediately determined whether a particular value is a member of this bin.

Author:
mbi
See Also:
Range

Constructor Summary
HistogramBin(java.lang.Comparable loBound, java.lang.Comparable hiBound)
          Creates a new instance of HistogramBin with the specified low and high bounds.
 
Method Summary
 boolean add(java.lang.Number n)
          Adds the specified Number object to this range if it truly falls within it.
 int compareTo(java.lang.Object o)
          Comparaable Interface Implementation
 boolean contains(java.lang.Number n)
          Determines if a given number falls within the Range described by this HistogramBin.
 long getCount()
          Gets the current count for this HistogramBin.
 java.lang.Comparable getHiBound()
          Gets the high bound of the Range described by this HistogramBin.
 java.lang.Comparable getLoBound()
          Gets the low bound of the Range described by this HistorgramBin
 Range merge(Range range)
          A helper method that will merge this HistogramBin with another HistogramBin iff the ranges are adjescent.
 boolean overlaps(HistogramBin bin)
          Determines if the specified HistogramBin overlaps this HistogramBin.
 java.lang.String toString()
          Creates a String representation fo this HistogramBin indicating its low bound, high bound, and current counter.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HistogramBin

public HistogramBin(java.lang.Comparable loBound,
                    java.lang.Comparable hiBound)
Creates a new instance of HistogramBin with the specified low and high bounds. This constructor enforces that the loBond < hiBound.

Parameters:
loBound - The low bound of the range represented by this HistogramBin. This is the value that is less than or equal to all values that are enclosed by this range.
hiBound - The high bound of the range represented by this HistogramBin. This is the value that is grater than all values that are enclosed by this range.
See Also:
Range
Method Detail

add

public boolean add(java.lang.Number n)
Adds the specified Number object to this range if it truly falls within it. If added, the HistogramBin's counter is incremented.

Parameters:
n - the Number object to add
Returns:
true if added and the count incremented, false if the Number object is not in the HistogramBin's range.

getLoBound

public java.lang.Comparable getLoBound()
Gets the low bound of the Range described by this HistorgramBin

Specified by:
getLoBound in interface Range
Returns:
he low bound of the range represented by this HistogramBin. This is the value that is less than or equal to all values that are enclosed by this range.

getHiBound

public java.lang.Comparable getHiBound()
Gets the high bound of the Range described by this HistogramBin.

Specified by:
getHiBound in interface Range
Returns:
The high bound of the range represented by this HistogramBin. This is the value that is grater than all values that are enclosed by this range.

merge

public Range merge(Range range)
A helper method that will merge this HistogramBin with another HistogramBin iff the ranges are adjescent.

Specified by:
merge in interface Range
Parameters:
range - the Range object to merge with this range.
Returns:
a new Object that implements the Range interface which encompasses both the current Range, and the specified Range. If the two ranges are not adjascent, then <null> is returned.
See Also:
Range

getCount

public long getCount()
Gets the current count for this HistogramBin.

Specified by:
getCount in interface Range
Returns:
The courrent count for this HistogramBin.
See Also:
Range.getHiBound(), Range.getLoBound()

contains

public boolean contains(java.lang.Number n)
Determines if a given number falls within the Range described by this HistogramBin. Falling within range is defined as being greater than or equal to the low bound of the range, and less than the high bound of the range. The only exception is in the special case where the low bound is equal to the high bound, and the test number is equal to both of them.

Parameters:
n - The Number object to test for inclusion in this HistogramBin's Range.
Returns:
true if it is within this HistogramBin's range, false if not.
See Also:
Range

overlaps

public boolean overlaps(HistogramBin bin)
Determines if the specified HistogramBin overlaps this HistogramBin.

Parameters:
bin - The HistogramBin to test.
Returns:
true if the specified HistogramBin overlaps, false if not.
See Also:
HistogramBin

compareTo

public int compareTo(java.lang.Object o)
Comparaable Interface Implementation

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
o - The Object that we will be comparing.
Returns:
see java.lang.Comparable
See Also:
Comparable

toString

public java.lang.String toString()
Creates a String representation fo this HistogramBin indicating its low bound, high bound, and current counter.

Returns:
a String representation fo this HistogramBin indicating its low bound, high bound, and current counter.