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.time.MovingAverage.java

/**
 * Creates a new {@link TimeSeries} containing moving average values for
 * the given series, calculated by number of points (irrespective of the
 * 'age' of those points).  If the series is empty (contains zero items),
 * the result is an empty series./*from   w ww . j ava  2 s  .c om*/
 * <p>
 * Developed by Benoit Xhenseval (www.ObjectLab.co.uk).
 *
 * @param source  the source series.
 * @param name  the name of the new series.
 * @param pointCount  the number of POINTS used in the average calculation
 *                    (not periods!)
 *
 * @return The moving average series.
 */
public static TimeSeries createPointMovingAverage(TimeSeries source, String name, int pointCount) {

    ParamChecks.nullNotPermitted(source, "source");
    if (pointCount < 2) {
        throw new IllegalArgumentException("periodCount must be greater " + "than or equal to 2.");
    }

    TimeSeries result = new TimeSeries(name);
    double rollingSumForPeriod = 0.0;
    for (int i = 0; i < source.getItemCount(); i++) {
        // get the current data item...
        TimeSeriesDataItem current = source.getRawDataItem(i);
        RegularTimePeriod period = current.getPeriod();
        // FIXME: what if value is null on next line?
        rollingSumForPeriod += current.getValue().doubleValue();

        if (i > pointCount - 1) {
            // remove the point i-periodCount out of the rolling sum.
            TimeSeriesDataItem startOfMovingAvg = source.getRawDataItem(i - pointCount);
            rollingSumForPeriod -= startOfMovingAvg.getValue().doubleValue();
            result.add(period, rollingSumForPeriod / pointCount);
        } else if (i == pointCount - 1) {
            result.add(period, rollingSumForPeriod / pointCount);
        }
    }
    return result;
}

From source file:org.jfree.data.gantt.TaskSeriesCollection.java

/**
 * Returns the column index for a column key.
 *
 * @param columnKey  the column key (<code>null</code> not permitted).
 *
 * @return The column index./*w  w w.  j ava 2  s. co m*/
 */
@Override
public int getColumnIndex(Comparable columnKey) {
    ParamChecks.nullNotPermitted(columnKey, "columnKey");
    return this.keys.indexOf(columnKey);
}

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

/**
 * Adds any unique x-values from 'series' to the dataset, and also adds any
 * x-values that are in the dataset but not in 'series' to the series.
 *
 * @param series  the series (<code>null</code> not permitted).
 *///from   w  w  w.j  a va  2  s  . c  o m
private void updateXPoints(XYSeries series) {
    ParamChecks.nullNotPermitted(series, "series");
    HashSet seriesXPoints = new HashSet();
    boolean savedState = this.propagateEvents;
    this.propagateEvents = false;
    for (int itemNo = 0; itemNo < series.getItemCount(); itemNo++) {
        Number xValue = series.getX(itemNo);
        seriesXPoints.add(xValue);
        if (!this.xPoints.contains(xValue)) {
            this.xPoints.add(xValue);
            int seriesCount = this.data.size();
            for (int seriesNo = 0; seriesNo < seriesCount; seriesNo++) {
                XYSeries dataSeries = (XYSeries) this.data.get(seriesNo);
                if (!dataSeries.equals(series)) {
                    dataSeries.add(xValue, null);
                }
            }
        }
    }
    Iterator iterator = this.xPoints.iterator();
    while (iterator.hasNext()) {
        Number xPoint = (Number) iterator.next();
        if (!seriesXPoints.contains(xPoint)) {
            series.add(xPoint, null);
        }
    }
    this.propagateEvents = savedState;
}

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

/**
 * Adds a series to the collection./*from  www  .ja va2  s  .co m*/
 * <P>
 * Notifies all registered listeners that the dataset has changed.
 * </p>
 *
 * @param series the series (<code>null</code> not permitted).
 */
public void addSeries(MatrixSeries series) {
    ParamChecks.nullNotPermitted(series, "series");
    // FIXME: Check that there isn't already a series with the same key

    // add the series...
    this.seriesList.add(series);
    series.addChangeListener(this);
    fireDatasetChanged();
}

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

/**
 * Removes the specified series from the collection.
 *
 * @param series  the series to remove (<code>null</code> not permitted).
 *///from   w w  w .  j a  v  a2 s. com
public void removeSeries(TimePeriodValues series) {
    ParamChecks.nullNotPermitted(series, "series");
    this.data.remove(series);
    series.removeChangeListener(this);
    fireDatasetChanged();

}

From source file:org.jfree.data.KeyToGroupMap.java

/**
 * Returns the number of keys mapped to the specified group.  This method
 * won't always return an accurate result for the default group, since
 * explicit mappings are not required for this group.
 *
 * @param group  the group (<code>null</code> not permitted).
 *
 * @return The key count./*from  w ww.ja  v a 2 s. com*/
 */
public int getKeyCount(Comparable group) {
    ParamChecks.nullNotPermitted(group, "group");
    int result = 0;
    Iterator iterator = this.keyToGroupMap.values().iterator();
    while (iterator.hasNext()) {
        Comparable g = (Comparable) iterator.next();
        if (group.equals(g)) {
            result++;
        }
    }
    return result;
}

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

/**
 * Constructs a new instance, based on a particular date/time and time zone.
 *
 * @param time  the date/time (<code>null</code> not permitted).
 * @param zone  the time zone (<code>null</code> not permitted).
 * @param locale  the locale (<code>null</code> not permitted).
 *//*w  w  w. j av a  2  s  . c om*/
public Day(Date time, TimeZone zone, Locale locale) {
    ParamChecks.nullNotPermitted(time, "time");
    ParamChecks.nullNotPermitted(zone, "zone");
    ParamChecks.nullNotPermitted(locale, "locale");
    Calendar calendar = Calendar.getInstance(zone, locale);
    calendar.setTime(time);
    int d = calendar.get(Calendar.DAY_OF_MONTH);
    int m = calendar.get(Calendar.MONTH) + 1;
    int y = calendar.get(Calendar.YEAR);
    this.serialDate = SerialDate.createInstance(d, m, y);
    peg(calendar);
}

From source file:org.jfree.data.KeyedObjects2D.java

/**
 * Returns the object for the given row and column keys.
 *
 * @param rowKey  the row key (<code>null</code> not permitted).
 * @param columnKey  the column key (<code>null</code> not permitted).
 *
 * @return The object (possibly <code>null</code>).
 *
 * @throws IllegalArgumentException if <code>rowKey</code> or
 *         <code>columnKey</code> is <code>null</code>.
 * @throws UnknownKeyException if <code>rowKey</code> or
 *         <code>columnKey</code> is not recognised.
 *///from w w w  . j  a v  a 2 s  .c  o m
public Object getObject(Comparable rowKey, Comparable columnKey) {
    ParamChecks.nullNotPermitted(rowKey, "rowKey");
    ParamChecks.nullNotPermitted(columnKey, "columnKey");
    int row = this.rowKeys.indexOf(rowKey);
    if (row < 0) {
        throw new UnknownKeyException("Row key (" + rowKey + ") not recognised.");
    }
    int column = this.columnKeys.indexOf(columnKey);
    if (column < 0) {
        throw new UnknownKeyException("Column key (" + columnKey + ") not recognised.");
    }
    KeyedObjects rowData = (KeyedObjects) this.rows.get(row);
    int index = rowData.getIndex(columnKey);
    if (index >= 0) {
        return rowData.getObject(index);
    } else {
        return null;
    }
}

From source file:org.jfree.data.DataUtilities.java

/**
 * Constructs an array of <code>Number</code> objects from an array of
 * <code>double</code> primitives.
 *
 * @param data  the data (<code>null</code> not permitted).
 *
 * @return An array of <code>Double</code>.
 *///from  w  ww  . j  a va  2 s. c  o  m
public static Number[] createNumberArray(double[] data) {
    ParamChecks.nullNotPermitted(data, "data");
    Number[] result = new Number[data.length];
    for (int i = 0; i < data.length; i++) {
        result[i] = new Double(data[i]);
    }
    return result;
}

From source file:org.jfree.data.statistics.BoxAndWhiskerCalculator.java

/**
 * Calculates the third quartile for a list of numbers in ascending order.
 * If the items in the list are not in ascending order, the result is
 * unspecified.  If the list contains items that are <code>null</code>, not
 * an instance of <code>Number</code>, or equivalent to
 * <code>Double.NaN</code>, the result is unspecified.
 *
 * @param values  the list of values (<code>null</code> not permitted).
 *
 * @return The third quartile.//from w ww . ja  v  a2 s . com
 */
public static double calculateQ3(List values) {
    ParamChecks.nullNotPermitted(values, "values");
    double result = Double.NaN;
    int count = values.size();
    if (count > 0) {
        if (count % 2 == 1) {
            if (count > 1) {
                result = Statistics.calculateMedian(values, count / 2, count - 1);
            } else {
                result = Statistics.calculateMedian(values, 0, 0);
            }
        } else {
            result = Statistics.calculateMedian(values, count / 2, count - 1);
        }
    }
    return result;
}