/** * Returns the index of the item with the specified x-value, or a negative * index if the series does not contain an item with that x-value. Be * aware that for an unsorted series, the index is found by iterating * through all items in the series. * * @param x the x-value ({@code null} not permitted). * * @return The index. */ public int indexOf(Comparable x) { if (this.autoSort) { return Collections.binarySearch(this.data, new ComparableObjectItem( x, null)); } else { for (int i = 0; i < this.data.size(); i++) { ComparableObjectItem item = (ComparableObjectItem) this.data.get(i); if (item.getComparable().equals(x)) { return i; } } return -1; } }
/** * Updates the value of an item in the series and sends a * {@link SeriesChangeEvent} to all registered listeners. * * @param index the item (zero based index). * @param y the new value ({@code null} permitted). */ protected void updateByIndex(int index, Object y) { ComparableObjectItem item = getDataItem(index); item.setObject(y); fireSeriesChanged(); }
&& item.compareTo(this.data.get(index)) == 0) { index++; int index = indexOf(item.getComparable()); if (index >= 0) { throw new SeriesException("X-value already exists.");
/** * Adds new data to the series and, if requested, sends a * {@link SeriesChangeEvent} to all registered listeners. * <P> * Throws an exception if the x-value is a duplicate AND the * allowDuplicateXValues flag is false. * * @param x the x-value ({@code null} not permitted). * @param y the y-value ({@code null} permitted). * @param notify a flag the controls whether or not a * {@link SeriesChangeEvent} is sent to all registered * listeners. */ protected void add(Comparable x, Object y, boolean notify) { // delegate argument checking to XYDataItem... ComparableObjectItem item = new ComparableObjectItem(x, y); add(item, notify); }
/** * Returns a hash code. * * @return A hash code. */ @Override public int hashCode() { int result = super.hashCode(); // it is too slow to look at every data item, so let's just look at // the first, middle and last items... int count = getItemCount(); if (count > 0) { ComparableObjectItem item = getDataItem(0); result = 29 * result + item.hashCode(); } if (count > 1) { ComparableObjectItem item = getDataItem(count - 1); result = 29 * result + item.hashCode(); } if (count > 2) { ComparableObjectItem item = getDataItem(count / 2); result = 29 * result + item.hashCode(); } result = 29 * result + this.maximumItemCount; result = 29 * result + (this.autoSort ? 1 : 0); result = 29 * result + (this.allowDuplicateXValues ? 1 : 0); return result; }
&& item.compareTo(this.data.get(index)) == 0) { index++; int index = indexOf(item.getComparable()); if (index >= 0) { throw new SeriesException("X-value already exists.");
/** * Adds new data to the series and, if requested, sends a * {@link SeriesChangeEvent} to all registered listeners. * <P> * Throws an exception if the x-value is a duplicate AND the * allowDuplicateXValues flag is false. * * @param x the x-value (<code>null</code> not permitted). * @param y the y-value (<code>null</code> permitted). * @param notify a flag the controls whether or not a * {@link SeriesChangeEvent} is sent to all registered * listeners. */ protected void add(Comparable x, Object y, boolean notify) { // delegate argument checking to XYDataItem... ComparableObjectItem item = new ComparableObjectItem(x, y); add(item, notify); }
/** * Returns a hash code. * * @return A hash code. */ public int hashCode() { int result = super.hashCode(); // it is too slow to look at every data item, so let's just look at // the first, middle and last items... int count = getItemCount(); if (count > 0) { ComparableObjectItem item = getDataItem(0); result = 29 * result + item.hashCode(); } if (count > 1) { ComparableObjectItem item = getDataItem(count - 1); result = 29 * result + item.hashCode(); } if (count > 2) { ComparableObjectItem item = getDataItem(count / 2); result = 29 * result + item.hashCode(); } result = 29 * result + this.maximumItemCount; result = 29 * result + (this.autoSort ? 1 : 0); result = 29 * result + (this.allowDuplicateXValues ? 1 : 0); return result; }
/** * Returns the index of the item with the specified x-value, or a negative * index if the series does not contain an item with that x-value. Be * aware that for an unsorted series, the index is found by iterating * through all items in the series. * * @param x the x-value (<code>null</code> not permitted). * * @return The index. */ public int indexOf(Comparable x) { if (this.autoSort) { return Collections.binarySearch(this.data, new ComparableObjectItem( x, null)); } else { for (int i = 0; i < this.data.size(); i++) { ComparableObjectItem item = (ComparableObjectItem) this.data.get(i); if (item.getComparable().equals(x)) { return i; } } return -1; } }
/** * Updates the value of an item in the series and sends a * {@link SeriesChangeEvent} to all registered listeners. * * @param index the item (zero based index). * @param y the new value (<code>null</code> permitted). */ protected void updateByIndex(int index, Object y) { ComparableObjectItem item = getDataItem(index); item.setObject(y); fireSeriesChanged(); }
/** * Updates an item in the series. * * @param x the x-value ({@code null} not permitted). * @param y the y-value ({@code null} permitted). * * @throws SeriesException if there is no existing item with the specified * x-value. */ protected void update(Comparable x, Object y) { int index = indexOf(x); if (index < 0) { throw new SeriesException("No observation for x = " + x); } else { ComparableObjectItem item = getDataItem(index); item.setObject(y); fireSeriesChanged(); } }
/** * Updates an item in the series. * * @param x the x-value (<code>null</code> not permitted). * @param y the y-value (<code>null</code> permitted). * * @throws SeriesException if there is no existing item with the specified * x-value. */ protected void update(Comparable x, Object y) { int index = indexOf(x); if (index < 0) { throw new SeriesException("No observation for x = " + x); } else { ComparableObjectItem item = getDataItem(index); item.setObject(y); fireSeriesChanged(); } }