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
/** * Calculates the correlation between two datasets. Both arrays should * contain the same number of items. Null values are treated as zero. * <P>// w w w . j ava2 s . c o m * Information about the correlation calculation was obtained from: * * http://trochim.human.cornell.edu/kb/statcorr.htm * * @param data1 the first dataset. * @param data2 the second dataset. * * @return The correlation. */ public static double getCorrelation(Number[] data1, Number[] data2) { ParamChecks.nullNotPermitted(data1, "data1"); ParamChecks.nullNotPermitted(data2, "data2"); if (data1.length != data2.length) { throw new IllegalArgumentException("'data1' and 'data2' arrays must have same length."); } int n = data1.length; double sumX = 0.0; double sumY = 0.0; double sumX2 = 0.0; double sumY2 = 0.0; double sumXY = 0.0; for (int i = 0; i < n; i++) { double x = 0.0; if (data1[i] != null) { x = data1[i].doubleValue(); } double y = 0.0; if (data2[i] != null) { y = data2[i].doubleValue(); } sumX = sumX + x; sumY = sumY + y; sumXY = sumXY + (x * y); sumX2 = sumX2 + (x * x); sumY2 = sumY2 + (y * y); } return (n * sumXY - sumX * sumY) / Math.pow((n * sumX2 - sumX * sumX) * (n * sumY2 - sumY * sumY), 0.5); }
From source file:org.jfree.data.xy.DefaultIntervalXYDataset.java
/** * Adds a series or if a series with the same key already exists replaces * the data for that series, then sends a {@link DatasetChangeEvent} to * all registered listeners./*ww w. j a v a2s .c om*/ * * @param seriesKey the series key (<code>null</code> not permitted). * @param data the data (must be an array with length 6, containing six * arrays of equal length, the first three containing the x-values * (x, xLow and xHigh) and the last three containing the y-values * (y, yLow and yHigh)). */ public void addSeries(Comparable seriesKey, double[][] data) { ParamChecks.nullNotPermitted(seriesKey, "seriesKey"); ParamChecks.nullNotPermitted(seriesKey, "data"); if (data.length != 6) { throw new IllegalArgumentException("The 'data' array must have length == 6."); } int length = data[0].length; if (length != data[1].length || length != data[2].length || length != data[3].length || length != data[4].length || length != data[5].length) { throw new IllegalArgumentException("The 'data' array must contain six arrays with equal length."); } int seriesIndex = indexOf(seriesKey); if (seriesIndex == -1) { // add a new series this.seriesKeys.add(seriesKey); this.seriesList.add(data); } else { // replace an existing series this.seriesList.remove(seriesIndex); this.seriesList.add(seriesIndex, data); } notifyListeners(new DatasetChangeEvent(this, this)); }
From source file:org.jfree.data.time.TimeSeriesCollection.java
/** * Returns the index of the series with the specified key, or -1 if no * series has that key./*w w w .ja va2 s.com*/ * * @param key the key (<code>null</code> not permitted). * * @return The index. * * @since 1.0.17 */ public int getSeriesIndex(Comparable key) { ParamChecks.nullNotPermitted(key, "key"); int seriesCount = getSeriesCount(); for (int i = 0; i < seriesCount; i++) { TimeSeries series = (TimeSeries) this.data.get(i); if (key.equals(series.getKey())) { return i; } } return -1; }
From source file:org.jfree.data.DefaultKeyedValues2D.java
/** * Removes a row from the table./*from w w w. j a va 2s . co m*/ * * @param rowKey the row key (<code>null</code> not permitted). * * @see #removeRow(int) * @see #removeColumn(Comparable) * * @throws UnknownKeyException if <code>rowKey</code> is not defined in the * table. */ public void removeRow(Comparable rowKey) { ParamChecks.nullNotPermitted(rowKey, "rowKey"); int index = getRowIndex(rowKey); if (index >= 0) { removeRow(index); } else { throw new UnknownKeyException("Unknown key: " + rowKey); } }
From source file:org.jfree.experimental.swt.SWTUtils.java
/** * Converts an AWT image to SWT./*from w ww. j a v a 2 s. c o m*/ * * @param image the image (<code>null</code> not permitted). * * @return Image data. */ public static ImageData convertAWTImageToSWT(Image image) { ParamChecks.nullNotPermitted(image, "image"); int w = image.getWidth(null); int h = image.getHeight(null); if (w == -1 || h == -1) { return null; } BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics g = bi.getGraphics(); g.drawImage(image, 0, 0, null); g.dispose(); return convertToSWT(bi); }
From source file:org.jfree.data.xy.DefaultTableXYDataset.java
/** * Removes the items from all series for a given x value. * * @param x the x-value./*from w ww. j a v a 2 s. c o m*/ */ public void removeAllValuesForX(Number x) { ParamChecks.nullNotPermitted(x, "x"); boolean savedState = this.propagateEvents; this.propagateEvents = false; for (int s = 0; s < this.data.size(); s++) { XYSeries series = (XYSeries) this.data.get(s); series.remove(x); } this.propagateEvents = savedState; this.xPoints.remove(x); fireDatasetChanged(); }
From source file:org.jfree.data.time.TimeSeriesCollection.java
/** * Adds a series to the collection and sends a {@link DatasetChangeEvent} to * all registered listeners./*from w ww . j ava2s . c o m*/ * * @param series the series (<code>null</code> not permitted). */ public void addSeries(TimeSeries series) { ParamChecks.nullNotPermitted(series, "series"); this.data.add(series); series.addChangeListener(this); series.addVetoableChangeListener(this); fireDatasetChanged(); }
From source file:org.jfree.data.time.TimeSeriesCollection.java
/** * Removes the specified series from the collection and sends a * {@link DatasetChangeEvent} to all registered listeners. * * @param series the series (<code>null</code> not permitted). *//*from w w w .j a v a 2 s .c o m*/ public void removeSeries(TimeSeries series) { ParamChecks.nullNotPermitted(series, "series"); this.data.remove(series); series.removeChangeListener(this); series.removeVetoableChangeListener(this); fireDatasetChanged(); }
From source file:org.jfree.data.DefaultKeyedValues2D.java
/** * Removes a column from the table./*from w w w .j a v a2 s . c o m*/ * * @param columnKey the column key (<code>null</code> not permitted). * * @throws UnknownKeyException if the table does not contain a column with * the specified key. * @throws IllegalArgumentException if <code>columnKey</code> is * <code>null</code>. * * @see #removeColumn(int) * @see #removeRow(Comparable) */ public void removeColumn(Comparable columnKey) { ParamChecks.nullNotPermitted(columnKey, "columnKey"); if (!this.columnKeys.contains(columnKey)) { throw new UnknownKeyException("Unknown key: " + columnKey); } Iterator iterator = this.rows.iterator(); while (iterator.hasNext()) { DefaultKeyedValues rowData = (DefaultKeyedValues) iterator.next(); int index = rowData.getIndex(columnKey); if (index >= 0) { rowData.removeValue(columnKey); } } this.columnKeys.remove(columnKey); }
From source file:org.jfree.data.time.TimeSeries.java
/** * Finds the range of y-values that fall within the specified range of * x-values (where the x-values are interpreted as milliseconds since the * epoch and converted to time periods using the specified timezone). * /*ww w.j ava 2 s. c om*/ * @param xRange the subset of x-values to use (<code>null</code> not * permitted). * @param xAnchor the anchor point for the x-values (<code>null</code> * not permitted). * @param zone the time zone (<code>null</code> not permitted). * * @return The range of y-values. * * @since 1.0.18 */ public Range findValueRange(Range xRange, TimePeriodAnchor xAnchor, TimeZone zone) { ParamChecks.nullNotPermitted(xRange, "xRange"); ParamChecks.nullNotPermitted(xAnchor, "xAnchor"); ParamChecks.nullNotPermitted(zone, "zone"); if (this.data.isEmpty()) { return null; } Calendar calendar = Calendar.getInstance(zone); // since the items are ordered, we could be more clever here and avoid // iterating over all the data double lowY = Double.POSITIVE_INFINITY; double highY = Double.NEGATIVE_INFINITY; for (int i = 0; i < this.data.size(); i++) { TimeSeriesDataItem item = (TimeSeriesDataItem) this.data.get(i); long millis = item.getPeriod().getMillisecond(xAnchor, calendar); if (xRange.contains(millis)) { Number n = item.getValue(); if (n != null) { double v = n.doubleValue(); lowY = Math.min(lowY, v); highY = Math.max(highY, v); } } } if (Double.isInfinite(lowY) && Double.isInfinite(highY)) { if (lowY < highY) { return new Range(lowY, highY); } else { return new Range(Double.NaN, Double.NaN); } } return new Range(lowY, highY); }