
eu.hansolo.steelseries.tools.Histogram Maven / Gradle / Ivy
package eu.hansolo.steelseries.tools;
/**
* @author Gerrit Grunwald
*/
public class Histogram
{
private final double MIN_VALUE; // the minimum value of the gauge dial
private final double MAX_VALUE; // the maximum value of the gauge dial
private final double MINOR_TICKMARK_SPACING; // the distance between two minor tickmarks
private final double[] FREQUENCE; // frequence[i] = # occurences of value i
private double max; // max frequency of any value
// Create a new histogram.
public Histogram(final double MIN_VALUE, final double MAX_VALUE, final double MINOR_TICKMARK_SPACING)
{
this.MIN_VALUE = MIN_VALUE;
this.MAX_VALUE = MAX_VALUE;
this.MINOR_TICKMARK_SPACING = MINOR_TICKMARK_SPACING;
final int N = (int) ((MAX_VALUE - MIN_VALUE) / MINOR_TICKMARK_SPACING);
FREQUENCE = new double[N];
}
// Add one occurrence of the value i.
public void addDataPoint(final int INDEX)
{
FREQUENCE[INDEX]++;
max = FREQUENCE[INDEX] > max ? FREQUENCE[INDEX] : max;
}
public void addDataPoint(final double VALUE)
{
addDataPoint((int) (VALUE / MINOR_TICKMARK_SPACING) - (int) (MIN_VALUE / MINOR_TICKMARK_SPACING));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy