Example usage for org.jfree.data.statistics SimpleHistogramBin overlapsWith

List of usage examples for org.jfree.data.statistics SimpleHistogramBin overlapsWith

Introduction

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

Prototype

public boolean overlapsWith(SimpleHistogramBin bin) 

Source Link

Document

Returns true if this bin overlaps with the specified bin, and false otherwise.

Usage

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

/**
 * Some checks for the overlapsWith() method.
 *//*from  w w w  .j av  a2 s.c  o m*/
@Test
public void testOverlapsWidth() {
    SimpleHistogramBin b1 = new SimpleHistogramBin(1.0, 2.0);
    SimpleHistogramBin b2 = new SimpleHistogramBin(2.0, 3.0);
    SimpleHistogramBin b3 = new SimpleHistogramBin(3.0, 4.0);
    SimpleHistogramBin b4 = new SimpleHistogramBin(0.0, 5.0);
    SimpleHistogramBin b5 = new SimpleHistogramBin(2.0, 3.0, false, true);
    SimpleHistogramBin b6 = new SimpleHistogramBin(2.0, 3.0, true, false);
    assertTrue(b1.overlapsWith(b2));
    assertTrue(b2.overlapsWith(b1));
    assertFalse(b1.overlapsWith(b3));
    assertFalse(b3.overlapsWith(b1));
    assertTrue(b1.overlapsWith(b4));
    assertTrue(b4.overlapsWith(b1));
    assertFalse(b1.overlapsWith(b5));
    assertFalse(b5.overlapsWith(b1));
    assertTrue(b1.overlapsWith(b6));
    assertTrue(b6.overlapsWith(b1));
}

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

/**
 * Adds a bin to the dataset.  An exception is thrown if the bin overlaps
 * with any existing bin in the dataset.
 *
 * @param bin  the bin (<code>null</code> not permitted).
 *
 * @see #removeAllBins()//from  w w w. ja  v  a2  s  .  c o m
 */
public void addBin(SimpleHistogramBin bin) {
    // check that the new bin doesn't overlap with any existing bin
    Iterator iterator = this.bins.iterator();
    while (iterator.hasNext()) {
        SimpleHistogramBin existingBin = (SimpleHistogramBin) iterator.next();
        if (bin.overlapsWith(existingBin)) {
            throw new RuntimeException("Overlapping bin");
        }
    }
    this.bins.add(bin);
    Collections.sort(this.bins);
}