Example usage for org.jfree.data.statistics HistogramBin HistogramBin

List of usage examples for org.jfree.data.statistics HistogramBin HistogramBin

Introduction

In this page you can find the example usage for org.jfree.data.statistics HistogramBin HistogramBin.

Prototype

public HistogramBin(double startBoundary, double endBoundary) 

Source Link

Document

Creates a new bin.

Usage

From source file:org.jfree.data.statistics.HistogramBinTest.java

/**
 * Confirm that the equals method can distinguish all the required fields.
 */// w w w  .java2  s .c  om
@Test
public void testEquals() {
    double start = 10.0;
    double end = 20.0;
    HistogramBin b1 = new HistogramBin(start, end);
    HistogramBin b2 = new HistogramBin(start, end);
    assertEquals(b1, b2);
}

From source file:org.jfree.data.statistics.HistogramBinTest.java

/**
 * Confirm that cloning works./*  w w w.  j a  va 2  s .c  o m*/
 */
@Test
public void testCloning() throws CloneNotSupportedException {
    double start = 10.0;
    double end = 20.0;
    HistogramBin b1 = new HistogramBin(start, end);
    HistogramBin b2 = (HistogramBin) b1.clone();
    assertTrue(b1 != b2);
    assertTrue(b1.getClass() == b2.getClass());
    assertTrue(b1.equals(b2));
}

From source file:org.jfree.data.statistics.HistogramBinTest.java

/**
 * Serialize an instance, restore it, and check for equality.
 */// w ww. j a v  a2  s  .  c  o m
@Test
public void testSerialization() {
    double start = 10.0;
    double end = 20.0;
    HistogramBin b1 = new HistogramBin(start, end);
    HistogramBin b2 = (HistogramBin) TestUtilities.serialised(b1);
    assertEquals(b1, b2);
}

From source file:org.jfree.data.statistics.HistogramDataset.java

/**
 * Adds a series to the dataset. Any data value less than minimum will be
 * assigned to the first bin, and any data value greater than maximum will
 * be assigned to the last bin.  Values falling on the boundary of
 * adjacent bins will be assigned to the higher indexed bin.
 *
 * @param key  the series key (<code>null</code> not permitted).
 * @param values  the raw observations./*  ww  w .j  ava 2s . c  o  m*/
 * @param bins  the number of bins (must be at least 1).
 * @param minimum  the lower bound of the bin range.
 * @param maximum  the upper bound of the bin range.
 */
public void addSeries(Comparable key, double[] values, int bins, double minimum, double maximum) {

    ParamChecks.nullNotPermitted(key, "key");
    ParamChecks.nullNotPermitted(values, "values");
    if (bins < 1) {
        throw new IllegalArgumentException("The 'bins' value must be at least 1.");
    }
    double binWidth = (maximum - minimum) / bins;

    double lower = minimum;
    double upper;
    List binList = new ArrayList(bins);
    for (int i = 0; i < bins; i++) {
        HistogramBin bin;
        // make sure bins[bins.length]'s upper boundary ends at maximum
        // to avoid the rounding issue. the bins[0] lower boundary is
        // guaranteed start from min
        if (i == bins - 1) {
            bin = new HistogramBin(lower, maximum);
        } else {
            upper = minimum + (i + 1) * binWidth;
            bin = new HistogramBin(lower, upper);
            lower = upper;
        }
        binList.add(bin);
    }
    // fill the bins
    for (int i = 0; i < values.length; i++) {
        int binIndex = bins - 1;
        if (values[i] < maximum) {
            double fraction = (values[i] - minimum) / (maximum - minimum);
            if (fraction < 0.0) {
                fraction = 0.0;
            }
            binIndex = (int) (fraction * bins);
            // rounding could result in binIndex being equal to bins
            // which will cause an IndexOutOfBoundsException - see bug
            // report 1553088
            if (binIndex >= bins) {
                binIndex = bins - 1;
            }
        }
        HistogramBin bin = (HistogramBin) binList.get(binIndex);
        bin.incrementCount();
    }
    // generic map for each series
    Map map = new HashMap();
    map.put("key", key);
    map.put("bins", binList);
    map.put("values.length", new Integer(values.length));
    map.put("bin width", new Double(binWidth));
    this.list.add(map);
    fireDatasetChanged();
}