Class ConcurrentHistogram<T>
- java.lang.Object
-
- com.pervasivecode.utils.stats.histogram.ConcurrentHistogram<T>
-
- Type Parameters:
T
- The type of value counted by this Histogram.
- All Implemented Interfaces:
BucketingSystem<T>
,Histogram<T>
,MutableHistogram<T>
public class ConcurrentHistogram<T> extends Object implements MutableHistogram<T>
A thread-safe Histogram based on theAtomicLongArray
class.- See Also:
BucketingSystem
-
-
Constructor Summary
Constructors Constructor Description ConcurrentHistogram(BucketSelector<T> bucketer)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description T
bucketUpperBound(int index)
Get the upper-bound value of the specified bucket.long
countInBucket(int index)
Get the number of elements that were counted in the specified bucket.void
countValue(T value)
Count the specified value by assigning it to a bucket and incrementing the stored count of values that belong to that bucket.int
numBuckets()
Get the total number of buckets.
-
-
-
Constructor Detail
-
ConcurrentHistogram
public ConcurrentHistogram(BucketSelector<T> bucketer)
-
-
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.
-
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 ofindex
).- Specified by:
bucketUpperBound
in interfaceBucketingSystem<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.
-
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 interfaceHistogram<T>
- Parameters:
index
- The bucket number to examine.- Returns:
- The count of values in the specified bucket.
-
countValue
public void countValue(T value)
Description copied from interface:MutableHistogram
Count the specified value by assigning it to a bucket and incrementing the stored count of values that belong to that bucket.- Specified by:
countValue
in interfaceMutableHistogram<T>
- Parameters:
value
- The value to count. This must not be null.
-
-