From: <mu...@us...> - 2008-11-24 09:48:10
|
Revision: 1697 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=1697&view=rev Author: mungady Date: 2008-11-24 09:48:01 +0000 (Mon, 24 Nov 2008) Log Message: ----------- 2008-11-24 David Gilbert <dav...@ob...> Bug 1955483: * source/org/jfree/data/xy/XYSeries.java (addOrUpdate): Check early for duplicates allowed, * tests/org/jfree/data/xy/junit/XYSeriesTests.java (testBug1955483): New test. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/NEWS branches/jfreechart-1.0.x-branch/source/org/jfree/data/xy/XYSeries.java branches/jfreechart-1.0.x-branch/tests/org/jfree/data/xy/junit/XYSeriesTests.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2008-11-24 09:19:36 UTC (rev 1696) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2008-11-24 09:48:01 UTC (rev 1697) @@ -1,3 +1,11 @@ +2008-11-24 David Gilbert <dav...@ob...> + + Bug 1955483: + * source/org/jfree/data/xy/XYSeries.java + (addOrUpdate): Check early for duplicates allowed, + * tests/org/jfree/data/xy/junit/XYSeriesTests.java + (testBug1955483): New test. + 2008-11-18 David Gilbert <dav...@ob...> Bug 2216511: Modified: branches/jfreechart-1.0.x-branch/NEWS =================================================================== --- branches/jfreechart-1.0.x-branch/NEWS 2008-11-24 09:19:36 UTC (rev 1696) +++ branches/jfreechart-1.0.x-branch/NEWS 2008-11-24 09:48:01 UTC (rev 1697) @@ -7,7 +7,8 @@ 2221495 : XYLineAnnotation with dashed stroke; 2216511 : SWTBarChartDemo1 throws RuntimeException; 2121818 : Label link lines for very thin RingPlot; -2113627 : XYStepRenderer item labels. +2113627 : XYStepRenderer item labels; +1955483 : XYSeries.addOrUpdate() problem. Also fixed StackedXYBarRenderer which was ignoring the shadowsVisible attribute. Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/data/xy/XYSeries.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/data/xy/XYSeries.java 2008-11-24 09:19:36 UTC (rev 1696) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/data/xy/XYSeries.java 2008-11-24 09:48:01 UTC (rev 1697) @@ -70,6 +70,7 @@ * 22-Nov-2007 : Reimplemented clone() (DG); * 01-May-2008 : Fixed bug 1955483 in addOrUpdate() method, thanks to * Ted Schwartz (DG); + * 24-Nov-2008 : Further fix for 1955483 (DG); * */ @@ -295,14 +296,18 @@ } /** - * Adds new data to the series and sends a {@link SeriesChangeEvent} to - * all registered listeners. + * Adds a new data item to the series (in the correct position if the + * <code>autoSort</code> flag is set for the series) and sends a + * {@link SeriesChangeEvent} to all registered listeners. * <P> * Throws an exception if the x-value is a duplicate AND the * allowDuplicateXValues flag is false. * * @param x the x-value (<code>null</code> not permitted). * @param y the y-value (<code>null</code> permitted). + * + * @throws SeriesException if the x-value is a duplicate and the + * <code>allowDuplicateXValues</code> flag is not set for this series. */ public void add(Number x, Number y) { // argument checking delegated... @@ -537,8 +542,7 @@ /** * Adds or updates an item in the series and sends a - * {@link org.jfree.data.general.SeriesChangeEvent} to all registered - * listeners. + * {@link SeriesChangeEvent} to all registered listeners. * * @param x the x-value (<code>null</code> not permitted). * @param y the y-value (<code>null</code> permitted). @@ -550,9 +554,15 @@ if (x == null) { throw new IllegalArgumentException("Null 'x' argument."); } + if (this.allowDuplicateXValues) { + add(x, y); + return null; + } + + // if we get to here, we know that duplicate X values are not permitted XYDataItem overwritten = null; int index = indexOf(x); - if (index >= 0 && !this.allowDuplicateXValues) { + if (index >= 0) { XYDataItem existing = (XYDataItem) this.data.get(index); try { overwritten = (XYDataItem) existing.clone(); Modified: branches/jfreechart-1.0.x-branch/tests/org/jfree/data/xy/junit/XYSeriesTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/data/xy/junit/XYSeriesTests.java 2008-11-24 09:19:36 UTC (rev 1696) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/data/xy/junit/XYSeriesTests.java 2008-11-24 09:48:01 UTC (rev 1697) @@ -39,6 +39,7 @@ * 30-Jan-2007 : Fixed some code that won't compile with Java 1.4 (DG); * 31-Oct-2007 : New hashCode() test (DG); * 01-May-2008 : Added testAddOrUpdate3() (DG); + * 24-Nov-2008 : Added testBug1955483() (DG); * */ @@ -469,4 +470,16 @@ assertTrue(Double.isNaN(dataset.getYValue(0, 3))); } + /** + * Another test for the addOrUpdate() method. + */ + public void testBug1955483() { + XYSeries series = new XYSeries("Series", true, true); + series.addOrUpdate(1.0, 1.0); + series.addOrUpdate(1.0, 2.0); + assertEquals(new Double(1.0), series.getY(0)); + assertEquals(new Double(2.0), series.getY(1)); + assertEquals(2, series.getItemCount()); + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |