Example usage for org.jfree.data.general SeriesException SeriesException

List of usage examples for org.jfree.data.general SeriesException SeriesException

Introduction

In this page you can find the example usage for org.jfree.data.general SeriesException SeriesException.

Prototype

public SeriesException(String message) 

Source Link

Document

Constructs a new series exception.

Usage

From source file:org.jfree.data.xy.XYSeries.java

/**
 * Adds or updates an item in the series and sends a
 * {@link SeriesChangeEvent} to all registered listeners.
 *
 * @param x  the x-value (<code>null</code> not permitted).
 * @param y  the y-value (<code>null</code> permitted).
 *
 * @return A copy of the overwritten data item, or
 *         <code>null</code> if noitem was overwritten.
 *//*from   ww w .  j  a  v a 2s .  co m*/
public XYDataItem addOrUpdate(Number x, Number y) {
    if (x == null) {
        throw new IllegalArgumentException("Null 'x' argument.");
    }
    if (this.allowDuplicateXValues) {
        add(x, y);
        return null;
    }

    // if we get to here, we know that duplicate X values are not permitted
    XYDataItem overwritten = null;
    int index = indexOf(x);
    if (index >= 0) {
        XYDataItem existing = (XYDataItem) this.data.get(index);
        try {
            overwritten = (XYDataItem) existing.clone();
        } catch (CloneNotSupportedException e) {
            throw new SeriesException("Couldn't clone XYDataItem!");
        }
        existing.setY(y);
    } else {

        // if the series is sorted, the negative index is a result from
        // Collections.binarySearch() and tells us where to insert the
        // new item...otherwise it will be just -1 and we should just
        // append the value to the list...
        if (this.autoSort) {
            this.data.add(-index - 1, new XYDataItem(x, y));
        } else {
            this.data.add(new XYDataItem(x, y));
        }

        // check if this addition will exceed the maximum item count...
        if (getItemCount() > this.maximumItemCount) {
            this.data.remove(0);
        }
    }
    fireSeriesChanged();
    return overwritten;
}

From source file:org.jfree.data.time.TimeSeries.java

/**
 * Adds a data item to the series and sends a {@link SeriesChangeEvent} to
 * all registered listeners./* w  w w. ja v a2 s. com*/
 *
 * @param item  the (timeperiod, value) pair (<code>null</code> not
 *              permitted).
 * @param notify  notify listeners?
 */
public void add(TimeSeriesDataItem item, boolean notify) {
    ParamChecks.nullNotPermitted(item, "item");
    item = (TimeSeriesDataItem) item.clone();
    Class c = item.getPeriod().getClass();
    if (this.timePeriodClass == null) {
        this.timePeriodClass = c;
    } else if (!this.timePeriodClass.equals(c)) {
        StringBuilder b = new StringBuilder();
        b.append("You are trying to add data where the time period class ");
        b.append("is ");
        b.append(item.getPeriod().getClass().getName());
        b.append(", but the TimeSeries is expecting an instance of ");
        b.append(this.timePeriodClass.getName());
        b.append(".");
        throw new SeriesException(b.toString());
    }

    // make the change (if it's not a duplicate time period)...
    boolean added = false;
    int count = getItemCount();
    if (count == 0) {
        this.data.add(item);
        added = true;
    } else {
        RegularTimePeriod last = getTimePeriod(getItemCount() - 1);
        if (item.getPeriod().compareTo(last) > 0) {
            this.data.add(item);
            added = true;
        } else {
            int index = Collections.binarySearch(this.data, item);
            if (index < 0) {
                this.data.add(-index - 1, item);
                added = true;
            } else {
                StringBuilder b = new StringBuilder();
                b.append("You are attempting to add an observation for ");
                b.append("the time period ");
                b.append(item.getPeriod().toString());
                b.append(" but the series already contains an observation");
                b.append(" for that time period. Duplicates are not ");
                b.append("permitted.  Try using the addOrUpdate() method.");
                throw new SeriesException(b.toString());
            }
        }
    }
    if (added) {
        updateBoundsForAddedItem(item);
        // check if this addition will exceed the maximum item count...
        if (getItemCount() > this.maximumItemCount) {
            TimeSeriesDataItem d = (TimeSeriesDataItem) this.data.remove(0);
            updateBoundsForRemovedItem(d);
        }

        removeAgedItems(false); // remove old items if necessary, but
                                // don't notify anyone, because that
                                // happens next anyway...
        if (notify) {
            fireSeriesChanged();
        }
    }

}

From source file:org.jfree.data.xy.XYSeries.java

/**
 * Updates an item in the series.// ww  w .ja v  a 2s .  c  o m
 *
 * @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.
 */
public void update(Number x, Number y) {
    int index = indexOf(x);
    if (index < 0) {
        throw new SeriesException("No observation for x = " + x);
    }
    updateByIndex(index, y);
}

From source file:org.jfree.data.time.TimeSeries.java

/**
 * Updates (changes) the value for a time period.  Throws a
 * {@link SeriesException} if the period does not exist.
 *
 * @param period  the period (<code>null</code> not permitted).
 * @param value  the value (<code>null</code> permitted).
 *//* w w w  . j  ava2 s  . c  o m*/
public void update(RegularTimePeriod period, Number value) {
    TimeSeriesDataItem temp = new TimeSeriesDataItem(period, value);
    int index = Collections.binarySearch(this.data, temp);
    if (index < 0) {
        throw new SeriesException("There is no existing value for the " + "specified 'period'.");
    }
    update(index, value);
}

From source file:org.jfree.data.time.TimeSeries.java

/**
 * Adds or updates an item in the times series and sends a
 * {@link SeriesChangeEvent} to all registered listeners.
 *
 * @param item  the data item (<code>null</code> not permitted).
 *
 * @return A copy of the overwritten data item, or <code>null</code> if no
 *         item was overwritten.//from w  w  w  .j av  a 2  s  .c om
 *
 * @since 1.0.14
 */
public TimeSeriesDataItem addOrUpdate(TimeSeriesDataItem item) {

    ParamChecks.nullNotPermitted(item, "item");
    Class periodClass = item.getPeriod().getClass();
    if (this.timePeriodClass == null) {
        this.timePeriodClass = periodClass;
    } else if (!this.timePeriodClass.equals(periodClass)) {
        String msg = "You are trying to add data where the time " + "period class is " + periodClass.getName()
                + ", but the TimeSeries is expecting an instance of " + this.timePeriodClass.getName() + ".";
        throw new SeriesException(msg);
    }
    TimeSeriesDataItem overwritten = null;
    int index = Collections.binarySearch(this.data, item);
    if (index >= 0) {
        TimeSeriesDataItem existing = (TimeSeriesDataItem) this.data.get(index);
        overwritten = (TimeSeriesDataItem) existing.clone();
        // figure out if we need to iterate through all the y-values
        // to find the revised minY / maxY
        boolean iterate = false;
        Number oldYN = existing.getValue();
        double oldY = oldYN != null ? oldYN.doubleValue() : Double.NaN;
        if (!Double.isNaN(oldY)) {
            iterate = oldY <= this.minY || oldY >= this.maxY;
        }
        existing.setValue(item.getValue());
        if (iterate) {
            updateMinMaxYByIteration();
        } else if (item.getValue() != null) {
            double yy = item.getValue().doubleValue();
            this.minY = minIgnoreNaN(this.minY, yy);
            this.maxY = maxIgnoreNaN(this.maxY, yy);
        }
    } else {
        item = (TimeSeriesDataItem) item.clone();
        this.data.add(-index - 1, item);
        updateBoundsForAddedItem(item);

        // check if this addition will exceed the maximum item count...
        if (getItemCount() > this.maximumItemCount) {
            TimeSeriesDataItem d = (TimeSeriesDataItem) this.data.remove(0);
            updateBoundsForRemovedItem(d);
        }
    }
    removeAgedItems(false); // remove old items if necessary, but
                            // don't notify anyone, because that
                            // happens next anyway...
    fireSeriesChanged();
    return overwritten;

}