Example usage for org.jfree.data.xy XYDataItem clone

List of usage examples for org.jfree.data.xy XYDataItem clone

Introduction

In this page you can find the example usage for org.jfree.data.xy XYDataItem clone.

Prototype

@Override
public Object clone() 

Source Link

Document

Returns a clone of this object.

Usage

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

/**
 * Confirm that cloning works.//from   w  w  w.jav  a  2s  .  c  om
 */
@Test
public void testCloning() {
    XYDataItem i1 = new XYDataItem(1.0, 1.1);
    XYDataItem i2 = (XYDataItem) i1.clone();
    assertTrue(i1 != i2);
    assertTrue(i1.getClass() == i2.getClass());
    assertTrue(i1.equals(i2));
}

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

/**
 * Creates a new series by copying a subset of the data in this time series.
 *
 * @param start  the index of the first item to copy.
 * @param end  the index of the last item to copy.
 *
 * @return A series containing a copy of this series from start until end.
 *
 * @throws CloneNotSupportedException if there is a cloning problem.
 *//*from w w  w.  j a  v a2 s  . c  o  m*/
public XYSeries createCopy(int start, int end) throws CloneNotSupportedException {

    XYSeries copy = (XYSeries) super.clone();
    copy.data = new java.util.ArrayList();
    if (this.data.size() > 0) {
        for (int index = start; index <= end; index++) {
            XYDataItem item = (XYDataItem) this.data.get(index);
            XYDataItem clone = (XYDataItem) item.clone();
            try {
                copy.add(clone);
            } catch (SeriesException e) {
                System.err.println("Unable to add cloned data item.");
            }
        }
    }
    return copy;

}

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

/**
 * Creates a new series by copying a subset of the data in this
 * time series.//from  w  ww. ja va  2s  .c o  m
 *
 * @param start  the index of the first item to copy.
 * @param end  the index of the last item to copy.
 *
 * @return A series containing a copy of this series from start
 *         until end.
 *
 * @throws CloneNotSupportedException if there is a cloning
 *                                    problem.
 */
public XYSeries createCopy(int start, int end) throws CloneNotSupportedException {
    XYSeries copy = (XYSeries) super.clone();

    copy.data = new java.util.ArrayList();
    if (this.data.size() > 0) {
        for (int index = start; index <= end; index++) {
            XYDataItem item = (XYDataItem) this.data.get(index);
            XYDataItem clone = (XYDataItem) item.clone();
            try {
                copy.add(clone);
            } catch (SeriesException e) {
                System.err.println("Unable to add cloned data item.");
            }
        }
    }
    return copy;
}

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 no
 *         item was overwritten./*from  w  ww  .  ja  v a2s  . c o  m*/
 */
public XYDataItem addOrUpdate(Number x, Number y) {
    if (x == null) {
        throw new IllegalArgumentException("Null 'x' argument.");
    }

    // if we get to here, we know that duplicate X values are not permitted
    XYDataItem overwritten = null;
    int index = indexOf(x);
    if (index >= 0 && !this.allowDuplicateXValues) {
        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.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 no
 *         item was overwritten.// ww w  .j a v  a2 s.c o  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.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 va 2 s  .c om
public XYDataItem addOrUpdate(Number x, Number y) {
    if (x == null) {
        throw new IllegalArgumentException("Null 'x' argument.");
    }

    // if we get to here, we know that duplicate X values are not permitted
    XYDataItem overwritten = null;
    int index = indexOf(x);
    if (index >= 0 && !this.allowDuplicateXValues) {
        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.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   w  w w .j  a va  2 s  . com
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.xy.XYSeries.java

/**
 * Return the data item with the specified index.
 *
 * @param index  the index.//from  w  ww  .  j a va 2s .  c  om
 *
 * @return The data item with the specified index.
 */
public XYDataItem getDataItem(int index) {
    XYDataItem item = (XYDataItem) this.data.get(index);
    return (XYDataItem) item.clone();
}

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

/**
 * Creates a new series by copying a subset of the data in this time series.
 *
 * @param start  the index of the first item to copy.
 * @param end  the index of the last item to copy.
 *
 * @return A series containing a copy of this series from start until end.
 *
 * @throws CloneNotSupportedException if there is a cloning problem.
 *//*from   w w  w .j a  va  2 s . c  om*/
public XYSeries createCopy(int start, int end) throws CloneNotSupportedException {

    XYSeries copy = (XYSeries) super.clone();
    copy.data = new java.util.ArrayList();
    if (this.data.size() > 0) {
        for (int index = start; index <= end; index++) {
            XYDataItem item = (XYDataItem) this.data.get(index);
            XYDataItem clone = (XYDataItem) item.clone();
            try {
                copy.add(clone);
            } catch (SeriesException e) {
                throw new RuntimeException("Unable to add cloned data item.", e);
            }
        }
    }
    return copy;

}

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 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 ww. j a  v a2  s.  com*/
 *
 * @since 1.0.14
 */
public XYDataItem addOrUpdate(XYDataItem item) {
    ParamChecks.nullNotPermitted(item, "item");
    if (this.allowDuplicateXValues) {
        add(item);
        return null;
    }

    // if we get to here, we know that duplicate X values are not permitted
    XYDataItem overwritten = null;
    int index = indexOf(item.getX());
    if (index >= 0) {
        XYDataItem existing = (XYDataItem) this.data.get(index);
        overwritten = (XYDataItem) existing.clone();
        // figure out if we need to iterate through all the y-values
        boolean iterate = false;
        double oldY = existing.getYValue();
        if (!Double.isNaN(oldY)) {
            iterate = oldY <= this.minY || oldY >= this.maxY;
        }
        existing.setY(item.getY());

        if (iterate) {
            findBoundsByIteration();
        } else if (item.getY() != null) {
            double yy = item.getY().doubleValue();
            this.minY = minIgnoreNaN(this.minY, yy);
            this.maxY = maxIgnoreNaN(this.maxY, yy);
        }
    } 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...
        item = (XYDataItem) item.clone();
        if (this.autoSort) {
            this.data.add(-index - 1, item);
        } else {
            this.data.add(item);
        }
        updateBoundsForAddedItem(item);

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