From: <mu...@us...> - 2007-07-11 10:23:45
|
Revision: 118 http://jfreechart.svn.sourceforge.net/jfreechart/?rev=118&view=rev Author: mungady Date: 2007-07-11 03:23:41 -0700 (Wed, 11 Jul 2007) Log Message: ----------- Reformatting. Modified Paths: -------------- branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/axis/junit/SegmentedTimelineTests.java Modified: branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/axis/junit/SegmentedTimelineTests.java =================================================================== --- branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/axis/junit/SegmentedTimelineTests.java 2007-07-11 10:09:33 UTC (rev 117) +++ branches/jfreechart-1.0.x-branch/tests/org/jfree/chart/axis/junit/SegmentedTimelineTests.java 2007-07-11 10:23:41 UTC (rev 118) @@ -30,7 +30,7 @@ * (C) Copyright 2003-2007, by Bill Kelemen and Contributors. * * Original Author: Bill Kelemen; - * Contributor(s): ; + * Contributor(s): David Gilbert (for Object Refinery Limited); * * $Id: SegmentedTimelineTests.java,v 1.1.2.3 2007/02/02 15:10:21 mungady Exp $ * @@ -80,12 +80,12 @@ private static final int TEST_CYCLE_INC = 55; /** Number of ms in five years */ - private static final long FIVE_YEARS - = 5 * 365 * SegmentedTimeline.DAY_SEGMENT_SIZE; + private static final long FIVE_YEARS = 5 * 365 + * SegmentedTimeline.DAY_SEGMENT_SIZE; /** Number format object for ms tests. */ private static final NumberFormat NUMBER_FORMAT - = NumberFormat.getNumberInstance(); + = NumberFormat.getNumberInstance(); /** Date format object for Monday through Friday tests. */ private static final SimpleDateFormat DATE_FORMAT; @@ -94,40 +94,40 @@ private static final SimpleDateFormat DATE_TIME_FORMAT; /** Some ms exceptions for ms testing. */ - private static final String[] MS_EXCEPTIONS = - {"0", "2", "4", "10", "15", "16", "17", "18", "19", "20", "21", "22", - "23", "24", "47", "58", "100", "101"}; + private static final String[] MS_EXCEPTIONS = {"0", "2", "4", "10", "15", + "16", "17", "18", "19", "20", "21", "22", "23", "24", "47", "58", + "100", "101"}; /** Some ms4 exceptions for ms testing. */ - private static final String[] MS2_BASE_TIMELINE_EXCEPTIONS = - {"0", "8", "16", "24", "32", "40", "48", "56", "64", "72", "80", "88", - "96", "104", "112", "120", "128", "136"}; + private static final String[] MS2_BASE_TIMELINE_EXCEPTIONS = {"0", "8", + "16", "24", "32", "40", "48", "56", "64", "72", "80", "88", "96", + "104", "112", "120", "128", "136"}; /** US non-trading dates in 2000 through 2002 to test exceptions. */ - private static final String[] US_HOLIDAYS = - {"2000-01-17", "2000-02-21", "2000-04-21", "2000-05-29", "2000-07-04", - "2000-09-04", "2000-11-23", "2000-12-25", "2001-01-01", "2001-01-15", - "2001-02-19", "2001-04-13", "2001-05-28", "2001-07-04", "2001-09-03", - "2001-09-11", "2001-09-12", "2001-09-13", "2001-09-14", "2001-11-22", - "2001-12-25", "2002-01-01", "2002-01-21", "2002-02-18", "2002-03-29", - "2002-05-27", "2002-07-04", "2002-09-02", "2002-11-28", "2002-12-25"}; + private static final String[] US_HOLIDAYS = {"2000-01-17", "2000-02-21", + "2000-04-21", "2000-05-29", "2000-07-04", "2000-09-04", "2000-11-23", + "2000-12-25", "2001-01-01", "2001-01-15", "2001-02-19", "2001-04-13", + "2001-05-28", "2001-07-04", "2001-09-03", "2001-09-11", "2001-09-12", + "2001-09-13", "2001-09-14", "2001-11-22", "2001-12-25", "2002-01-01", + "2002-01-21", "2002-02-18", "2002-03-29", "2002-05-27", "2002-07-04", + "2002-09-02", "2002-11-28", "2002-12-25"}; /** Some test exceptions for the fifteen min timeline. */ - private static final String[] FIFTEEN_MIN_EXCEPTIONS = - {"2000-01-10 09:00:00", "2000-01-10 09:15:00", "2000-01-10 09:30:00", - "2000-01-10 09:45:00", "2000-01-10 10:00:00", "2000-01-10 10:15:00", - "2000-02-15 09:00:00", "2000-02-15 09:15:00", "2000-02-15 09:30:00", - "2000-02-15 09:45:00", "2000-02-15 10:00:00", "2000-02-15 10:15:00", - "2000-02-16 11:00:00", "2000-02-16 11:15:00", "2000-02-16 11:30:00", - "2000-02-16 11:45:00", "2000-02-16 12:00:00", "2000-02-16 12:15:00", - "2000-02-16 12:30:00", "2000-02-16 12:45:00", "2000-02-16 01:00:00", - "2000-02-16 01:15:00", "2000-02-16 01:30:00", "2000-02-16 01:45:00", - "2000-05-17 11:45:00", "2000-05-17 12:00:00", "2000-05-17 12:15:00", - "2000-05-17 12:30:00", "2000-05-17 12:45:00", "2000-05-17 01:00:00", - "2000-05-17 01:15:00", "2000-05-17 01:30:00", "2000-05-17 01:45:00", - "2000-05-17 02:00:00", "2000-05-17 02:15:00", "2000-05-17 02:30:00", - "2000-05-17 02:45:00", "2000-05-17 03:00:00", "2000-05-17 03:15:00", - "2000-05-17 03:30:00", "2000-05-17 03:45:00", "2000-05-17 04:00:00"}; + private static final String[] FIFTEEN_MIN_EXCEPTIONS = { + "2000-01-10 09:00:00", "2000-01-10 09:15:00", "2000-01-10 09:30:00", + "2000-01-10 09:45:00", "2000-01-10 10:00:00", "2000-01-10 10:15:00", + "2000-02-15 09:00:00", "2000-02-15 09:15:00", "2000-02-15 09:30:00", + "2000-02-15 09:45:00", "2000-02-15 10:00:00", "2000-02-15 10:15:00", + "2000-02-16 11:00:00", "2000-02-16 11:15:00", "2000-02-16 11:30:00", + "2000-02-16 11:45:00", "2000-02-16 12:00:00", "2000-02-16 12:15:00", + "2000-02-16 12:30:00", "2000-02-16 12:45:00", "2000-02-16 01:00:00", + "2000-02-16 01:15:00", "2000-02-16 01:30:00", "2000-02-16 01:45:00", + "2000-05-17 11:45:00", "2000-05-17 12:00:00", "2000-05-17 12:15:00", + "2000-05-17 12:30:00", "2000-05-17 12:45:00", "2000-05-17 01:00:00", + "2000-05-17 01:15:00", "2000-05-17 01:30:00", "2000-05-17 01:45:00", + "2000-05-17 02:00:00", "2000-05-17 02:15:00", "2000-05-17 02:30:00", + "2000-05-17 02:45:00", "2000-05-17 03:00:00", "2000-05-17 03:15:00", + "2000-05-17 03:30:00", "2000-05-17 03:45:00", "2000-05-17 04:00:00"}; /** Our 1-ms test timeline using 5 included and 2 excluded segments. */ private SegmentedTimeline msTimeline; @@ -262,16 +262,15 @@ // test monday though friday timeline this.mondayFridayTimeline - = SegmentedTimeline.newMondayThroughFridayTimeline(); + = SegmentedTimeline.newMondayThroughFridayTimeline(); // test 9am-4pm Monday through Friday timeline this.fifteenMinTimeline - = SegmentedTimeline.newFifteenMinuteTimeline(); + = SegmentedTimeline.newFifteenMinuteTimeline(); // find first Monday after 2001-01-01 Calendar cal = new GregorianCalendar( - SegmentedTimeline.NO_DST_TIME_ZONE - ); + SegmentedTimeline.NO_DST_TIME_ZONE); cal.set(2001, 0, 1, 0, 0, 0); cal.set(Calendar.MILLISECOND, 0); while (cal.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) { @@ -329,14 +328,10 @@ */ public void testMondayThroughFridaySegmentedTimeline() { // verify attributes set during object construction - assertEquals( - SegmentedTimeline.DAY_SEGMENT_SIZE, - this.mondayFridayTimeline.getSegmentSize() - ); - assertEquals( - SegmentedTimeline.FIRST_MONDAY_AFTER_1900, - this.mondayFridayTimeline.getStartTime() - ); + assertEquals(SegmentedTimeline.DAY_SEGMENT_SIZE, + this.mondayFridayTimeline.getSegmentSize()); + assertEquals(SegmentedTimeline.FIRST_MONDAY_AFTER_1900, + this.mondayFridayTimeline.getStartTime()); assertEquals(5, this.mondayFridayTimeline.getSegmentsIncluded()); assertEquals(2, this.mondayFridayTimeline.getSegmentsExcluded()); } @@ -349,8 +344,8 @@ assertEquals(SegmentedTimeline.FIFTEEN_MINUTE_SEGMENT_SIZE, this.fifteenMinTimeline.getSegmentSize()); assertEquals(SegmentedTimeline.FIRST_MONDAY_AFTER_1900 + 36 - * this.fifteenMinTimeline.getSegmentSize(), - this.fifteenMinTimeline.getStartTime()); + * this.fifteenMinTimeline.getSegmentSize(), + this.fifteenMinTimeline.getStartTime()); assertEquals(28, this.fifteenMinTimeline.getSegmentsIncluded()); assertEquals(68, this.fifteenMinTimeline.getSegmentsExcluded()); } @@ -403,30 +398,21 @@ // get two consecutive segments for various tests SegmentedTimeline.Segment segment1 = timeline.getSegment( - this.monday.getTime().getTime() + testCycle - ); - SegmentedTimeline.Segment segment2 = - timeline.getSegment(segment1.getSegmentEnd() + 1); + this.monday.getTime().getTime() + testCycle); + SegmentedTimeline.Segment segment2 = timeline.getSegment( + segment1.getSegmentEnd() + 1); // verify segments are consecutive and correct - assertEquals( - segment1.getSegmentNumber() + 1, segment2.getSegmentNumber() - ); - assertEquals( - segment1.getSegmentEnd() + 1, segment2.getSegmentStart() - ); - assertEquals( - segment1.getSegmentStart() + timeline.getSegmentSize() - 1, - segment1.getSegmentEnd() - ); - assertEquals( - segment1.getSegmentStart() + timeline.getSegmentSize(), - segment2.getSegmentStart() - ); - assertEquals( - segment1.getSegmentEnd() + timeline.getSegmentSize(), - segment2.getSegmentEnd() - ); + assertEquals(segment1.getSegmentNumber() + 1, + segment2.getSegmentNumber()); + assertEquals(segment1.getSegmentEnd() + 1, + segment2.getSegmentStart()); + assertEquals(segment1.getSegmentStart() + + timeline.getSegmentSize() - 1, segment1.getSegmentEnd()); + assertEquals(segment1.getSegmentStart() + timeline.getSegmentSize(), + segment2.getSegmentStart()); + assertEquals(segment1.getSegmentEnd() + timeline.getSegmentSize(), + segment2.getSegmentEnd()); // verify various indices inside a segment are the same segment long delta; @@ -453,14 +439,12 @@ long end = segment1.getSegmentStart() + timeline.getSegmentSize() - 1; SegmentedTimeline.Segment lastSeg = timeline.getSegment( - segment1.getSegmentStart() - ); + segment1.getSegmentStart()); SegmentedTimeline.Segment seg; for (long i = start; i < end; i += delta) { seg = timeline.getSegment(i); - assertEquals( - lastSeg.getSegmentNumber(), seg.getSegmentNumber() - ); + assertEquals(lastSeg.getSegmentNumber(), + seg.getSegmentNumber()); assertEquals(lastSeg.getSegmentStart(), seg.getSegmentStart()); assertEquals(lastSeg.getSegmentEnd(), seg.getSegmentEnd()); assertTrue(lastSeg.getMillisecond() < seg.getMillisecond()); @@ -527,32 +511,24 @@ if ((seg1.getSegmentEnd() + 1) != seg2.getSegmentStart()) { // logically consecutive segments non-physically consecutive // (with non-contained time in between) - assertTrue( - !timeline.containsDomainRange( - seg1.getSegmentEnd() + 1, seg2.getSegmentStart() - 1 - ) - ); - assertEquals( - 0, (seg2.getSegmentStart() - seg1.getSegmentStart()) % m - ); - assertEquals( - 0, (seg2.getSegmentEnd() - seg1.getSegmentEnd()) % m - ); - assertEquals( - 0, (seg2.getMillisecond() - seg1.getMillisecond()) % m - ); + assertTrue(!timeline.containsDomainRange( + seg1.getSegmentEnd() + 1, + seg2.getSegmentStart() - 1)); + assertEquals(0, (seg2.getSegmentStart() + - seg1.getSegmentStart()) % m); + assertEquals(0, (seg2.getSegmentEnd() + - seg1.getSegmentEnd()) % m); + assertEquals(0, (seg2.getMillisecond() + - seg1.getMillisecond()) % m); } else { // physically consecutive - assertEquals( - seg1.getSegmentStart() + m, seg2.getSegmentStart() - ); - assertEquals( - seg1.getSegmentEnd() + m, seg2.getSegmentEnd() - ); - assertEquals( - seg1.getMillisecond() + m, seg2.getMillisecond() - ); + assertEquals(seg1.getSegmentStart() + m, + seg2.getSegmentStart()); + assertEquals(seg1.getSegmentEnd() + m, + seg2.getSegmentEnd()); + assertEquals(seg1.getMillisecond() + m, + seg2.getMillisecond()); } // test inc(n) method @@ -600,9 +576,8 @@ * on the first monday after 1/1/2000 and for five years. */ public void testMondayThroughFridayIncludedAndExcludedSegments() { - verifyIncludedAndExcludedSegments( - this.mondayFridayTimeline, this.monday.getTime().getTime() - ); + verifyIncludedAndExcludedSegments(this.mondayFridayTimeline, + this.monday.getTime().getTime()); } /** @@ -611,9 +586,8 @@ * on the first monday after 1/1/2000 and for five years. */ public void testFifteenMinIncludedAndExcludedSegments() { - verifyIncludedAndExcludedSegments( - this.fifteenMinTimeline, this.monday9am.getTime().getTime() - ); + verifyIncludedAndExcludedSegments(this.fifteenMinTimeline, + this.monday9am.getTime().getTime()); } /** @@ -667,9 +641,8 @@ * @throws ParseException if there is a parsing error. */ public void testMs2BaseTimelineExceptionSegments() throws ParseException { - verifyExceptionSegments( - this.ms2BaseTimeline, MS2_BASE_TIMELINE_EXCEPTIONS, NUMBER_FORMAT - ); + verifyExceptionSegments(this.ms2BaseTimeline, + MS2_BASE_TIMELINE_EXCEPTIONS, NUMBER_FORMAT); } /** @@ -679,9 +652,8 @@ */ public void testMondayThoughFridayExceptionSegments() throws ParseException { - verifyExceptionSegments( - this.mondayFridayTimeline, US_HOLIDAYS, DATE_FORMAT - ); + verifyExceptionSegments(this.mondayFridayTimeline, + US_HOLIDAYS, DATE_FORMAT); } /** @@ -690,9 +662,8 @@ * @throws ParseException if there is a parsing error. */ public void testFifteenMinExceptionSegments() throws ParseException { - verifyExceptionSegments( - this.fifteenMinTimeline, FIFTEEN_MIN_EXCEPTIONS, DATE_TIME_FORMAT - ); + verifyExceptionSegments(this.fifteenMinTimeline, + FIFTEEN_MIN_EXCEPTIONS, DATE_TIME_FORMAT); } /** @@ -710,28 +681,26 @@ throws ParseException { // fill in the exceptions - long[] exception = verifyFillInExceptions( - timeline, exceptionString, fmt - ); + long[] exception = verifyFillInExceptions(timeline, exceptionString, + fmt); int m = exception.length; // verify list of exceptions assertEquals(exception.length, timeline.getExceptionSegments().size()); - SegmentedTimeline.Segment lastSegment - = timeline.getSegment(exception[m - 1]); + SegmentedTimeline.Segment lastSegment = timeline.getSegment( + exception[m - 1]); for (int i = 0; i < m; i++) { - SegmentedTimeline.Segment segment - = timeline.getSegment(exception[i]); + SegmentedTimeline.Segment segment = timeline.getSegment( + exception[i]); assertTrue(segment.inExceptionSegments()); // include current exception and last one assertEquals(m - i, timeline.getExceptionSegmentCount( - segment.getSegmentStart(), lastSegment.getSegmentEnd())); + segment.getSegmentStart(), lastSegment.getSegmentEnd())); // exclude current exception and last one - assertEquals( - Math.max(0, m - i - 2), timeline.getExceptionSegmentCount( - exception[i] + 1, exception[m - 1] - 1) - ); + assertEquals(Math.max(0, m - i - 2), + timeline.getExceptionSegmentCount(exception[i] + 1, + exception[m - 1] - 1)); } } @@ -756,9 +725,8 @@ * @throws ParseException if there is a parsing error. */ public void testMs2BaseTimelineTranslations() throws ParseException { - verifyFillInExceptions( - this.ms2BaseTimeline, MS2_BASE_TIMELINE_EXCEPTIONS, NUMBER_FORMAT - ); + verifyFillInExceptions(this.ms2BaseTimeline, + MS2_BASE_TIMELINE_EXCEPTIONS, NUMBER_FORMAT); verifyTranslations(this.ms2BaseTimeline, 0); } @@ -768,9 +736,8 @@ * @throws ParseException if there is a parsing error. */ public void testMs2Translations() throws ParseException { - fillInBaseTimelineExceptions( - this.ms2Timeline, MS2_BASE_TIMELINE_EXCEPTIONS, NUMBER_FORMAT - ); + fillInBaseTimelineExceptions(this.ms2Timeline, + MS2_BASE_TIMELINE_EXCEPTIONS, NUMBER_FORMAT); fillInBaseTimelineExclusionsAsExceptions(this.ms2Timeline, 0, 5000); verifyTranslations(this.ms2Timeline, 1); } @@ -780,13 +747,11 @@ * * @throws ParseException if there is a parsing error. */ - public void testMondayThroughFridayTranslations() throws ParseException { - verifyFillInExceptions( - this.mondayFridayTimeline, US_HOLIDAYS, DATE_FORMAT - ); - verifyTranslations( - this.mondayFridayTimeline, this.monday.getTime().getTime() - ); + public void textMondayThroughFridayTranslations() throws ParseException { + verifyFillInExceptions(this.mondayFridayTimeline, US_HOLIDAYS, + DATE_FORMAT); + verifyTranslations(this.mondayFridayTimeline, + this.monday.getTime().getTime()); } /** @@ -795,20 +760,15 @@ * @throws ParseException if there is a parsing error. */ public void testFifteenMinTranslations() throws ParseException { - verifyFillInExceptions( - this.fifteenMinTimeline, FIFTEEN_MIN_EXCEPTIONS, DATE_TIME_FORMAT - ); - fillInBaseTimelineExceptions( - this.fifteenMinTimeline, US_HOLIDAYS, DATE_FORMAT - ); - fillInBaseTimelineExclusionsAsExceptions( - this.fifteenMinTimeline, - this.monday9am.getTime().getTime(), - this.monday9am.getTime().getTime() + FIVE_YEARS - ); - verifyTranslations( - this.fifteenMinTimeline, this.monday9am.getTime().getTime() - ); + verifyFillInExceptions(this.fifteenMinTimeline, + FIFTEEN_MIN_EXCEPTIONS, DATE_TIME_FORMAT); + fillInBaseTimelineExceptions(this.fifteenMinTimeline, + US_HOLIDAYS, DATE_FORMAT); + fillInBaseTimelineExclusionsAsExceptions(this.fifteenMinTimeline, + this.monday9am.getTime().getTime(), + this.monday9am.getTime().getTime() + FIVE_YEARS); + verifyTranslations(this.fifteenMinTimeline, + this.monday9am.getTime().getTime()); } /** @@ -823,12 +783,12 @@ long millisecond = startTest + testCycle * timeline.getSegmentSize(); - SegmentedTimeline.Segment segment - = timeline.getSegment(millisecond); + SegmentedTimeline.Segment segment = timeline.getSegment( + millisecond); for (int i = 0; i < 1000; i++) { - long translatedValue - = timeline.toTimelineValue(segment.getMillisecond()); + long translatedValue = timeline.toTimelineValue( + segment.getMillisecond()); long newValue = timeline.toMillisecond(translatedValue); if (segment.inExcludeSegments() @@ -881,13 +841,12 @@ out.close(); ObjectInput in = new ObjectInputStream( - new ByteArrayInputStream(buffer.toByteArray()) - ); + new ByteArrayInputStream(buffer.toByteArray())); a2 = (SegmentedTimeline) in.readObject(); in.close(); } catch (Exception e) { - System.out.println(e.toString()); + e.printStackTrace(); } assertEquals(a1, a2); } @@ -917,18 +876,16 @@ e = ((NumberFormat) fmt).parse(exceptionString[i]).longValue(); } else { - e = timeline.getTime( - ((SimpleDateFormat) fmt).parse(exceptionString[i]) - ); + e = timeline.getTime(((SimpleDateFormat) fmt) + .parse(exceptionString[i])); } // only add an exception if it is currently an included segment SegmentedTimeline.Segment segment = timeline.getSegment(e); if (segment.inIncludeSegments()) { timeline.addException(e); exceptionList.add(new Long(e)); - assertEquals( - exceptionList.size(), timeline.getExceptionSegments().size() - ); + assertEquals(exceptionList.size(), + timeline.getExceptionSegments().size()); assertTrue(segment.inExceptionSegments()); } } @@ -964,9 +921,8 @@ e = ((NumberFormat) fmt).parse(exceptionString[i]).longValue(); } else { - e = timeline.getTime( - ((SimpleDateFormat) fmt).parse(exceptionString[i]) - ); + e = timeline.getTime(((SimpleDateFormat) fmt) + .parse(exceptionString[i])); } timeline.addBaseTimelineException(e); @@ -974,7 +930,7 @@ // baseTimeline.segment are now exceptions SegmentedTimeline.Segment segment1 = baseTimeline.getSegment(e); for (SegmentedTimeline.Segment segment2 - = timeline.getSegment(segment1.getSegmentStart()); + = timeline.getSegment(segment1.getSegmentStart()); segment2.getSegmentStart() <= segment1.getSegmentEnd(); segment2.inc()) { if (!segment2.inExcludeSegments()) { @@ -1000,8 +956,8 @@ timeline.addBaseTimelineExclusions(from, to); // validate base timeline exclusions added as timeline's esceptions - for (SegmentedTimeline.Segment segment1 - = timeline.getBaseTimeline().getSegment(from); + for (SegmentedTimeline.Segment segment1 = timeline.getBaseTimeline() + .getSegment(from); segment1.getSegmentStart() <= to; segment1.inc()) { @@ -1009,10 +965,10 @@ // verify all timeline segments included in the // baseTimeline.segment are now exceptions - for (SegmentedTimeline.Segment segment2 - = timeline.getSegment(segment1.getSegmentStart()); - segment2.getSegmentStart() <= segment1.getSegmentEnd(); - segment2.inc()) { + for (SegmentedTimeline.Segment segment2 = timeline.getSegment( + segment1.getSegmentStart()); + segment2.getSegmentStart() <= segment1.getSegmentEnd(); + segment2.inc()) { if (!segment2.inExcludeSegments()) { assertTrue(segment2.inExceptionSegments()); } @@ -1031,7 +987,7 @@ l2 = (SegmentedTimeline) l1.clone(); } catch (CloneNotSupportedException e) { - System.err.println("Failed to clone."); + e.printStackTrace(); } assertTrue(l1 != l2); assertTrue(l1.getClass() == l2.getClass()); @@ -1097,13 +1053,12 @@ out.close(); ObjectInput in = new ObjectInputStream( - new ByteArrayInputStream(buffer.toByteArray()) - ); + new ByteArrayInputStream(buffer.toByteArray())); l2 = (SegmentedTimeline) in.readObject(); in.close(); } catch (Exception e) { - System.out.println(e.toString()); + e.printStackTrace(); } boolean b = l1.equals(l2); assertTrue(b); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |