/** * Returns the y-value (as a double primitive) for an item within a series. * * @param series the series index (zero-based). * @param item the item index (zero-based). * @return The y-value. * @see #getAdjustForBinSize() */ public double getYValue(int series, int item) { SimpleHistogramBin bin = (SimpleHistogramBin) this.bins.get(item); if (this.adjustForBinSize) { return bin.getItemCount() / (bin.getUpperBound() - bin.getLowerBound()); } else { return bin.getItemCount(); } }
/** * Removes all current observation data and sends a {@link DatasetChangeEvent} to all registered * listeners. * * @since 1.0.6 * @see #addObservations(double[]) * @see #removeAllBins() */ public void clearObservations() { Iterator iterator = this.bins.iterator(); while (iterator.hasNext()) { SimpleHistogramBin bin = (SimpleHistogramBin) iterator.next(); bin.setItemCount(0); } notifyListeners(new DatasetChangeEvent(this, this)); }
/** * Adds an observation to the dataset (by incrementing the item count for the appropriate bin). A * runtime exception is thrown if the value does not fit into any bin. * * @param value the value. * @param notify send {@link DatasetChangeEvent} to listeners? */ public void addObservation(double value, boolean notify) { boolean placed = false; Iterator iterator = this.bins.iterator(); while (iterator.hasNext() && !placed) { SimpleHistogramBin bin = (SimpleHistogramBin) iterator.next(); if (bin.accepts(value)) { bin.setItemCount(bin.getItemCount() + 1); placed = true; } } if (!placed) { throw new RuntimeException("No bin."); } if (notify) { notifyListeners(new DatasetChangeEvent(this, this)); } }
/** * 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() */ 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); }
/** * Returns the end x-value (as a double primitive) for an item within a series. * * @param series the series index (zero-based). * @param item the item index (zero-based). * @return The end x-value. */ public double getEndXValue(int series, int item) { SimpleHistogramBin bin = (SimpleHistogramBin) this.bins.get(item); return bin.getUpperBound(); }
/** * Returns the x-value (as a double primitive) for an item within a series. * * @param series the series index (zero-based). * @param item the item index (zero-based). * @return The x-value. */ public double getXValue(int series, int item) { SimpleHistogramBin bin = (SimpleHistogramBin) this.bins.get(item); return (bin.getLowerBound() + bin.getUpperBound()) / 2.0; }