From: <mu...@us...> - 2008-04-10 16:30:10
|
Revision: 836 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=836&view=rev Author: mungady Date: 2008-04-10 09:20:55 -0700 (Thu, 10 Apr 2008) Log Message: ----------- 2008-04-11 David Gilbert <dav...@ob...> * source/org/jfree/data/xy/XIntervalSeries.java (getXLowValue): New method, (getXHighValue): Likewise. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/source/org/jfree/data/xy/XIntervalSeries.java branches/jfreechart-1.0.x-branch/tests/org/jfree/data/xy/junit/XIntervalSeriesTests.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2008-04-09 13:52:58 UTC (rev 835) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2008-04-10 16:20:55 UTC (rev 836) @@ -1,3 +1,9 @@ +2008-04-11 David Gilbert <dav...@ob...> + + * source/org/jfree/data/xy/XIntervalSeries.java + (getXLowValue): New method, + (getXHighValue): Likewise. + 2008-04-08 David Gilbert <dav...@ob...> Bug 1932146: Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/data/xy/XIntervalSeries.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/data/xy/XIntervalSeries.java 2008-04-09 13:52:58 UTC (rev 835) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/data/xy/XIntervalSeries.java 2008-04-10 16:20:55 UTC (rev 836) @@ -2,32 +2,32 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2008, 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 + * 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 + * 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. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. + * [Java is a trademark or registered trademark of Sun Microsystems, Inc. * in the United States and other countries.] * * -------------------- * XIntervalSeries.java * -------------------- - * (C) Copyright 2006, 2007, by Object Refinery Limited. + * (C) Copyright 2006-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -35,6 +35,7 @@ * Changes * ------- * 20-Oct-2006 : Version 1 (DG); + * 11-Apr-2008 : Added getXLowValue() and getXHighValue() methods (DG); * */ @@ -51,10 +52,10 @@ * @see XIntervalSeriesCollection */ public class XIntervalSeries extends ComparableObjectSeries { - + /** - * Creates a new empty series. By default, items added to the series will - * be sorted into ascending order by x-value, and duplicate x-values will + * Creates a new empty series. By default, items added to the series will + * be sorted into ascending order by x-value, and duplicate x-values will * be allowed (these defaults can be modified with another constructor. * * @param key the series key (<code>null</code> not permitted). @@ -62,22 +63,22 @@ public XIntervalSeries(Comparable key) { this(key, true, true); } - + /** - * Constructs a new xy-series that contains no data. You can specify + * Constructs a new xy-series that contains no data. You can specify * whether or not duplicate x-values are allowed for the series. * * @param key the series key (<code>null</code> not permitted). - * @param autoSort a flag that controls whether or not the items in the + * @param autoSort a flag that controls whether or not the items in the * series are sorted. - * @param allowDuplicateXValues a flag that controls whether duplicate + * @param allowDuplicateXValues a flag that controls whether duplicate * x-values are allowed. */ - public XIntervalSeries(Comparable key, boolean autoSort, + public XIntervalSeries(Comparable key, boolean autoSort, boolean allowDuplicateXValues) { super(key, autoSort, allowDuplicateXValues); } - + /** * Adds a data item to the series. * @@ -89,7 +90,7 @@ public void add(double x, double xLow, double xHigh, double y) { super.add(new XIntervalDataItem(x, xLow, xHigh, y), true); } - + /** * Returns the x-value for the specified item. * @@ -101,8 +102,36 @@ XIntervalDataItem item = (XIntervalDataItem) getDataItem(index); return item.getX(); } - + /** + * Returns the lower bound of the x-interval for the specified item. + * + * @param index the item index. + * + * @return The lower bound of the x-interval. + * + * @since 1.0.10 + */ + public double getXLowValue(int index) { + XIntervalDataItem item = (XIntervalDataItem) getDataItem(index); + return item.getXLowValue(); + } + + /** + * Returns the upper bound of the x-interval for the specified item. + * + * @param index the item index. + * + * @return The upper bound of the x-interval. + * + * @since 1.0.10 + */ + public double getXHighValue(int index) { + XIntervalDataItem item = (XIntervalDataItem) getDataItem(index); + return item.getXHighValue(); + } + + /** * Returns the y-value for the specified item. * * @param index the item index. @@ -113,16 +142,16 @@ XIntervalDataItem item = (XIntervalDataItem) getDataItem(index); return item.getYValue(); } - + /** * Returns the data item at the specified index. - * + * * @param index the item index. - * + * * @return The data item. */ public ComparableObjectItem getDataItem(int index) { return super.getDataItem(index); } - + } Modified: branches/jfreechart-1.0.x-branch/tests/org/jfree/data/xy/junit/XIntervalSeriesTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/data/xy/junit/XIntervalSeriesTests.java 2008-04-09 13:52:58 UTC (rev 835) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/data/xy/junit/XIntervalSeriesTests.java 2008-04-10 16:20:55 UTC (rev 836) @@ -2,32 +2,32 @@ * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * - * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. + * (C) Copyright 2000-2008, 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 + * 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 + * 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. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. + * [Java is a trademark or registered trademark of Sun Microsystems, Inc. * in the United States and other countries.] * * ------------------------- * XIntervalSeriesTests.java * ------------------------- - * (C) Copyright 2006, 2007, by Object Refinery Limited and Contributors. + * (C) Copyright 2006-2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -36,6 +36,7 @@ * ------- * 20-Oct-2006 : Version 1, based on XYSeriesTests (DG); * 27-Nov-2007 : Added testClear() method (DG); + * 10-Apr-2008 : Added testGetXLowValue() and testGetXHighValue() (DG); * */ @@ -59,11 +60,11 @@ /** * Tests for the {@link XIntervalSeries} class. */ -public class XIntervalSeriesTests extends TestCase +public class XIntervalSeriesTests extends TestCase implements SeriesChangeListener { SeriesChangeEvent lastEvent; - + public void seriesChanged(SeriesChangeEvent event) { this.lastEvent = event; } @@ -90,29 +91,29 @@ * Confirm that the equals method can distinguish all the required fields. */ public void testEquals() { - + XIntervalSeries s1 = new XIntervalSeries("s1"); XIntervalSeries s2 = new XIntervalSeries("s1"); assertTrue(s1.equals(s2)); - + // seriesKey s1 = new XIntervalSeries("s2"); assertFalse(s1.equals(s2)); s2 = new XIntervalSeries("s2"); assertTrue(s1.equals(s2)); - + // autoSort s1 = new XIntervalSeries("s2", false, true); assertFalse(s1.equals(s2)); s2 = new XIntervalSeries("s2", false, true); assertTrue(s1.equals(s2)); - + // allowDuplicateValues s1 = new XIntervalSeries("s2", false, false); assertFalse(s1.equals(s2)); s2 = new XIntervalSeries("s2", false, false); assertTrue(s1.equals(s2)); - + // add a value s1.add(1.0, 0.5, 1.5, 2.0); assertFalse(s1.equals(s2)); @@ -130,7 +131,7 @@ assertFalse(s1.equals(s2)); s2.remove(new Double(1.0)); assertTrue(s2.equals(s1)); - + } /** @@ -159,7 +160,7 @@ XIntervalSeries s1 = new XIntervalSeries("s1"); s1.add(1.0, 0.5, 1.5, 2.0); XIntervalSeries s2 = null; - + try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); @@ -177,7 +178,7 @@ assertEquals(s1, s2); } - + /** * Simple test for the indexOf() method. */ @@ -188,7 +189,7 @@ s1.add(3.0, 3.0, 3.0, 4.0); assertEquals(0, s1.indexOf(new Double(1.0))); } - + /** * A check for the indexOf() method for an unsorted series. */ @@ -197,9 +198,9 @@ s1.add(1.0, 1.0, 1.0, 2.0); s1.add(3.0, 3.0, 3.0, 3.0); s1.add(2.0, 2.0, 2.0, 2.0); - assertEquals(0, s1.indexOf(new Double(1.0))); - assertEquals(1, s1.indexOf(new Double(3.0))); - assertEquals(2, s1.indexOf(new Double(2.0))); + assertEquals(0, s1.indexOf(new Double(1.0))); + assertEquals(1, s1.indexOf(new Double(3.0))); + assertEquals(2, s1.indexOf(new Double(2.0))); } /** @@ -211,18 +212,18 @@ s1.add(2.0, 2.0, 2.0, 2.0); s1.add(3.0, 3.0, 3.0, 3.0); assertEquals(3, s1.getItemCount()); - + s1.remove(new Double(2.0)); assertEquals(new Double(3.0), s1.getX(1)); - + s1.remove(new Double(1.0)); - assertEquals(new Double(3.0), s1.getX(0)); + assertEquals(new Double(3.0), s1.getX(0)); } private static final double EPSILON = 0.0000000001; - + /** - * When items are added with duplicate x-values, we expect them to remain + * When items are added with duplicate x-values, we expect them to remain * in the order they were added. */ public void testAdditionOfDuplicateXValues() { @@ -238,7 +239,7 @@ assertEquals(4.0, s1.getYValue(3), EPSILON); assertEquals(5.0, s1.getYValue(4), EPSILON); } - + /** * Some checks for the add() method for an UNSORTED series. */ @@ -259,7 +260,7 @@ assertEquals(2.2, series.getYValue(5), EPSILON); assertEquals(1.1, series.getYValue(6), EPSILON); } - + /** * A simple check that the maximumItemCount attribute is working. */ @@ -274,7 +275,7 @@ assertEquals(2.0, s1.getX(0).doubleValue(), EPSILON); assertEquals(3.0, s1.getX(1).doubleValue(), EPSILON); } - + /** * Check that the maximum item count can be applied retrospectively. */ @@ -287,7 +288,7 @@ assertEquals(2.0, s1.getX(0).doubleValue(), EPSILON); assertEquals(3.0, s1.getX(1).doubleValue(), EPSILON); } - + /** * Some checks for the clear() method. */ @@ -302,6 +303,28 @@ s1.clear(); assertNotNull(this.lastEvent); assertTrue(s1.isEmpty()); - } - + } + + /** + * A simple check for getXLowValue(). + */ + public void testGetXLowValue() { + XIntervalSeries s1 = new XIntervalSeries("S1"); + s1.add(1.0, 2.0, 3.0, 4.0); + assertEquals(2.0, s1.getXLowValue(0), EPSILON); + s1.add(2.0, 1.0, 4.0, 2.5); + assertEquals(1.0, s1.getXLowValue(1), EPSILON); + } + + /** + * A simple check for getXHighValue(). + */ + public void testGetXHighValue() { + XIntervalSeries s1 = new XIntervalSeries("S1"); + s1.add(1.0, 2.0, 3.0, 4.0); + assertEquals(3.0, s1.getXHighValue(0), EPSILON); + s1.add(2.0, 1.0, 4.0, 2.5); + assertEquals(4.0, s1.getXHighValue(1), EPSILON); + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |