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.xy.YIntervalSeriesCollection.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). * * @since 1.0.10/*w w w . ja va2 s .co m*/ */ public void removeSeries(YIntervalSeries series) { ParamChecks.nullNotPermitted(series, "series"); if (this.data.contains(series)) { series.removeChangeListener(this); this.data.remove(series); fireDatasetChanged(); } }
From source file:org.jfree.data.DefaultKeyedValues.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 0 to getItemCount()). * @param key the key (<code>null</code> not permitted). * @param value the value (<code>null</code> permitted). * * @since 1.0.6//w w w. j ava 2 s.co m */ public void insertValue(int position, Comparable key, Number value) { if (position < 0 || position > getItemCount()) { throw new IllegalArgumentException("'position' out of bounds."); } ParamChecks.nullNotPermitted(key, "key"); int pos = getIndex(key); if (pos == position) { this.keys.set(pos, key); this.values.set(pos, value); } else { if (pos >= 0) { this.keys.remove(pos); this.values.remove(pos); } this.keys.add(position, key); this.values.add(position, value); rebuildIndex(); } }
From source file:org.jfree.data.xy.XIntervalSeriesCollection.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). * * @since 1.0.10//from ww w. j a v a 2 s .c o m */ public void removeSeries(XIntervalSeries series) { ParamChecks.nullNotPermitted(series, "series"); if (this.data.contains(series)) { series.removeChangeListener(this); this.data.remove(series); fireDatasetChanged(); } }
From source file:org.jfree.data.Range.java
/** * Creates a new range by adding margins to an existing range. * * @param range the range (<code>null</code> not permitted). * @param lowerMargin the lower margin (expressed as a percentage of the * range length).// w ww. j ava 2 s . c o m * @param upperMargin the upper margin (expressed as a percentage of the * range length). * * @return The expanded range. */ public static Range expand(Range range, double lowerMargin, double upperMargin) { ParamChecks.nullNotPermitted(range, "range"); double length = range.getLength(); double lower = range.getLowerBound() - length * lowerMargin; double upper = range.getUpperBound() + length * upperMargin; if (lower > upper) { lower = lower / 2.0 + upper / 2.0; upper = lower; } return new Range(lower, upper); }
From source file:org.jfree.data.statistics.Statistics.java
/** * Returns the standard deviation of a set of numbers. * * @param data the data ({@code null} or zero length array not * permitted)./*from w w w . ja v a2 s.com*/ * * @return The standard deviation of a set of numbers. */ public static double getStdDev(Number[] data) { ParamChecks.nullNotPermitted(data, "data"); if (data.length == 0) { throw new IllegalArgumentException("Zero length 'data' array."); } double avg = calculateMean(data); double sum = 0.0; for (int counter = 0; counter < data.length; counter++) { double diff = data[counter].doubleValue() - avg; sum = sum + diff * diff; } return Math.sqrt(sum / (data.length - 1)); }
From source file:org.jfree.data.time.MovingAverage.java
/** * Creates a new {@link XYSeries} containing the moving averages of one * series in the <code>source</code> dataset. * * @param source the source dataset.//w ww.j a v a 2 s . c o m * @param series the series index (zero based). * @param name the name for the new series. * @param period the averaging period. * @param skip the length of the initial skip period. * * @return The dataset. */ public static XYSeries createMovingAverage(XYDataset source, int series, String name, double period, double skip) { ParamChecks.nullNotPermitted(source, "source"); if (period < Double.MIN_VALUE) { throw new IllegalArgumentException("period must be positive."); } if (skip < 0.0) { throw new IllegalArgumentException("skip must be >= 0.0."); } XYSeries result = new XYSeries(name); if (source.getItemCount(series) > 0) { // if the initial averaging period is to be excluded, then // calculate the lowest x-value to have an average calculated... double first = source.getXValue(series, 0) + skip; for (int i = source.getItemCount(series) - 1; i >= 0; i--) { // get the current data item... double x = source.getXValue(series, i); if (x >= first) { // work out the average for the earlier values... int n = 0; double sum = 0.0; double limit = x - period; int offset = 0; boolean finished = false; while (!finished) { if ((i - offset) >= 0) { double xx = source.getXValue(series, i - offset); Number yy = source.getY(series, i - offset); if (xx > limit) { if (yy != null) { sum = sum + yy.doubleValue(); n = n + 1; } } else { finished = true; } } else { finished = true; } offset = offset + 1; } if (n > 0) { result.add(x, sum / n); } else { result.add(x, null); } } } } return result; }
From source file:org.jfree.data.xy.DefaultXYZDataset.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./* w w w. j a v a2 s . c om*/ * * @param seriesKey the series key (<code>null</code> not permitted). * @param data the data (must be an array with length 3, containing three * arrays of equal length, the first containing the x-values, the * second containing the y-values and the third containing the * z-values). */ public void addSeries(Comparable seriesKey, double[][] data) { ParamChecks.nullNotPermitted(seriesKey, "seriesKey"); ParamChecks.nullNotPermitted(data, "data"); if (data.length != 3) { throw new IllegalArgumentException("The 'data' array must have length == 3."); } if (data[0].length != data[1].length || data[0].length != data[2].length) { throw new IllegalArgumentException( "The 'data' array must contain " + "three arrays all having the same 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.general.DatasetUtilities.java
/** * Calculates the total of all the values in a {@link PieDataset}. If * the dataset contains negative or <code>null</code> values, they are * ignored./* w w w .ja va2 s .c o m*/ * * @param dataset the dataset (<code>null</code> not permitted). * * @return The total. */ public static double calculatePieDatasetTotal(PieDataset dataset) { ParamChecks.nullNotPermitted(dataset, "dataset"); List keys = dataset.getKeys(); double totalValue = 0; Iterator iterator = keys.iterator(); while (iterator.hasNext()) { Comparable current = (Comparable) iterator.next(); if (current != null) { Number value = dataset.getValue(current); double v = 0.0; if (value != null) { v = value.doubleValue(); } if (v > 0) { totalValue = totalValue + v; } } } return totalValue; }
From source file:org.jfree.data.xy.XYIntervalSeriesCollection.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). * * @since 1.0.10/* w ww . j a v a 2s . c om*/ */ public void removeSeries(XYIntervalSeries series) { ParamChecks.nullNotPermitted(series, "series"); if (this.data.contains(series)) { series.removeChangeListener(this); this.data.remove(series); fireDatasetChanged(); } }
From source file:org.jfree.data.xy.XYSeriesCollection.java
/** * Returns a series from the collection. * * @param key the key (<code>null</code> not permitted). * * @return The series with the specified key. * * @throws UnknownKeyException if <code>key</code> is not found in the * collection.//from ww w. j av a 2s.com * * @since 1.0.9 */ public XYSeries getSeries(Comparable key) { ParamChecks.nullNotPermitted(key, "key"); Iterator iterator = this.data.iterator(); while (iterator.hasNext()) { XYSeries series = (XYSeries) iterator.next(); if (key.equals(series.getKey())) { return series; } } throw new UnknownKeyException("Key not found: " + key); }