List of usage examples for org.jfree.chart.util ParamChecks nullNotPermitted
public static void nullNotPermitted(Object param, String name)
IllegalArgumentException
if the supplied param
is null
. From source file:org.jfree.data.statistics.Statistics.java
/** * Fits a straight line to a set of (x, y) data, returning the slope and * intercept.//www. j a va 2 s . c om * * @param xData the x-data ({@code null} not permitted). * @param yData the y-data ({@code null} not permitted). * * @return A double array with the intercept in [0] and the slope in [1]. */ public static double[] getLinearFit(Number[] xData, Number[] yData) { ParamChecks.nullNotPermitted(xData, "xData"); ParamChecks.nullNotPermitted(yData, "yData"); if (xData.length != yData.length) { throw new IllegalArgumentException("Statistics.getLinearFit(): array lengths must be equal."); } double[] result = new double[2]; // slope result[1] = getSlope(xData, yData); // intercept result[0] = calculateMean(yData) - result[1] * calculateMean(xData); return result; }
From source file:org.jfree.data.category.DefaultIntervalCategoryDataset.java
/** * Sets the names of the series in the dataset. * * @param seriesKeys the new keys (<code>null</code> not permitted, the * length of the array must match the number of series in the * dataset).// w ww. ja v a 2s.co m * * @see #setCategoryKeys(Comparable[]) */ public void setSeriesKeys(Comparable[] seriesKeys) { ParamChecks.nullNotPermitted(seriesKeys, "seriesKeys"); if (seriesKeys.length != getSeriesCount()) { throw new IllegalArgumentException("The number of series keys does not match the data."); } this.seriesKeys = seriesKeys; fireDatasetChanged(); }
From source file:org.jfree.data.Range.java
/** * Shifts the range by the specified amount. * * @param base the base range (<code>null</code> not permitted). * @param delta the shift amount.// w ww . jav a 2s . c o m * @param allowZeroCrossing a flag that determines whether or not the * bounds of the range are allowed to cross * zero after adjustment. * * @return A new range. */ public static Range shift(Range base, double delta, boolean allowZeroCrossing) { ParamChecks.nullNotPermitted(base, "base"); if (allowZeroCrossing) { return new Range(base.getLowerBound() + delta, base.getUpperBound() + delta); } else { return new Range(shiftWithNoZeroCrossing(base.getLowerBound(), delta), shiftWithNoZeroCrossing(base.getUpperBound(), delta)); } }
From source file:org.jfree.data.statistics.Statistics.java
/** * Finds the slope of a regression line using least squares. * * @param xData the x-values ({@code null} not permitted). * @param yData the y-values ({@code null} not permitted). * * @return The slope.// ww w. j ava2 s. c om */ public static double getSlope(Number[] xData, Number[] yData) { ParamChecks.nullNotPermitted(xData, "xData"); ParamChecks.nullNotPermitted(yData, "yData"); if (xData.length != yData.length) { throw new IllegalArgumentException("Array lengths must be equal."); } // ********* stat function for linear slope ******** // y = a + bx // a = ybar - b * xbar // sum(x * y) - (sum (x) * sum(y)) / n // b = ------------------------------------ // sum (x^2) - (sum(x)^2 / n // ************************************************* // sum of x, x^2, x * y, y double sx = 0.0, sxx = 0.0, sxy = 0.0, sy = 0.0; int counter; for (counter = 0; counter < xData.length; counter++) { sx = sx + xData[counter].doubleValue(); sxx = sxx + Math.pow(xData[counter].doubleValue(), 2); sxy = sxy + yData[counter].doubleValue() * xData[counter].doubleValue(); sy = sy + yData[counter].doubleValue(); } return (sxy - (sx * sy) / counter) / (sxx - (sx * sx) / counter); }
From source file:org.jfree.data.xy.XYSeriesCollection.java
/** * Returns the index of the series with the specified key, or -1 if no * series has that key./* w ww . jav a2 s . c o m*/ * * @param key the key (<code>null</code> not permitted). * * @return The index. * * @since 1.0.14 */ public int getSeriesIndex(Comparable key) { ParamChecks.nullNotPermitted(key, "key"); int seriesCount = getSeriesCount(); for (int i = 0; i < seriesCount; i++) { XYSeries series = (XYSeries) this.data.get(i); if (key.equals(series.getKey())) { return i; } } return -1; }
From source file:org.jfree.data.time.TimeSeriesCollection.java
/** * Returns the index of the specified series, or -1 if that series is not * present in the dataset.//from ww w . j a v a 2s. c om * * @param series the series (<code>null</code> not permitted). * * @return The series index. * * @since 1.0.6 */ public int indexOf(TimeSeries series) { ParamChecks.nullNotPermitted(series, "series"); return this.data.indexOf(series); }
From source file:org.jfree.data.Range.java
/** * Scales the range by the specified factor. * * @param base the base range (<code>null</code> not permitted). * @param factor the scaling factor (must be non-negative). * * @return A new range.//from www . j av a2 s. com * * @since 1.0.9 */ public static Range scale(Range base, double factor) { ParamChecks.nullNotPermitted(base, "base"); if (factor < 0) { throw new IllegalArgumentException("Negative 'factor' argument."); } return new Range(base.getLowerBound() * factor, base.getUpperBound() * factor); }
From source file:org.jfree.data.time.ohlc.OHLCSeriesCollection.java
/** * Removes the specified series from the dataset and sends a * {@link DatasetChangeEvent} to all registered listeners. * * @param series the series (<code>null</code> not permitted). * * @return <code>true</code> if the series was removed, and * <code>false</code> otherwise. * * @since 1.0.14//from w w w . j av a 2 s.c o m */ public boolean removeSeries(OHLCSeries series) { ParamChecks.nullNotPermitted(series, "series"); boolean removed = this.data.remove(series); if (removed) { series.removeChangeListener(this); fireDatasetChanged(); } return removed; }
From source file:org.jfree.data.category.DefaultIntervalCategoryDataset.java
/** * Sets the categories for the dataset.// ww w .j a v a 2 s. c o m * * @param categoryKeys an array of objects representing the categories in * the dataset. * * @see #getRowKeys() * @see #setSeriesKeys(Comparable[]) */ public void setCategoryKeys(Comparable[] categoryKeys) { ParamChecks.nullNotPermitted(categoryKeys, "categoryKeys"); if (categoryKeys.length != getCategoryCount()) { throw new IllegalArgumentException("The number of categories does not match the data."); } for (int i = 0; i < categoryKeys.length; i++) { if (categoryKeys[i] == null) { throw new IllegalArgumentException( "DefaultIntervalCategoryDataset.setCategoryKeys(): " + "null category not permitted."); } } this.categoryKeys = categoryKeys; fireDatasetChanged(); }
From source file:org.jfree.data.xy.DefaultTableXYDataset.java
/** * Removes a series from the collection and sends a * {@link DatasetChangeEvent} to all registered listeners. * * @param series the series (<code>null</code> not permitted). *//*from w ww . j a va2s . com*/ public void removeSeries(XYSeries series) { ParamChecks.nullNotPermitted(series, "series"); if (this.data.contains(series)) { series.removeChangeListener(this); this.data.remove(series); if (this.data.isEmpty()) { this.xPoints.clear(); } fireDatasetChanged(); } }