Class 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 Detail

      • IrregularSetBucketSelector

        public IrregularSetBucketSelector​(SortedSet<T> upperBoundValueSet)
        Create a IrregularSetBucketSelector from a set of upper-bound values.
        Parameters:
        upperBoundValueSet - The upper bound values for the buckets. (There will also be one more bucket that has no upper bound.)
    • 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 interface BucketingSystem<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 interface BucketSelector<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 of index).

        Specified by:
        bucketUpperBound in interface BucketingSystem<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.