From: <mu...@us...> - 2007-11-12 15:57:49
|
Revision: 495 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=495&view=rev Author: mungady Date: 2007-11-12 07:57:45 -0800 (Mon, 12 Nov 2007) Log Message: ----------- 2007-11-12 David Gilbert <dav...@ob...> * source/org/jfree/data/statistics/DefaultBoxAndWhiskerXYDataset.java (add): Fire dataset change event, (getY): Removed redundant constructor call, (equals): New method override, (clone): Likewise. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/DefaultBoxAndWhiskerXYDataset.java branches/jfreechart-1.0.x-branch/tests/org/jfree/data/statistics/junit/DataStatisticsPackageTests.java Added Paths: ----------- branches/jfreechart-1.0.x-branch/tests/org/jfree/data/statistics/junit/DefaultBoxAndWhiskerXYDatasetTests.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2007-11-12 11:26:58 UTC (rev 494) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2007-11-12 15:57:45 UTC (rev 495) @@ -1,5 +1,13 @@ 2007-11-12 David Gilbert <dav...@ob...> + * source/org/jfree/data/statistics/DefaultBoxAndWhiskerXYDataset.java + (add): Fire dataset change event, + (getY): Removed redundant constructor call, + (equals): New method override, + (clone): Likewise. + +2007-11-12 David Gilbert <dav...@ob...> + * source/org/jfree/chart/plot/XYPlot.java (equals): Added check for domain/rangeTickBandPaint, * source/org/jfree/chart/renderer/xy/AbstractXYItemRenderer.java Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/DefaultBoxAndWhiskerXYDataset.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/DefaultBoxAndWhiskerXYDataset.java 2007-11-12 11:26:58 UTC (rev 494) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/data/statistics/DefaultBoxAndWhiskerXYDataset.java 2007-11-12 15:57:45 UTC (rev 495) @@ -54,6 +54,7 @@ * release (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 02-Feb-2007 : Removed author tags from all over JFreeChart sources (DG); + * 12-Nov-2007 : Implemented equals() and clone() (DG); * */ @@ -65,15 +66,16 @@ import org.jfree.data.Range; import org.jfree.data.RangeInfo; +import org.jfree.data.general.DatasetChangeEvent; import org.jfree.data.xy.AbstractXYDataset; +import org.jfree.util.ObjectUtilities; /** - * A simple implementation of the {@link BoxAndWhiskerXYDataset}. The dataset - * can hold only one series. + * A simple implementation of the {@link BoxAndWhiskerXYDataset} interface. + * This dataset implementation can hold only one series. */ public class DefaultBoxAndWhiskerXYDataset extends AbstractXYDataset - implements BoxAndWhiskerXYDataset, - RangeInfo { + implements BoxAndWhiskerXYDataset, RangeInfo { /** The series key. */ private Comparable seriesKey; @@ -127,11 +129,96 @@ } /** - * Adds an item to the dataset. + * Returns the value used as the outlier coefficient. The outlier + * coefficient gives an indication of the degree of certainty in an + * unskewed distribution. Increasing the coefficient increases the number + * of values included. Currently only used to ensure farout coefficient is + * greater than the outlier coefficient + * + * @return A <code>double</code> representing the value used to calculate + * outliers. + * + * @see #setOutlierCoefficient(double) + */ + public double getOutlierCoefficient() { + return this.outlierCoefficient; + } + + /** + * Sets the value used as the outlier coefficient + * + * @param outlierCoefficient being a <code>double</code> representing the + * value used to calculate outliers. + * + * @see #getOutlierCoefficient() + */ + public void setOutlierCoefficient(double outlierCoefficient) { + this.outlierCoefficient = outlierCoefficient; + } + + /** + * Returns the value used as the farout coefficient. The farout coefficient + * allows the calculation of which values will be off the graph. + * + * @return A <code>double</code> representing the value used to calculate + * farouts. + * + * @see #setFaroutCoefficient(double) + */ + public double getFaroutCoefficient() { + return this.faroutCoefficient; + } + + /** + * Sets the value used as the farouts coefficient. The farout coefficient + * must b greater than the outlier coefficient. * - * @param date the date. - * @param item the item. + * @param faroutCoefficient being a <code>double</code> representing the + * value used to calculate farouts. + * + * @see #getFaroutCoefficient() */ + public void setFaroutCoefficient(double faroutCoefficient) { + + if (faroutCoefficient > getOutlierCoefficient()) { + this.faroutCoefficient = faroutCoefficient; + } + else { + throw new IllegalArgumentException("Farout value must be greater " + + "than the outlier value, which is currently set at: (" + + getOutlierCoefficient() + ")"); + } + } + + /** + * Returns the number of series in the dataset. + * <p> + * This implementation only allows one series. + * + * @return The number of series. + */ + public int getSeriesCount() { + return 1; + } + + /** + * Returns the number of items in the specified series. + * + * @param series the index (zero-based) of the series. + * + * @return The number of items in the specified series. + */ + public int getItemCount(int series) { + return this.dates.size(); + } + + /** + * Adds an item to the dataset and sends a {@link DatasetChangeEvent} to + * all registered listeners. + * + * @param date the date (<code>null</code> not permitted). + * @param item the item (<code>null</code> not permitted). + */ public void add(Date date, BoxAndWhiskerItem item) { this.dates.add(date); this.items.add(item); @@ -155,6 +242,7 @@ } this.rangeBounds = new Range(this.minimumRangeValue.doubleValue(), this.maximumRangeValue.doubleValue()); + fireDatasetChanged(); } /** @@ -214,7 +302,7 @@ * Returns the y-value for one item in a series. * <p> * This method (from the XYDataset interface) is mapped to the - * getMaxNonOutlierValue() method. + * getMeanValue() method. * * @param series the series (zero-based index). * @param item the item (zero-based index). @@ -222,7 +310,7 @@ * @return The y-value. */ public Number getY(int series, int item) { - return new Double(getMeanValue(series, item).doubleValue()); + return getMeanValue(series, item); } /** @@ -379,82 +467,6 @@ } /** - * Returns the value used as the outlier coefficient. The outlier - * coefficient gives an indication of the degree of certainty in an - * unskewed distribution. Increasing the coefficient increases the number - * of values included. Currently only used to ensure farout coefficient is - * greater than the outlier coefficient - * - * @return A <code>double</code> representing the value used to calculate - * outliers. - */ - public double getOutlierCoefficient() { - return this.outlierCoefficient; - } - - /** - * Returns the value used as the farout coefficient. The farout coefficient - * allows the calculation of which values will be off the graph. - * - * @return A <code>double</code> representing the value used to calculate - * farouts. - */ - public double getFaroutCoefficient() { - return this.faroutCoefficient; - } - - /** - * Returns the number of series in the dataset. - * <p> - * This implementation only allows one series. - * - * @return The number of series. - */ - public int getSeriesCount() { - return 1; - } - - /** - * Returns the number of items in the specified series. - * - * @param series the index (zero-based) of the series. - * - * @return The number of items in the specified series. - */ - public int getItemCount(int series) { - return this.dates.size(); - } - - /** - * Sets the value used as the outlier coefficient - * - * @param outlierCoefficient being a <code>double</code> representing the - * value used to calculate outliers. - */ - public void setOutlierCoefficient(double outlierCoefficient) { - this.outlierCoefficient = outlierCoefficient; - } - - /** - * Sets the value used as the farouts coefficient. The farout coefficient - * must b greater than the outlier coefficient. - * - * @param faroutCoefficient being a <code>double</code> representing the - * value used to calculate farouts. - */ - public void setFaroutCoefficient(double faroutCoefficient) { - - if (faroutCoefficient > getOutlierCoefficient()) { - this.faroutCoefficient = faroutCoefficient; - } - else { - throw new IllegalArgumentException("Farout value must be greater " - + "than the outlier value, which is currently set at: (" - + getOutlierCoefficient() + ")"); - } - } - - /** * Returns the minimum y-value in the dataset. * * @param includeInterval a flag that determines whether or not the @@ -497,5 +509,48 @@ public Range getRangeBounds(boolean includeInterval) { return this.rangeBounds; } + + /** + * Tests this dataset for equality with an arbitrary object. + * + * @param obj the object (<code>null</code> permitted). + * + * @return A boolean. + */ + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof DefaultBoxAndWhiskerXYDataset)) { + return false; + } + DefaultBoxAndWhiskerXYDataset that + = (DefaultBoxAndWhiskerXYDataset) obj; + if (!ObjectUtilities.equal(this.seriesKey, that.seriesKey)) { + return false; + } + if (!this.dates.equals(that.dates)) { + return false; + } + if (!this.items.equals(that.items)) { + return false; + } + return true; + } + + /** + * Returns a clone of the plot. + * + * @return A clone. + * + * @throws CloneNotSupportedException if the cloning is not supported. + */ + public Object clone() throws CloneNotSupportedException { + DefaultBoxAndWhiskerXYDataset clone + = (DefaultBoxAndWhiskerXYDataset) super.clone(); + clone.dates = new java.util.ArrayList(this.dates); + clone.items = new java.util.ArrayList(this.items); + return clone; + } } Modified: branches/jfreechart-1.0.x-branch/tests/org/jfree/data/statistics/junit/DataStatisticsPackageTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/data/statistics/junit/DataStatisticsPackageTests.java 2007-11-12 11:26:58 UTC (rev 494) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/data/statistics/junit/DataStatisticsPackageTests.java 2007-11-12 15:57:45 UTC (rev 495) @@ -40,6 +40,7 @@ * 10-Jan-2005 : Added tests for new SimpleHistogramDataset and * SimpleHistogramBin classes (DG); * 18-Jan-2005 : Added main() method (DG); + * 12-Nov-2007 : Added DefaultBoxAndWhiskerXYDatasetTests (DG); * */ @@ -66,6 +67,7 @@ suite.addTestSuite(BoxAndWhiskerCalculatorTests.class); suite.addTestSuite(BoxAndWhiskerItemTests.class); suite.addTestSuite(DefaultBoxAndWhiskerCategoryDatasetTests.class); + suite.addTestSuite(DefaultBoxAndWhiskerXYDatasetTests.class); suite.addTestSuite(DefaultStatisticalCategoryDatasetTests.class); suite.addTestSuite(HistogramBinTests.class); suite.addTestSuite(HistogramDatasetTests.class); Added: branches/jfreechart-1.0.x-branch/tests/org/jfree/data/statistics/junit/DefaultBoxAndWhiskerXYDatasetTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/data/statistics/junit/DefaultBoxAndWhiskerXYDatasetTests.java (rev 0) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/data/statistics/junit/DefaultBoxAndWhiskerXYDatasetTests.java 2007-11-12 15:57:45 UTC (rev 495) @@ -0,0 +1,220 @@ +/* =========================================================== + * JFreeChart : a free chart library for the Java(tm) platform + * =========================================================== + * + * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. + * + * Project Info: http://www.jfree.org/jfreechart/index.html + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * [Java is a trademark or registered trademark of Sun Microsystems, Inc. + * in the United States and other countries.] + * + * --------------------------------------- + * DefaultBoxAndWhiskerXYDatasetTests.java + * --------------------------------------- + * (C) Copyright 2007, by Object Refinery Limited and Contributors. + * + * Original Author: David Gilbert (for Object Refinery Limited); + * Contributor(s): -; + * + * Changes + * ------- + * 12-Nov-2007 : Version 1 (DG); + * + */ + +package org.jfree.data.statistics.junit; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectInput; +import java.io.ObjectInputStream; +import java.io.ObjectOutput; +import java.io.ObjectOutputStream; +import java.util.ArrayList; +import java.util.Date; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.jfree.data.Range; +import org.jfree.data.statistics.BoxAndWhiskerItem; +import org.jfree.data.statistics.DefaultBoxAndWhiskerXYDataset; + +/** + * Tests for the {@link DefaultBoxAndWhiskerXYDataset} class. + */ +public class DefaultBoxAndWhiskerXYDatasetTests extends TestCase { + + /** + * Returns the tests as a test suite. + * + * @return The test suite. + */ + public static Test suite() { + return new TestSuite(DefaultBoxAndWhiskerXYDatasetTests.class); + } + + /** + * Constructs a new set of tests. + * + * @param name the name of the tests. + */ + public DefaultBoxAndWhiskerXYDatasetTests(String name) { + super(name); + } + + /** + * Confirm that the equals method can distinguish all the required fields. + */ + public void testEquals() { + DefaultBoxAndWhiskerXYDataset d1 = new DefaultBoxAndWhiskerXYDataset( + "Series"); + DefaultBoxAndWhiskerXYDataset d2 = new DefaultBoxAndWhiskerXYDataset( + "Series"); + assertTrue(d1.equals(d2)); + + d1.add(new Date(1L), new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, 5.0, + 6.0, 7.0, 8.0, new ArrayList())); + assertFalse(d1.equals(d2)); + d2.add(new Date(1L), new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, 5.0, + 6.0, 7.0, 8.0, new ArrayList())); + assertTrue(d1.equals(d2)); + } + + /** + * Serialize an instance, restore it, and check for equality. + */ + public void testSerialization() { + + DefaultBoxAndWhiskerXYDataset d1 = new DefaultBoxAndWhiskerXYDataset( + "Series"); + d1.add(new Date(1L), new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, 5.0, + 6.0, 7.0, 8.0, new ArrayList())); + DefaultBoxAndWhiskerXYDataset d2 = null; + + try { + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + ObjectOutput out = new ObjectOutputStream(buffer); + out.writeObject(d1); + out.close(); + + ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( + buffer.toByteArray())); + d2 = (DefaultBoxAndWhiskerXYDataset) in.readObject(); + in.close(); + } + catch (Exception e) { + e.printStackTrace(); + } + assertEquals(d1, d2); + + // test independence + d1.add(new Date(2L), new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, 5.0, + 6.0, 7.0, 8.0, new ArrayList())); + assertFalse(d1.equals(d2)); + } + + /** + * Confirm that cloning works. + */ + public void testCloning() { + DefaultBoxAndWhiskerXYDataset d1 = new DefaultBoxAndWhiskerXYDataset( + "Series"); + d1.add(new Date(1L), new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, 5.0, + 6.0, 7.0, 8.0, new ArrayList())); + DefaultBoxAndWhiskerXYDataset d2 = null; + try { + d2 = (DefaultBoxAndWhiskerXYDataset) d1.clone(); + } + catch (CloneNotSupportedException e) { + e.printStackTrace(); + } + assertTrue(d1 != d2); + assertTrue(d1.getClass() == d2.getClass()); + assertTrue(d1.equals(d2)); + + // test independence + d1.add(new Date(2L), new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, 5.0, + 6.0, 7.0, 8.0, new ArrayList())); + assertFalse(d1.equals(d2)); + } + + private static final double EPSILON = 0.0000000001; + + /** + * Some checks for the add() method. + */ + public void testAdd() { + DefaultBoxAndWhiskerXYDataset dataset + = new DefaultBoxAndWhiskerXYDataset("S1"); + BoxAndWhiskerItem item1 = new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, + 5.0, 6.0, 7.0, 8.0, new ArrayList()); + dataset.add(new Date(33L), item1); + + assertEquals(1.0, dataset.getY(0, 0).doubleValue(), EPSILON); + assertEquals(1.0, dataset.getMeanValue(0, 0).doubleValue(), EPSILON); + assertEquals(2.0, dataset.getMedianValue(0, 0).doubleValue(), EPSILON); + assertEquals(3.0, dataset.getQ1Value(0, 0).doubleValue(), EPSILON); + assertEquals(4.0, dataset.getQ3Value(0, 0).doubleValue(), EPSILON); + assertEquals(5.0, dataset.getMinRegularValue(0, 0).doubleValue(), + EPSILON); + assertEquals(6.0, dataset.getMaxRegularValue(0, 0).doubleValue(), + EPSILON); + assertEquals(7.0, dataset.getMinOutlier(0, 0).doubleValue(), EPSILON); + assertEquals(8.0, dataset.getMaxOutlier(0, 0).doubleValue(), EPSILON); + assertEquals(new Range(5.0, 6.0), dataset.getRangeBounds(false)); + } + + /** + * Some basic checks for the constructor. + */ + public void testConstructor() { + DefaultBoxAndWhiskerXYDataset dataset + = new DefaultBoxAndWhiskerXYDataset("S1"); + assertEquals(1, dataset.getSeriesCount()); + assertEquals(0, dataset.getItemCount(0)); + assertTrue(Double.isNaN(dataset.getRangeLowerBound(false))); + assertTrue(Double.isNaN(dataset.getRangeUpperBound(false))); + } + + /** + * Some checks for the getRangeBounds() method. + */ + public void testGetRangeBounds() { + DefaultBoxAndWhiskerXYDataset d1 + = new DefaultBoxAndWhiskerXYDataset("S"); + d1.add(new Date(1L), new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, 5.0, + 6.0, 7.0, 8.0, new ArrayList())); + assertEquals(new Range(5.0, 6.0), d1.getRangeBounds(false)); + assertEquals(new Range(5.0, 6.0), d1.getRangeBounds(true)); + + d1.add(new Date(1L), new BoxAndWhiskerItem(1.5, 2.5, 3.5, 4.5, 5.5, + 6.5, 7.5, 8.5, new ArrayList())); + assertEquals(new Range(5.0, 6.5), d1.getRangeBounds(false)); + assertEquals(new Range(5.0, 6.5), d1.getRangeBounds(true)); + + d1.add(new Date(2L), new BoxAndWhiskerItem(2.5, 3.5, 4.5, 5.5, 6.5, + 7.5, 8.5, 9.5, new ArrayList())); + assertEquals(new Range(5.0, 7.5), d1.getRangeBounds(false)); + assertEquals(new Range(5.0, 7.5), d1.getRangeBounds(true)); + } + + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |