Class IrregularSetBucketSelector<T>
- java.lang.Object
-
- com.pervasivecode.utils.stats.histogram.IrregularSetBucketSelector<T>
-
- All Implemented Interfaces:
BucketingSystem<T>
,BucketSelector<T>
public class IrregularSetBucketSelector<T> extends Object implements BucketSelector<T>
This BucketSelector counts values in buckets that have an irregular set of bucket upper bound values, such as {1, 5, 7}, that are most easily expressed explicitly, rather than by a formula that generates a series of upper bound values.- See Also:
BucketingSystem
-
-
Constructor Summary
Constructors Constructor Description IrregularSetBucketSelector(SortedSet<T> upperBoundValueSet)
Create a IrregularSetBucketSelector from a set of upper-bound values.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
bucketIndexFor(T value)
Determine the index of the bucket that a specified value should be counted in.T
bucketUpperBound(int bucketIndex)
Get the upper-bound value of the specified bucket.int
numBuckets()
Get the total number of buckets.
-
-
-
Method Detail
-
numBuckets
public int numBuckets()
Description copied from interface:BucketingSystem
Get the total number of buckets. This will not be smaller than 1.- Specified by:
numBuckets
in interfaceBucketingSystem<T>
- Returns:
- The number of buckets.
-
bucketIndexFor
public int bucketIndexFor(T value)
Description copied from interface:BucketSelector
Determine the index of the bucket that a specified value should be counted in.- Specified by:
bucketIndexFor
in interfaceBucketSelector<T>
- Parameters:
value
- The value to compare to bucket upper bounds values when identifying the appropriate bucket.- Returns:
- The bucket index for the specified value.
-
bucketUpperBound
public T bucketUpperBound(int bucketIndex)
Description copied from interface:BucketingSystem
Get the upper-bound value of the specified bucket.The first bucket has an index of 0. The last bucket has no upper bound, so passing the last index value in
index
is not allowed and will result in an IllegalArgumentException being thrown. In other words, if there are 10 buckets in a given instance, there are only 9 upper bound values, so the valid index values are 0 through 8 inclusive.A BucketingSystem with only one bucket is valid (all values fall in that bucket), but would have no upper bound values, so this method would always throw an IllegalArgumentException (for
index
value 0) or an IndexOutOfBoundsException (for all other values ofindex
).- Specified by:
bucketUpperBound
in interfaceBucketingSystem<T>
- Parameters:
bucketIndex
- The bucket index to examine. This must be a value from zero through the next-to-last bucket index.- Returns:
- The upper bound value of the specified bucket. This will not be null.
-
-