Class Histogram<B extends Comparable<B>>
- Type Parameters:
B- Type of the bins within the histogram.
Bins act as intervals or “buckets” for categorizing values. Bins can
be of any type, but must implement the Comparable interface,
which is used to determine the order of the bins within the histogram.
It is possible to add bins with a frequency of zero, for cases where
the histogram needs to depict the entire range of bins.
Series can be used to provide more information on different categories of data that contribute towards the overall frequency within each bin. Series are purely descriptive text label, and are therefore always of type string. Also unlike bins, series do not have an explicit order, with series being sorted based on their overall frequency within the data set.
The following example shows a histogram with multiple bins and multiple series, presented in glorious ASCII art:
[2] [1] [2] [1] [1] [1] ------------------------------- 0-10 11-20 21-30 31-40
This class is not thread-safe, Histogram instances should therefore
not be used concurrently from multiple threads.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds the specified frequency to this histogram.voidAdds the specified frequency to this histogram.getBinFrequency(B bin) Returns a map containing all series and corresponding frequency that exist in the specified bin.getBins()Returns a list of all bins in this histogram.intgetBinTotal(B bin) Returns the total frequency for the specified bin, combining the frequencies of all series that are included in that bin.intgetFrequency(B bin, String series) Returns the frequency count for the specified bin and series.Returns a list of all series in this histogram.getSeriesFrequency(String series) Returns a list of tuples for all bins in this histogram, with each tuple consisting of the bin and the corresponding frequency for the specified series.Returns a map containing the total frequency for all series in this histogram, but normalized to percentages instead of the absolute numbers.intgetSeriesTotal(String series) Returns the total frequency for the specified series, combining all bins in which the series might exist.Returns map containing the total frequency for all series in this histogram.intgetTotal()Returns the combined total frequency of all data in this histogram.voidAdds all data from the specified other histogram to this histogram.
-
Constructor Details
-
Histogram
public Histogram()Creates a new histogram that is initially empty. Bins will be added on-the-fly as data is added to the histogram. -
Histogram
-
-
Method Details
-
count
-
count
Adds the specified frequency to this histogram. The requested bin and/or series are added to this histogram if they do not yet exist.- Throws:
IllegalArgumentException- when trying to add a negative frequency. Note that adding zero is in fact allowed, this will add the bin if it does not exist yet without adding a frequency to the bin.
-
merge
-
getBins
Returns a list of all bins in this histogram. The bins are sorted based on their natural order, i.e. based on theComparableinterface. -
getSeries
-
getFrequency
-
getBinFrequency
-
getSeriesFrequency
-
getBinTotal
Returns the total frequency for the specified bin, combining the frequencies of all series that are included in that bin. Returns zero if no such bin exists in this histogram. -
getSeriesTotal
Returns the total frequency for the specified series, combining all bins in which the series might exist. Returns zero if no such series exists in this histogram. -
getSeriesTotals
Returns map containing the total frequency for all series in this histogram. The iteration order of the map will matchgetSeries(). -
getSeriesPercentages
Returns a map containing the total frequency for all series in this histogram, but normalized to percentages instead of the absolute numbers. The iteration order of the map will matchgetSeries(). UsegetSeriesTotals()if you need the absolute numbers. -
getTotal
public int getTotal()Returns the combined total frequency of all data in this histogram. This number will match both the sum of all bins and the sum of all series.
-