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.KeyedObjects.java
/** * Inserts a new value at the specified position in the dataset or, if * there is an existing item with the specified key, updates the value * for that item and moves it to the specified position. * * @param position the position (in the range <code>0</code> to * <code>getItemCount()</code>). * @param key the key (<code>null</code> not permitted). * @param value the value (<code>null</code> permitted). * * @since 1.0.7/*from w ww. j a va 2 s. c om*/ */ public void insertValue(int position, Comparable key, Object value) { if (position < 0 || position > this.data.size()) { throw new IllegalArgumentException("'position' out of bounds."); } ParamChecks.nullNotPermitted(key, "key"); int pos = getIndex(key); if (pos >= 0) { this.data.remove(pos); } KeyedObject item = new KeyedObject(key, value); if (position <= this.data.size()) { this.data.add(position, item); } else { this.data.add(item); } }
From source file:org.jfree.data.statistics.Regression.java
/** * Returns the parameters 'a0', 'a1', 'a2', ..., 'an' for a polynomial * function of order n, y = a0 + a1 * x + a2 * x^2 + ... + an * x^n, * fitted to the data using a polynomial regression equation. * The result is returned as an array with a length of n + 2, * where double[0] --> a0, double[1] --> a1, .., double[n] --> an. * and double[n + 1] is the correlation coefficient R2 * Reference: J. D. Faires, R. L. Burden, Numerische Methoden (german * edition), pp. 243ff and 327ff./*from w w w . ja v a 2s .com*/ * * @param dataset the dataset (<code>null</code> not permitted). * @param series the series to fit the regression line against (the series * must have at least order + 1 non-NaN items). * @param order the order of the function (> 0). * * @return The parameters. * * @since 1.0.14 */ public static double[] getPolynomialRegression(XYDataset dataset, int series, int order) { ParamChecks.nullNotPermitted(dataset, "dataset"); int itemCount = dataset.getItemCount(series); if (itemCount < order + 1) { throw new IllegalArgumentException("Not enough data."); } int validItems = 0; double[][] data = new double[2][itemCount]; for (int item = 0; item < itemCount; item++) { double x = dataset.getXValue(series, item); double y = dataset.getYValue(series, item); if (!Double.isNaN(x) && !Double.isNaN(y)) { data[0][validItems] = x; data[1][validItems] = y; validItems++; } } if (validItems < order + 1) { throw new IllegalArgumentException("Not enough data."); } int equations = order + 1; int coefficients = order + 2; double[] result = new double[equations + 1]; double[][] matrix = new double[equations][coefficients]; double sumX = 0.0; double sumY = 0.0; for (int item = 0; item < validItems; item++) { sumX += data[0][item]; sumY += data[1][item]; for (int eq = 0; eq < equations; eq++) { for (int coe = 0; coe < coefficients - 1; coe++) { matrix[eq][coe] += Math.pow(data[0][item], eq + coe); } matrix[eq][coefficients - 1] += data[1][item] * Math.pow(data[0][item], eq); } } double[][] subMatrix = calculateSubMatrix(matrix); for (int eq = 1; eq < equations; eq++) { matrix[eq][0] = 0; for (int coe = 1; coe < coefficients; coe++) { matrix[eq][coe] = subMatrix[eq - 1][coe - 1]; } } for (int eq = equations - 1; eq > -1; eq--) { double value = matrix[eq][coefficients - 1]; for (int coe = eq; coe < coefficients - 1; coe++) { value -= matrix[eq][coe] * result[coe]; } result[eq] = value / matrix[eq][eq]; } double meanY = sumY / validItems; double yObsSquare = 0.0; double yRegSquare = 0.0; for (int item = 0; item < validItems; item++) { double yCalc = 0; for (int eq = 0; eq < equations; eq++) { yCalc += result[eq] * Math.pow(data[0][item], eq); } yRegSquare += Math.pow(yCalc - meanY, 2); yObsSquare += Math.pow(data[1][item] - meanY, 2); } double rSquare = yRegSquare / yObsSquare; result[equations] = rSquare; return result; }
From source file:org.jfree.data.DataUtilities.java
/** * Constructs an array of arrays of <code>Number</code> objects from a * corresponding structure containing <code>double</code> primitives. * * @param data the data (<code>null</code> not permitted). * * @return An array of <code>Double</code>. *///from www . j a v a2 s. co m public static Number[][] createNumberArray2D(double[][] data) { ParamChecks.nullNotPermitted(data, "data"); int l1 = data.length; Number[][] result = new Number[l1][]; for (int i = 0; i < l1; i++) { result[i] = createNumberArray(data[i]); } return result; }
From source file:org.jfree.data.DefaultKeyedValues2D.java
/** * Returns the column index for a given key. * * @param key the key (<code>null</code> not permitted). * * @return The column index./*w w w. ja va2 s .c o m*/ * * @see #getColumnKey(int) * @see #getRowIndex(Comparable) */ @Override public int getColumnIndex(Comparable key) { ParamChecks.nullNotPermitted(key, "key"); return this.columnKeys.indexOf(key); }
From source file:de.hs.mannheim.modUro.controller.diagram.fx.ChartCanvas.java
/** * Sets the chart to be displayed by this node. * /* w w w. j a va 2 s.c o m*/ * @param chart the chart ({@code null} not permitted). */ public void setChart(JFreeChart chart) { ParamChecks.nullNotPermitted(chart, "chart"); this.chart.removeChangeListener(this); this.chart = chart; this.chart.addChangeListener(this); draw(); }
From source file:org.jfree.data.xy.XYSeriesCollection.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). */// w w w . j a va 2 s .co m public void removeSeries(XYSeries series) { ParamChecks.nullNotPermitted(series, "series"); if (this.data.contains(series)) { series.removeChangeListener(this); series.removeVetoableChangeListener(this); this.data.remove(series); fireDatasetChanged(); } }
From source file:org.jfree.data.gantt.TaskSeriesCollection.java
/** * Adds a series to the dataset and sends a * {@link org.jfree.data.general.DatasetChangeEvent} to all registered * listeners.//from w ww .j a va2s . c om * * @param series the series (<code>null</code> not permitted). */ public void add(TaskSeries series) { ParamChecks.nullNotPermitted(series, "series"); this.data.add(series); series.addChangeListener(this); // look for any keys that we don't already know about... Iterator iterator = series.getTasks().iterator(); while (iterator.hasNext()) { Task task = (Task) iterator.next(); String key = task.getDescription(); int index = this.keys.indexOf(key); if (index < 0) { this.keys.add(key); } } fireDatasetChanged(); }
From source file:org.jfree.data.DefaultKeyedValues.java
/** * Updates an existing value, or adds a new value to the collection. * * @param key the key (<code>null</code> not permitted). * @param value the value (<code>null</code> permitted). *//*from w w w .j a v a 2 s . co m*/ public void setValue(Comparable key, Number value) { ParamChecks.nullNotPermitted(key, "key"); int keyIndex = getIndex(key); if (keyIndex >= 0) { this.keys.set(keyIndex, key); this.values.set(keyIndex, value); } else { this.keys.add(key); this.values.add(value); this.indexMap.put(key, new Integer(this.keys.size() - 1)); } }
From source file:org.jfree.data.ComparableObjectSeries.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.//ww w . j av a 2 s . c o m */ protected void add(ComparableObjectItem item, boolean notify) { ParamChecks.nullNotPermitted(item, "item"); 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.getComparable()); if (index >= 0) { throw new SeriesException("X-value already exists."); } } this.data.add(item); } if (getItemCount() > this.maximumItemCount) { this.data.remove(0); } if (notify) { fireSeriesChanged(); } }
From source file:de.hs.mannheim.modUro.controller.diagram.fx.ChartViewer.java
/** * Removes a listener from the list of objects listening for chart mouse * events.//from w ww. j av a 2 s . co m * * @param listener the listener. */ public void removeChartMouseListener(ChartMouseListenerFX listener) { ParamChecks.nullNotPermitted(listener, "listener"); this.chartMouseListeners.remove(listener); }