From: <mu...@us...> - 2008-05-28 20:15:52
|
Revision: 1021 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=1021&view=rev Author: mungady Date: 2008-05-28 13:15:31 -0700 (Wed, 28 May 2008) Log Message: ----------- 2008-05-28 David Gilbert <dav...@ob...> * source/org/jfree/data/time/DateRange.java (lowerDate): Changed from Date to long, (upperDate): Likewise, (DateRange(Date, Date)): Updated for field type change, (DateRange(long, long)): Likewise, (getLowerDate): Likewise, (getUpperDate): Likewise, (toString): Likewise, * source/org/jfree/data/time/FixedMillisecond.java (time): Changed from Date to long. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/ChangeLog branches/jfreechart-1.0.x-branch/source/org/jfree/data/time/DateRange.java branches/jfreechart-1.0.x-branch/source/org/jfree/data/time/FixedMillisecond.java branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/DateRangeTests.java branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/FixedMillisecondTests.java Modified: branches/jfreechart-1.0.x-branch/ChangeLog =================================================================== --- branches/jfreechart-1.0.x-branch/ChangeLog 2008-05-28 19:46:09 UTC (rev 1020) +++ branches/jfreechart-1.0.x-branch/ChangeLog 2008-05-28 20:15:31 UTC (rev 1021) @@ -1,3 +1,16 @@ +2008-05-28 David Gilbert <dav...@ob...> + + * source/org/jfree/data/time/DateRange.java + (lowerDate): Changed from Date to long, + (upperDate): Likewise, + (DateRange(Date, Date)): Updated for field type change, + (DateRange(long, long)): Likewise, + (getLowerDate): Likewise, + (getUpperDate): Likewise, + (toString): Likewise, + * source/org/jfree/data/time/FixedMillisecond.java + (time): Changed from Date to long. + 2008-05-26 David Gilbert <dav...@ob...> * source/org/jfree/chart/labels/AbstractXYItemLabelGenerator.java Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/data/time/DateRange.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/data/time/DateRange.java 2008-05-28 19:46:09 UTC (rev 1020) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/data/time/DateRange.java 2008-05-28 20:15:31 UTC (rev 1021) @@ -2,7 +2,7 @@ * 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 * @@ -27,7 +27,7 @@ * -------------- * DateRange.java * -------------- - * (C) Copyright 2002-2007, by Object Refinery Limited and Contributors. + * (C) Copyright 2002-2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Bill Kelemen; @@ -37,6 +37,7 @@ * 22-Apr-2002 : Version 1 based on code by Bill Kelemen (DG); * 07-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 23-Sep-2003 : Minor Javadoc update (DG); + * 28-May-2008 : Fixed problem with immutability (DG); * */ @@ -58,10 +59,10 @@ private static final long serialVersionUID = -4705682568375418157L; /** The lower bound for the range. */ - private Date lowerDate; + private long lowerDate; /** The upper bound for the range. */ - private Date upperDate; + private long upperDate; /** * Default constructor. @@ -78,8 +79,8 @@ */ public DateRange(Date lower, Date upper) { super(lower.getTime(), upper.getTime()); - this.lowerDate = lower; - this.upperDate = upper; + this.lowerDate = lower.getTime(); + this.upperDate = upper.getTime(); } /** @@ -91,8 +92,8 @@ */ public DateRange(double lower, double upper) { super(lower, upper); - this.lowerDate = new Date((long) lower); - this.upperDate = new Date((long) upper); + this.lowerDate = (long) lower; + this.upperDate = (long) upper; } /** @@ -113,7 +114,7 @@ * @return The lower date for the range. */ public Date getLowerDate() { - return this.lowerDate; + return new Date(this.lowerDate); } /** @@ -122,7 +123,7 @@ * @return The upper date for the range. */ public Date getUpperDate() { - return this.upperDate; + return new Date(this.upperDate); } /** @@ -132,8 +133,8 @@ */ public String toString() { DateFormat df = DateFormat.getDateTimeInstance(); - return "[" + df.format(this.lowerDate) + " --> " - + df.format(this.upperDate) + "]"; + return "[" + df.format(getLowerDate()) + " --> " + + df.format(getUpperDate()) + "]"; } } Modified: branches/jfreechart-1.0.x-branch/source/org/jfree/data/time/FixedMillisecond.java =================================================================== --- branches/jfreechart-1.0.x-branch/source/org/jfree/data/time/FixedMillisecond.java 2008-05-28 19:46:09 UTC (rev 1020) +++ branches/jfreechart-1.0.x-branch/source/org/jfree/data/time/FixedMillisecond.java 2008-05-28 20:15:31 UTC (rev 1021) @@ -2,7 +2,7 @@ * 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 * @@ -27,7 +27,7 @@ * --------------------- * FixedMillisecond.java * --------------------- - * (C) Copyright 2002-2007 by Object Refinery Limited. + * (C) Copyright 2002-2008 by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -43,6 +43,7 @@ * 21-Oct-2003 : Added hashCode() method (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 06-Oct-2006 : Added peg() method (DG); + * 28-May-2008 : Fixed immutability problem (DG); * */ @@ -64,7 +65,7 @@ private static final long serialVersionUID = 7867521484545646931L; /** The millisecond. */ - private Date time; + private long time; /** * Constructs a millisecond based on the current system time. @@ -88,7 +89,7 @@ * @param time the time. */ public FixedMillisecond(Date time) { - this.time = time; + this.time = time.getTime(); } /** @@ -97,7 +98,7 @@ * @return The date/time. */ public Date getTime() { - return this.time; + return new Date(this.time); } /** @@ -118,7 +119,7 @@ */ public RegularTimePeriod previous() { RegularTimePeriod result = null; - long t = this.time.getTime(); + long t = this.time; if (t != Long.MIN_VALUE) { result = new FixedMillisecond(t - 1); } @@ -132,7 +133,7 @@ */ public RegularTimePeriod next() { RegularTimePeriod result = null; - long t = this.time.getTime(); + long t = this.time; if (t != Long.MAX_VALUE) { result = new FixedMillisecond(t + 1); } @@ -149,7 +150,7 @@ public boolean equals(Object object) { if (object instanceof FixedMillisecond) { FixedMillisecond m = (FixedMillisecond) object; - return this.time.equals(m.getTime()); + return this.time == m.getFirstMillisecond(); } else { return false; @@ -163,7 +164,7 @@ * @return A hash code. */ public int hashCode() { - return this.time.hashCode(); + return (int) this.time; } /** @@ -184,7 +185,7 @@ // ------------------------------------------- if (o1 instanceof FixedMillisecond) { FixedMillisecond t1 = (FixedMillisecond) o1; - difference = this.time.getTime() - t1.time.getTime(); + difference = this.time - t1.time; if (difference > 0) { result = 1; } @@ -222,7 +223,7 @@ * @return The first millisecond of the time period. */ public long getFirstMillisecond() { - return this.time.getTime(); + return this.time; } @@ -234,7 +235,7 @@ * @return The first millisecond of the time period. */ public long getFirstMillisecond(Calendar calendar) { - return this.time.getTime(); + return this.time; } /** @@ -243,7 +244,7 @@ * @return The last millisecond of the time period. */ public long getLastMillisecond() { - return this.time.getTime(); + return this.time; } /** @@ -254,7 +255,7 @@ * @return The last millisecond of the time period. */ public long getLastMillisecond(Calendar calendar) { - return this.time.getTime(); + return this.time; } /** @@ -263,7 +264,7 @@ * @return The millisecond closest to the middle of the time period. */ public long getMiddleMillisecond() { - return this.time.getTime(); + return this.time; } /** @@ -274,7 +275,7 @@ * @return The millisecond closest to the middle of the time period. */ public long getMiddleMillisecond(Calendar calendar) { - return this.time.getTime(); + return this.time; } /** @@ -283,7 +284,7 @@ * @return The serial index number. */ public long getSerialIndex() { - return this.time.getTime(); + return this.time; } } Modified: branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/DateRangeTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/DateRangeTests.java 2008-05-28 19:46:09 UTC (rev 1020) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/DateRangeTests.java 2008-05-28 20:15:31 UTC (rev 1021) @@ -6,22 +6,22 @@ * * 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.] * * ------------------- @@ -59,7 +59,7 @@ * Some tests for the {@link DateRange} class. */ public class DateRangeTests extends TestCase { - + /** * Returns the tests as a test suite. * @@ -112,24 +112,36 @@ out.close(); ObjectInput in = new ObjectInputStream( - new ByteArrayInputStream(buffer.toByteArray()) - ); + new ByteArrayInputStream(buffer.toByteArray())); r2 = (DateRange) in.readObject(); in.close(); } catch (Exception e) { - System.out.println(e.toString()); + e.printStackTrace(); } assertEquals(r1, r2); } - + /** - * The {@link DateRange} class is immutable, so it doesn't need to + * The {@link DateRange} class is immutable, so it doesn't need to * be cloneable. */ public void testClone() { DateRange r1 = new DateRange(new Date(1000L), new Date(2000L)); assertFalse(r1 instanceof Cloneable); } - + + /** + * Confirm that a DateRange is immutable. + */ + public void testImmutable() { + Date d1 = new Date(10L); + Date d2 = new Date(20L); + DateRange r = new DateRange(d1, d2); + d1.setTime(11L); + assertEquals(new Date(10L), r.getLowerDate()); + r.getUpperDate().setTime(22L); + assertEquals(new Date(20L), r.getUpperDate()); + } + } Modified: branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/FixedMillisecondTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/FixedMillisecondTests.java 2008-05-28 19:46:09 UTC (rev 1020) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/data/time/junit/FixedMillisecondTests.java 2008-05-28 20:15:31 UTC (rev 1021) @@ -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.] * * -------------------------- * FixedMillisecondTests.java * -------------------------- - * (C) Copyright 2002-2007, by Object Refinery Limited. + * (C) Copyright 2002-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; @@ -37,6 +37,7 @@ * 29-Jan-2002 : Version 1 (DG); * 17-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 21-Oct-2003 : Added hashCode test (DG); + * 28-May-2008 : Added test for immutability (DG); * */ @@ -48,6 +49,7 @@ import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; +import java.util.Date; import junit.framework.Test; import junit.framework.TestCase; @@ -93,20 +95,19 @@ out.close(); ObjectInput in = new ObjectInputStream( - new ByteArrayInputStream(buffer.toByteArray()) - ); + new ByteArrayInputStream(buffer.toByteArray())); m2 = (FixedMillisecond) in.readObject(); in.close(); } catch (Exception e) { - System.out.println(e.toString()); + e.printStackTrace(); } assertEquals(m1, m2); } - + /** - * Two objects that are equal are required to return the same hashCode. + * Two objects that are equal are required to return the same hashCode. */ public void testHashcode() { FixedMillisecond m1 = new FixedMillisecond(500000L); @@ -116,9 +117,9 @@ int h2 = m2.hashCode(); assertEquals(h1, h2); } - + /** - * The {@link FixedMillisecond} class is immutable, so should not be + * The {@link FixedMillisecond} class is immutable, so should not be * {@link Cloneable}. */ public void testNotCloneable() { @@ -126,4 +127,13 @@ assertFalse(m instanceof Cloneable); } + /** + * A check for immutability. + */ + public void testImmutability() { + Date d = new Date(20L); + FixedMillisecond fm = new FixedMillisecond(d); + d.setTime(22L); + assertEquals(20L, fm.getFirstMillisecond()); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |