Class ImmutableHistogram<T>

  • Type Parameters:
    T - The type of value counted by this Histogram.
    All Implemented Interfaces:
    BucketingSystem<T>, Histogram<T>

    public abstract class ImmutableHistogram<T>
    extends Object
    implements Histogram<T>
    An immutable representation of a Histogram.
    See Also:
    BucketingSystem
    • Constructor Detail

      • ImmutableHistogram

        public ImmutableHistogram()
    • 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.
      • countInBucket

        public long countInBucket​(int index)
        Description copied from interface: Histogram
        Get the number of elements that were counted in the specified bucket. The first bucket has an index of 0.
        Specified by:
        countInBucket in interface Histogram<T>
        Parameters:
        index - The bucket number to examine.
        Returns:
        The count of values in the specified bucket.
      • bucketUpperBound

        public T bucketUpperBound​(int index)
        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:
        index - 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.
      • builder

        public static <V> ImmutableHistogram.Builder<V> builder()
        Obtain a builder that allows construction of a new instance.
        Type Parameters:
        V - The type of value counted by this Histogram.
        Returns:
        A new, empty Builder instance.
      • copyOf

        public static <V> ImmutableHistogram<V> copyOf​(Histogram<V> histogram)
        Make an immutable copy of another histogram with the same value type, size, bucket upper bounds and value counts.
        Type Parameters:
        V - The type of value counted by this Histogram.
        Parameters:
        histogram - The histogram to copy.
        Returns:
        An immutable copy of the histogram passed to this method.