Example usage for org.jfree.chart.util ParamChecks nullNotPermitted

List of usage examples for org.jfree.chart.util ParamChecks nullNotPermitted

Introduction

In this page you can find the example usage for org.jfree.chart.util ParamChecks nullNotPermitted.

Prototype

public static void nullNotPermitted(Object param, String name) 

Source Link

Document

Throws an IllegalArgumentException if the supplied param is null.

Usage

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

/**
 * Adds a data item to the series and, if requested, sends a
 * {@link SeriesChangeEvent} to all registered listeners.
 *
 * @param item  the (x, y) item (<code>null</code> not permitted).
 * @param notify  a flag that controls whether or not a
 *                {@link SeriesChangeEvent} is sent to all registered
 *                listeners.//from ww  w  . j av a2s .  c om
 */
public void add(XYDataItem item, boolean notify) {
    ParamChecks.nullNotPermitted(item, "item");
    item = (XYDataItem) item.clone();
    if (this.autoSort) {
        int index = Collections.binarySearch(this.data, item);
        if (index < 0) {
            this.data.add(-index - 1, item);
        } else {
            if (this.allowDuplicateXValues) {
                // need to make sure we are adding *after* any duplicates
                int size = this.data.size();
                while (index < size && item.compareTo(this.data.get(index)) == 0) {
                    index++;
                }
                if (index < this.data.size()) {
                    this.data.add(index, item);
                } else {
                    this.data.add(item);
                }
            } else {
                throw new SeriesException("X-value already exists.");
            }
        }
    } else {
        if (!this.allowDuplicateXValues) {
            // can't allow duplicate values, so we need to check whether
            // there is an item with the given x-value already
            int index = indexOf(item.getX());
            if (index >= 0) {
                throw new SeriesException("X-value already exists.");
            }
        }
        this.data.add(item);
    }
    updateBoundsForAddedItem(item);
    if (getItemCount() > this.maximumItemCount) {
        XYDataItem removed = (XYDataItem) this.data.remove(0);
        updateBoundsForRemovedItem(removed);
    }
    if (notify) {
        fireSeriesChanged();
    }
}

From source file:org.jfree.data.general.DatasetUtilities.java

/**
 * Creates a {@link CategoryDataset} that contains a copy of the data in
 * an array (instances of <code>Double</code> are created to represent the
 * data items).//from  w ww  .  jav a 2s.c o  m
 * <p>
 * Row and column keys are taken from the supplied arrays.
 *
 * @param rowKeys  the row keys (<code>null</code> not permitted).
 * @param columnKeys  the column keys (<code>null</code> not permitted).
 * @param data  the data.
 *
 * @return The dataset.
 */
public static CategoryDataset createCategoryDataset(Comparable[] rowKeys, Comparable[] columnKeys,
        double[][] data) {

    ParamChecks.nullNotPermitted(rowKeys, "rowKeys");
    ParamChecks.nullNotPermitted(columnKeys, "columnKeys");
    if (ArrayUtilities.hasDuplicateItems(rowKeys)) {
        throw new IllegalArgumentException("Duplicate items in 'rowKeys'.");
    }
    if (ArrayUtilities.hasDuplicateItems(columnKeys)) {
        throw new IllegalArgumentException("Duplicate items in 'columnKeys'.");
    }
    if (rowKeys.length != data.length) {
        throw new IllegalArgumentException(
                "The number of row keys does not match the number of rows in " + "the data array.");
    }
    int columnCount = 0;
    for (int r = 0; r < data.length; r++) {
        columnCount = Math.max(columnCount, data[r].length);
    }
    if (columnKeys.length != columnCount) {
        throw new IllegalArgumentException(
                "The number of column keys does not match the number of " + "columns in the data array.");
    }

    // now do the work...
    DefaultCategoryDataset result = new DefaultCategoryDataset();
    for (int r = 0; r < data.length; r++) {
        Comparable rowKey = rowKeys[r];
        for (int c = 0; c < data[r].length; c++) {
            Comparable columnKey = columnKeys[c];
            result.addValue(new Double(data[r][c]), rowKey, columnKey);
        }
    }
    return result;

}

From source file:org.jfree.data.general.DatasetUtilities.java

/**
 * Creates a {@link CategoryDataset} by copying the data from the supplied
 * {@link KeyedValues} instance./*from  w w w. j  ava 2s  .co  m*/
 *
 * @param rowKey  the row key (<code>null</code> not permitted).
 * @param rowData  the row data (<code>null</code> not permitted).
 *
 * @return A dataset.
 */
public static CategoryDataset createCategoryDataset(Comparable rowKey, KeyedValues rowData) {

    ParamChecks.nullNotPermitted(rowKey, "rowKey");
    ParamChecks.nullNotPermitted(rowData, "rowData");
    DefaultCategoryDataset result = new DefaultCategoryDataset();
    for (int i = 0; i < rowData.getItemCount(); i++) {
        result.addValue(rowData.getValue(i), rowKey, rowData.getKey(i));
    }
    return result;

}

From source file:org.jfree.data.category.DefaultIntervalCategoryDataset.java

/**
 * Returns a column index.//w  ww  . j  a  v  a  2 s.  c o m
 *
 * @param columnKey  the column key (<code>null</code> not permitted).
 *
 * @return The column index.
 *
 * @see #getCategoryIndex(Comparable)
 */
@Override
public int getColumnIndex(Comparable columnKey) {
    ParamChecks.nullNotPermitted(columnKey, "columnKey");
    return getCategoryIndex(columnKey);
}

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

/**
 * Returns the index for the item (if any) that corresponds to a time
 * period.// w  ww. j  a va 2  s .c o  m
 *
 * @param period  the time period (<code>null</code> not permitted).
 *
 * @return The index.
 */
public int getIndex(RegularTimePeriod period) {
    ParamChecks.nullNotPermitted(period, "period");
    TimeSeriesDataItem dummy = new TimeSeriesDataItem(period, Integer.MIN_VALUE);
    return Collections.binarySearch(this.data, dummy);
}

From source file:org.jfree.data.general.DatasetUtilities.java

/**
 * Creates an {@link XYSeries} by sampling the specified function over a
 * fixed range.//w ww  . j a  v a  2  s.c  o m
 *
 * @param f  the function (<code>null</code> not permitted).
 * @param start  the start value for the range.
 * @param end  the end value for the range.
 * @param samples  the number of sample points (must be &gt; 1).
 * @param seriesKey  the key to give the resulting series
 *                   (<code>null</code> not permitted).
 *
 * @return A series.
 *
 * @since 1.0.13
 */
public static XYSeries sampleFunction2DToSeries(Function2D f, double start, double end, int samples,
        Comparable seriesKey) {

    ParamChecks.nullNotPermitted(f, "f");
    ParamChecks.nullNotPermitted(seriesKey, "seriesKey");
    if (start >= end) {
        throw new IllegalArgumentException("Requires 'start' < 'end'.");
    }
    if (samples < 2) {
        throw new IllegalArgumentException("Requires 'samples' > 1");
    }

    XYSeries series = new XYSeries(seriesKey);
    double step = (end - start) / (samples - 1);
    for (int i = 0; i < samples; i++) {
        double x = start + (step * i);
        series.add(x, f.getValue(x));
    }
    return series;
}

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. j  a va2  s.c  o m
 *
 * @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.category.DefaultIntervalCategoryDataset.java

/**
 * Clones a two dimensional array of <code>Number</code> objects.
 *
 * @param array  the array (<code>null</code> not permitted).
 *
 * @return A clone of the array./* www . j  a  v  a 2  s .  c o  m*/
 */
private static Number[][] clone(Number[][] array) {
    ParamChecks.nullNotPermitted(array, "array");
    Number[][] result = new Number[array.length][];
    for (int i = 0; i < array.length; i++) {
        Number[] child = array[i];
        Number[] copychild = new Number[child.length];
        System.arraycopy(child, 0, copychild, 0, child.length);
        result[i] = copychild;
    }
    return result;
}

From source file:org.jfree.data.general.DatasetUtilities.java

/**
 * Returns the range of values in the domain (x-values) of a dataset.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param includeInterval  determines whether or not the x-interval is taken
 *                         into account (only applies if the dataset is an
 *                         {@link IntervalXYDataset}).
 *
 * @return The range of values (possibly <code>null</code>).
 *///from  w w w.j a va 2s .  c o  m
public static Range findDomainBounds(XYDataset dataset, boolean includeInterval) {

    ParamChecks.nullNotPermitted(dataset, "dataset");

    Range result;
    // if the dataset implements DomainInfo, life is easier
    if (dataset instanceof DomainInfo) {
        DomainInfo info = (DomainInfo) dataset;
        result = info.getDomainBounds(includeInterval);
    } else {
        result = iterateDomainBounds(dataset, includeInterval);
    }
    return result;

}

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  . java  2 s .co m*/
 *
 * @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;
}