org.jfree.chart.axis.SegmentedTimeline Java Examples
The following examples show how to use
org.jfree.chart.axis.SegmentedTimeline.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SegmentedTimelineTests2.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Creates a timeline from 9am on Thursday 25 March 2004 to 5pm on * Tuesday 30 March 2004, for the UK locale. * * @return A timeline. */ private SegmentedTimeline getTimeline() { Calendar cal = Calendar.getInstance(Locale.UK); cal.set(Calendar.YEAR, 2004); cal.set(Calendar.MONTH, Calendar.MARCH); cal.set(Calendar.DAY_OF_MONTH, 25); cal.set(Calendar.HOUR_OF_DAY, 9); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); Date from = cal.getTime(); cal = Calendar.getInstance(Locale.UK); cal.set(Calendar.YEAR, 2004); cal.set(Calendar.MONTH, Calendar.MARCH); cal.set(Calendar.DAY_OF_MONTH, 30); cal.set(Calendar.HOUR_OF_DAY, 17); cal.set(Calendar.MINUTE, 30); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); Date to = cal.getTime(); return getTimeline(from, to); }
Example #2
Source File: SegmentedTimelineTests2.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Creates a timeline from 9am on Thursday 25 March 2004 to 5pm on * Tuesday 30 March 2004, for the UK locale. * * @return A timeline. */ private SegmentedTimeline getTimeline() { Calendar cal = Calendar.getInstance(Locale.UK); cal.set(Calendar.YEAR, 2004); cal.set(Calendar.MONTH, Calendar.MARCH); cal.set(Calendar.DAY_OF_MONTH, 25); cal.set(Calendar.HOUR_OF_DAY, 9); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); Date from = cal.getTime(); cal = Calendar.getInstance(Locale.UK); cal.set(Calendar.YEAR, 2004); cal.set(Calendar.MONTH, Calendar.MARCH); cal.set(Calendar.DAY_OF_MONTH, 30); cal.set(Calendar.HOUR_OF_DAY, 17); cal.set(Calendar.MINUTE, 30); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); Date to = cal.getTime(); return getTimeline(from, to); }
Example #3
Source File: SegmentedTimelineTests.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Tests that a timeline's included and excluded segments are being * calculated correctly. * * @param timeline the timeline to verify * @param n the first segment number to start verifying */ public void verifyIncludedAndExcludedSegments(SegmentedTimeline timeline, long n) { // clear any exceptions in this timeline timeline.setExceptionSegments(new java.util.ArrayList()); // test some included and excluded segments SegmentedTimeline.Segment segment = timeline.getSegment(n); for (int i = 0; i < 1000; i++) { int d = (i % timeline.getGroupSegmentCount()); if (d < timeline.getSegmentsIncluded()) { // should be an included segment assertTrue(segment.inIncludeSegments()); assertTrue(!segment.inExcludeSegments()); assertTrue(!segment.inExceptionSegments()); } else { // should be an excluded segment assertTrue(!segment.inIncludeSegments()); assertTrue(segment.inExcludeSegments()); assertTrue(!segment.inExceptionSegments()); } segment.inc(); } }
Example #4
Source File: SegmentedTimelineTests2.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Test 4 checks 9.30am Friday 26 March 2004 (+ 1 millisecond) converts to * a timeline value and back again correctly. This is prior to Daylight * Saving. */ public void test4() { TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Calendar cal = Calendar.getInstance(Locale.UK); cal.set(Calendar.YEAR, 2004); cal.set(Calendar.MONTH, Calendar.MARCH); cal.set(Calendar.DAY_OF_MONTH, 26); cal.set(Calendar.HOUR_OF_DAY, 9); cal.set(Calendar.MINUTE, 30); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 1); Date date = cal.getTime(); SegmentedTimeline timeline = getTimeline(); long value = timeline.toTimelineValue(date); long ms = timeline.toMillisecond(value); Calendar cal2 = Calendar.getInstance(Locale.UK); cal2.setTime(new Date(ms)); Date reverted = cal2.getTime(); assertTrue( "test4", value == (900000 * 34 + 900000 * 2 + 1) && date.getTime() == reverted.getTime() ); TimeZone.setDefault(savedZone); }
Example #5
Source File: SegmentedTimelineTests.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Tests that a timeline's included and excluded segments are being * calculated correctly. * * @param timeline the timeline to verify * @param n the first segment number to start verifying */ public void verifyIncludedAndExcludedSegments(SegmentedTimeline timeline, long n) { // clear any exceptions in this timeline timeline.setExceptionSegments(new java.util.ArrayList()); // test some included and excluded segments SegmentedTimeline.Segment segment = timeline.getSegment(n); for (int i = 0; i < 1000; i++) { int d = (i % timeline.getGroupSegmentCount()); if (d < timeline.getSegmentsIncluded()) { // should be an included segment assertTrue(segment.inIncludeSegments()); assertTrue(!segment.inExcludeSegments()); assertTrue(!segment.inExceptionSegments()); } else { // should be an excluded segment assertTrue(!segment.inIncludeSegments()); assertTrue(segment.inExcludeSegments()); assertTrue(!segment.inExceptionSegments()); } segment.inc(); } }
Example #6
Source File: SegmentedTimelineTests2.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Test 4 checks 9.30am Friday 26 March 2004 (+ 1 millisecond) converts to * a timeline value and back again correctly. This is prior to Daylight * Saving. */ public void test4() { TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Calendar cal = Calendar.getInstance(Locale.UK); cal.set(Calendar.YEAR, 2004); cal.set(Calendar.MONTH, Calendar.MARCH); cal.set(Calendar.DAY_OF_MONTH, 26); cal.set(Calendar.HOUR_OF_DAY, 9); cal.set(Calendar.MINUTE, 30); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 1); Date date = cal.getTime(); SegmentedTimeline timeline = getTimeline(); long value = timeline.toTimelineValue(date); long ms = timeline.toMillisecond(value); Calendar cal2 = Calendar.getInstance(Locale.UK); cal2.setTime(new Date(ms)); Date reverted = cal2.getTime(); assertTrue( "test4", value == (900000 * 34 + 900000 * 2 + 1) && date.getTime() == reverted.getTime() ); TimeZone.setDefault(savedZone); }
Example #7
Source File: SegmentedTimelineTests.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Adds an array of exceptions relative to the base timeline. * * @param timeline The timeline where the exceptions will be stored * @param exceptionString The exceptions to load * @param fmt The date formatter to use to parse each exceptions[i] value * @throws ParseException If there is any exception parsing each * exceptions[i] value. */ private void fillInBaseTimelineExceptions(SegmentedTimeline timeline, String[] exceptionString, Format fmt) throws ParseException { SegmentedTimeline baseTimeline = timeline.getBaseTimeline(); for (int i = 0; i < exceptionString.length; i++) { long e; if (fmt instanceof NumberFormat) { e = ((NumberFormat) fmt).parse(exceptionString[i]).longValue(); } else { e = timeline.getTime(((SimpleDateFormat) fmt) .parse(exceptionString[i])); } timeline.addBaseTimelineException(e); // verify all timeline segments included in the // baseTimeline.segment are now exceptions SegmentedTimeline.Segment segment1 = baseTimeline.getSegment(e); for (SegmentedTimeline.Segment segment2 = timeline.getSegment(segment1.getSegmentStart()); segment2.getSegmentStart() <= segment1.getSegmentEnd(); segment2.inc()) { if (!segment2.inExcludeSegments()) { assertTrue(segment2.inExceptionSegments()); } } } }
Example #8
Source File: DateAxisTests.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Confirm that the equals method can distinguish all the required fields. */ public void testEquals() { DateAxis a1 = new DateAxis("Test"); DateAxis a2 = new DateAxis("Test"); assertTrue(a1.equals(a2)); assertFalse(a1.equals(null)); assertFalse(a1.equals("Some non-DateAxis object")); // tickUnit a1.setTickUnit(new DateTickUnit(DateTickUnit.DAY, 7)); assertFalse(a1.equals(a2)); a2.setTickUnit(new DateTickUnit(DateTickUnit.DAY, 7)); assertTrue(a1.equals(a2)); // dateFormatOverride a1.setDateFormatOverride(new SimpleDateFormat("yyyy")); assertFalse(a1.equals(a2)); a2.setDateFormatOverride(new SimpleDateFormat("yyyy")); assertTrue(a1.equals(a2)); // tickMarkPosition a1.setTickMarkPosition(DateTickMarkPosition.END); assertFalse(a1.equals(a2)); a2.setTickMarkPosition(DateTickMarkPosition.END); assertTrue(a1.equals(a2)); // timeline a1.setTimeline(SegmentedTimeline.newMondayThroughFridayTimeline()); assertFalse(a1.equals(a2)); a2.setTimeline(SegmentedTimeline.newMondayThroughFridayTimeline()); assertTrue(a1.equals(a2)); }
Example #9
Source File: DateAxisTests.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Confirm that the equals method can distinguish all the required fields. */ public void testEquals() { DateAxis a1 = new DateAxis("Test"); DateAxis a2 = new DateAxis("Test"); assertTrue(a1.equals(a2)); assertFalse(a1.equals(null)); assertFalse(a1.equals("Some non-DateAxis object")); // tickUnit a1.setTickUnit(new DateTickUnit(DateTickUnitType.DAY, 7)); assertFalse(a1.equals(a2)); a2.setTickUnit(new DateTickUnit(DateTickUnitType.DAY, 7)); assertTrue(a1.equals(a2)); // dateFormatOverride a1.setDateFormatOverride(new SimpleDateFormat("yyyy")); assertFalse(a1.equals(a2)); a2.setDateFormatOverride(new SimpleDateFormat("yyyy")); assertTrue(a1.equals(a2)); // tickMarkPosition a1.setTickMarkPosition(DateTickMarkPosition.END); assertFalse(a1.equals(a2)); a2.setTickMarkPosition(DateTickMarkPosition.END); assertTrue(a1.equals(a2)); // timeline a1.setTimeline(SegmentedTimeline.newMondayThroughFridayTimeline()); assertFalse(a1.equals(a2)); a2.setTimeline(SegmentedTimeline.newMondayThroughFridayTimeline()); assertTrue(a1.equals(a2)); }
Example #10
Source File: SegmentedTimelineTests.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Tests that the factory method that creates Monday through Friday * segmented timeline does so correctly. */ 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(5, this.mondayFridayTimeline.getSegmentsIncluded()); assertEquals(2, this.mondayFridayTimeline.getSegmentsExcluded()); }
Example #11
Source File: SegmentedTimelineTests.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Tests that the factory method that creates a 15-min 9:00 AM 4:00 PM * segmented axis does so correctly. */ public void testFifteenMinSegmentedTimeline() { assertEquals(SegmentedTimeline.FIFTEEN_MINUTE_SEGMENT_SIZE, this.fifteenMinTimeline.getSegmentSize()); assertEquals(SegmentedTimeline.FIRST_MONDAY_AFTER_1900 + 36 * this.fifteenMinTimeline.getSegmentSize(), this.fifteenMinTimeline.getStartTime()); assertEquals(28, this.fifteenMinTimeline.getSegmentsIncluded()); assertEquals(68, this.fifteenMinTimeline.getSegmentsExcluded()); }
Example #12
Source File: SegmentedTimelineTests2.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Test 7 checks 9am Monday 29 March 2004 converts to a timeline value and * back again correctly. This is during Daylight Saving. */ public void test7() { TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Calendar cal = Calendar.getInstance(Locale.UK); cal.set(Calendar.YEAR, 2004); cal.set(Calendar.MONTH, Calendar.MARCH); cal.set(Calendar.DAY_OF_MONTH, 29); cal.set(Calendar.HOUR_OF_DAY, 9); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); Date date = cal.getTime(); SegmentedTimeline timeline = getTimeline(); long value = timeline.toTimelineValue(date); long ms = timeline.toMillisecond(value); Calendar cal2 = Calendar.getInstance(Locale.UK); cal2.setTime(new Date(ms)); Date reverted = cal2.getTime(); Calendar expectedReverted = Calendar.getInstance(); expectedReverted.set(Calendar.YEAR, 2004); expectedReverted.set(Calendar.MONTH, Calendar.MARCH); expectedReverted.set(Calendar.DAY_OF_MONTH, 29); expectedReverted.set(Calendar.HOUR_OF_DAY, 9); expectedReverted.set(Calendar.MINUTE, 0); expectedReverted.set(Calendar.SECOND, 0); expectedReverted.set(Calendar.MILLISECOND, 0); assertTrue( "test7", value == (900000 * 34 * 2) && expectedReverted.getTime().getTime() == reverted.getTime() ); TimeZone.setDefault(savedZone); }
Example #13
Source File: SegmentedTimelineTests2.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Test 6 checks that 9am on Sunday 28 March 2004 converts to the timeline * value and back again correctly. Note that Saturday and Sunday are * excluded from the timeline, so we expect the value to map to 9am on * Monday 29 March 2004. This is during daylight saving. */ public void test6() { TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Calendar cal = Calendar.getInstance(Locale.UK); cal.set(Calendar.YEAR, 2004); cal.set(Calendar.MONTH, Calendar.MARCH); cal.set(Calendar.DAY_OF_MONTH, 28); cal.set(Calendar.HOUR_OF_DAY, 9); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); Date date = cal.getTime(); SegmentedTimeline timeline = getTimeline(); long value = timeline.toTimelineValue(date); long ms = timeline.toMillisecond(value); Calendar cal2 = Calendar.getInstance(Locale.UK); cal2.setTime(new Date(ms)); Date reverted = cal2.getTime(); Calendar expectedReverted = Calendar.getInstance(Locale.UK); expectedReverted.set(Calendar.YEAR, 2004); expectedReverted.set(Calendar.MONTH, Calendar.MARCH); expectedReverted.set(Calendar.DAY_OF_MONTH, 29); expectedReverted.set(Calendar.HOUR_OF_DAY, 9); expectedReverted.set(Calendar.MINUTE, 0); expectedReverted.set(Calendar.SECOND, 0); expectedReverted.set(Calendar.MILLISECOND, 0); assertTrue( "test6", value == (900000 * 34 * 2) && expectedReverted.getTime().getTime() == reverted.getTime() ); TimeZone.setDefault(savedZone); }
Example #14
Source File: SegmentedTimelineTests.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Tests methods related to adding exceptions. * * @param timeline the timeline to verify * @param exceptionString array of Strings that represent the exceptions * @param fmt Format object that can parse the exceptionString strings * * @throws ParseException if there is a parsing error. */ public void verifyExceptionSegments(SegmentedTimeline timeline, String[] exceptionString, Format fmt) throws ParseException { // fill in the exceptions 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]); for (int i = 0; i < m; 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())); // exclude current exception and last one assertEquals(Math.max(0, m - i - 2), timeline.getExceptionSegmentCount(exception[i] + 1, exception[m - 1] - 1)); } }
Example #15
Source File: SegmentedTimelineTests.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Tests translations between timelines. * * @param timeline the timeline to use for verifications. * @param startTest ??. */ public void verifyTranslations(SegmentedTimeline timeline, long startTest) { for (long testCycle = TEST_CYCLE_START; testCycle < TEST_CYCLE_END; testCycle += TEST_CYCLE_INC) { long millisecond = startTest + testCycle * timeline.getSegmentSize(); SegmentedTimeline.Segment segment = timeline.getSegment( millisecond); for (int i = 0; i < 1000; i++) { long translatedValue = timeline.toTimelineValue( segment.getMillisecond()); long newValue = timeline.toMillisecond(translatedValue); if (segment.inExcludeSegments() || segment.inExceptionSegments()) { // the reverse transformed value will be in the start of the // next non-excluded and non-exception segment SegmentedTimeline.Segment tempSegment = segment.copy(); tempSegment.moveIndexToStart(); do { tempSegment.inc(); } while (!tempSegment.inIncludeSegments()); assertEquals(tempSegment.getMillisecond(), newValue); } else { assertEquals(segment.getMillisecond(), newValue); } segment.inc(); } } }
Example #16
Source File: SegmentedTimelineTests.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Serialize an instance, restore it, and check for equality. */ public void testSerialization() { verifySerialization(this.msTimeline); verifySerialization(this.ms2Timeline); verifySerialization(this.ms2BaseTimeline); verifySerialization(SegmentedTimeline.newMondayThroughFridayTimeline()); verifySerialization(SegmentedTimeline.newFifteenMinuteTimeline()); }
Example #17
Source File: SegmentedTimelineTests.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Adds new exceptions to a timeline. The exceptions are the excluded * segments from its base timeline. * * @param timeline the timeline. * @param from the start. * @param to the end. */ private void fillInBaseTimelineExclusionsAsExceptions( SegmentedTimeline timeline, long from, long to) { // add the base timeline exclusions as timeline's esceptions timeline.addBaseTimelineExclusions(from, to); // validate base timeline exclusions added as timeline's esceptions for (SegmentedTimeline.Segment segment1 = timeline.getBaseTimeline() .getSegment(from); segment1.getSegmentStart() <= to; segment1.inc()) { if (segment1.inExcludeSegments()) { // 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()) { if (!segment2.inExcludeSegments()) { assertTrue(segment2.inExceptionSegments()); } } } } }
Example #18
Source File: SegmentedTimelineTests.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Two objects that are equal are required to return the same hashCode. */ public void testHashCode() { SegmentedTimeline l1 = new SegmentedTimeline(1000, 5, 2); SegmentedTimeline l2 = new SegmentedTimeline(1000, 5, 2); assertTrue(l1.equals(l2)); int h1 = l1.hashCode(); int h2 = l2.hashCode(); assertEquals(h1, h2); }
Example #19
Source File: SegmentedTimelineTests.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Tests a basic segmented timeline. */ public void testBasicSegmentedTimeline() { SegmentedTimeline stl = new SegmentedTimeline(10, 2, 3); stl.setStartTime(946684800000L); // 1-Jan-2000 assertFalse(stl.containsDomainValue(946684799999L)); assertTrue(stl.containsDomainValue(946684800000L)); assertTrue(stl.containsDomainValue(946684800019L)); assertFalse(stl.containsDomainValue(946684800020L)); assertFalse(stl.containsDomainValue(946684800049L)); assertTrue(stl.containsDomainValue(946684800050L)); assertTrue(stl.containsDomainValue(946684800069L)); assertFalse(stl.containsDomainValue(946684800070L)); assertFalse(stl.containsDomainValue(946684800099L)); assertTrue(stl.containsDomainValue(946684800100L)); assertEquals(0, stl.toTimelineValue(946684800000L)); assertEquals(19, stl.toTimelineValue(946684800019L)); assertEquals(20, stl.toTimelineValue(946684800020L)); assertEquals(20, stl.toTimelineValue(946684800049L)); assertEquals(20, stl.toTimelineValue(946684800050L)); assertEquals(39, stl.toTimelineValue(946684800069L)); assertEquals(40, stl.toTimelineValue(946684800070L)); assertEquals(40, stl.toTimelineValue(946684800099L)); assertEquals(40, stl.toTimelineValue(946684800100L)); assertEquals(946684800000L, stl.toMillisecond(0)); assertEquals(946684800019L, stl.toMillisecond(19)); assertEquals(946684800050L, stl.toMillisecond(20)); assertEquals(946684800069L, stl.toMillisecond(39)); assertEquals(946684800100L, stl.toMillisecond(40)); }
Example #20
Source File: SegmentedTimelineTests.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Tests a basic time line with one exception. */ public void testSegmentedTimelineWithException1() { SegmentedTimeline stl = new SegmentedTimeline(10, 2, 3); stl.setStartTime(946684800000L); // 1-Jan-2000 stl.addException(946684800050L); assertFalse(stl.containsDomainValue(946684799999L)); assertTrue(stl.containsDomainValue(946684800000L)); assertTrue(stl.containsDomainValue(946684800019L)); assertFalse(stl.containsDomainValue(946684800020L)); assertFalse(stl.containsDomainValue(946684800049L)); assertFalse(stl.containsDomainValue(946684800050L)); assertFalse(stl.containsDomainValue(946684800059L)); assertTrue(stl.containsDomainValue(946684800060L)); assertTrue(stl.containsDomainValue(946684800069L)); assertFalse(stl.containsDomainValue(946684800070L)); assertFalse(stl.containsDomainValue(946684800099L)); assertTrue(stl.containsDomainValue(946684800100L)); //long v = stl.toTimelineValue(946684800020L); assertEquals(0, stl.toTimelineValue(946684800000L)); assertEquals(19, stl.toTimelineValue(946684800019L)); assertEquals(20, stl.toTimelineValue(946684800020L)); assertEquals(20, stl.toTimelineValue(946684800049L)); assertEquals(20, stl.toTimelineValue(946684800050L)); assertEquals(29, stl.toTimelineValue(946684800069L)); assertEquals(30, stl.toTimelineValue(946684800070L)); assertEquals(30, stl.toTimelineValue(946684800099L)); assertEquals(30, stl.toTimelineValue(946684800100L)); assertEquals(946684800000L, stl.toMillisecond(0)); assertEquals(946684800019L, stl.toMillisecond(19)); assertEquals(946684800060L, stl.toMillisecond(20)); assertEquals(946684800069L, stl.toMillisecond(29)); assertEquals(946684800100L, stl.toMillisecond(30)); }
Example #21
Source File: SegmentedTimelineTests2.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Test 1 checks 9am Friday 26 March 2004 converts to a timeline value and * back again correctly. This is prior to Daylight Saving. */ public void test1() { TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Locale savedLocale = Locale.getDefault(); Locale.setDefault(Locale.UK); Calendar cal = Calendar.getInstance(Locale.UK); cal.set(Calendar.YEAR, 2004); cal.set(Calendar.MONTH, Calendar.MARCH); cal.set(Calendar.DAY_OF_MONTH, 26); cal.set(Calendar.HOUR_OF_DAY, 9); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); Date date = cal.getTime(); SegmentedTimeline timeline = getTimeline(); long value = timeline.toTimelineValue(date); long ms = timeline.toMillisecond(value); Calendar cal2 = Calendar.getInstance(Locale.UK); cal2.setTime(new Date(ms)); Date reverted = cal2.getTime(); assertTrue("test1", value == (900000 * 34) && date.getTime() == reverted.getTime()); TimeZone.setDefault(savedZone); Locale.setDefault(savedLocale); }
Example #22
Source File: SegmentedTimelineTests2.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Test 2 checks 9.15am Friday 26 March 2004 converts to a timeline value * and back again correctly. This is prior to Daylight Saving. */ public void test2() { TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Calendar cal = Calendar.getInstance(Locale.UK); cal.set(Calendar.YEAR, 2004); cal.set(Calendar.MONTH, Calendar.MARCH); cal.set(Calendar.DAY_OF_MONTH, 26); cal.set(Calendar.HOUR_OF_DAY, 9); cal.set(Calendar.MINUTE, 15); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); Date date = cal.getTime(); SegmentedTimeline timeline = getTimeline(); long value = timeline.toTimelineValue(date); long ms = timeline.toMillisecond(value); Calendar cal2 = Calendar.getInstance(Locale.UK); cal2.setTime(new Date(ms)); Date reverted = cal2.getTime(); assertTrue( "test2", value == (900000 * 34 + 900000) && date.getTime() == reverted.getTime() ); TimeZone.setDefault(savedZone); }
Example #23
Source File: SegmentedTimelineTests2.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Test 3 checks 9.30am Friday 26 March 2004 converts to a timeline value * and back again correctly. This is prior to Daylight Saving. */ public void test3() { TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Calendar cal = Calendar.getInstance(Locale.UK); cal.set(Calendar.YEAR, 2004); cal.set(Calendar.MONTH, Calendar.MARCH); cal.set(Calendar.DAY_OF_MONTH, 26); cal.set(Calendar.HOUR_OF_DAY, 9); cal.set(Calendar.MINUTE, 30); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); Date date = cal.getTime(); SegmentedTimeline timeline = getTimeline(); long value = timeline.toTimelineValue(date); long ms = timeline.toMillisecond(value); Calendar cal2 = Calendar.getInstance(Locale.UK); cal2.setTime(new Date(ms)); Date reverted = cal2.getTime(); assertTrue( "test2", value == (900000 * 34 + 900000 * 2) && date.getTime() == reverted.getTime() ); TimeZone.setDefault(savedZone); }
Example #24
Source File: SegmentedTimelineTests2.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Test 5 checks 5.30pm Thursday 25 March 2004 converts to a timeline * value and back again correctly. As it is in the excluded segment, we * expect it to map to 9am, Friday 26 March 2004. This is prior to * Daylight Saving. */ public void test5() { TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Calendar cal = Calendar.getInstance(Locale.UK); cal.set(Calendar.YEAR, 2004); cal.set(Calendar.MONTH, Calendar.MARCH); cal.set(Calendar.DAY_OF_MONTH, 25); cal.set(Calendar.HOUR_OF_DAY, 17); cal.set(Calendar.MINUTE, 30); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); Date date = cal.getTime(); SegmentedTimeline timeline = getTimeline(); long value = timeline.toTimelineValue(date); long ms = timeline.toMillisecond(value); Calendar cal2 = Calendar.getInstance(Locale.UK); cal2.setTime(new Date(ms)); Date reverted = cal2.getTime(); Calendar expectedReverted = Calendar.getInstance(Locale.UK); expectedReverted.set(Calendar.YEAR, 2004); expectedReverted.set(Calendar.MONTH, Calendar.MARCH); expectedReverted.set(Calendar.DAY_OF_MONTH, 26); expectedReverted.set(Calendar.HOUR_OF_DAY, 9); expectedReverted.set(Calendar.MINUTE, 0); expectedReverted.set(Calendar.SECOND, 0); expectedReverted.set(Calendar.MILLISECOND, 0); assertTrue( "test5", value == (900000 * 34) && expectedReverted.getTime().getTime() == reverted.getTime() ); TimeZone.setDefault(savedZone); }
Example #25
Source File: SegmentedTimelineTests2.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Test 1 checks 9am Friday 26 March 2004 converts to a timeline value and * back again correctly. This is prior to Daylight Saving. */ public void test1() { TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Locale savedLocale = Locale.getDefault(); Locale.setDefault(Locale.UK); Calendar cal = Calendar.getInstance(Locale.UK); cal.set(Calendar.YEAR, 2004); cal.set(Calendar.MONTH, Calendar.MARCH); cal.set(Calendar.DAY_OF_MONTH, 26); cal.set(Calendar.HOUR_OF_DAY, 9); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); Date date = cal.getTime(); SegmentedTimeline timeline = getTimeline(); long value = timeline.toTimelineValue(date); long ms = timeline.toMillisecond(value); Calendar cal2 = Calendar.getInstance(Locale.UK); cal2.setTime(new Date(ms)); Date reverted = cal2.getTime(); assertTrue("test1", value == (900000 * 34) && date.getTime() == reverted.getTime()); TimeZone.setDefault(savedZone); Locale.setDefault(savedLocale); }
Example #26
Source File: SegmentedTimelineTests.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Tests that the factory method that creates a 15-min 9:00 AM 4:00 PM * segmented axis does so correctly. */ public void testFifteenMinSegmentedTimeline() { assertEquals(SegmentedTimeline.FIFTEEN_MINUTE_SEGMENT_SIZE, this.fifteenMinTimeline.getSegmentSize()); assertEquals(SegmentedTimeline.FIRST_MONDAY_AFTER_1900 + 36 * this.fifteenMinTimeline.getSegmentSize(), this.fifteenMinTimeline.getStartTime()); assertEquals(28, this.fifteenMinTimeline.getSegmentsIncluded()); assertEquals(68, this.fifteenMinTimeline.getSegmentsExcluded()); }
Example #27
Source File: SegmentedTimelineTests.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Tests methods related to adding exceptions. * * @param timeline the timeline to verify * @param exceptionString array of Strings that represent the exceptions * @param fmt Format object that can parse the exceptionString strings * * @throws ParseException if there is a parsing error. */ public void verifyExceptionSegments(SegmentedTimeline timeline, String[] exceptionString, Format fmt) throws ParseException { // fill in the exceptions 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]); for (int i = 0; i < m; 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())); // exclude current exception and last one assertEquals(Math.max(0, m - i - 2), timeline.getExceptionSegmentCount(exception[i] + 1, exception[m - 1] - 1)); } }
Example #28
Source File: SegmentedTimelineTests.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Tests translations between timelines. * * @param timeline the timeline to use for verifications. * @param startTest ??. */ public void verifyTranslations(SegmentedTimeline timeline, long startTest) { for (long testCycle = TEST_CYCLE_START; testCycle < TEST_CYCLE_END; testCycle += TEST_CYCLE_INC) { long millisecond = startTest + testCycle * timeline.getSegmentSize(); SegmentedTimeline.Segment segment = timeline.getSegment( millisecond); for (int i = 0; i < 1000; i++) { long translatedValue = timeline.toTimelineValue( segment.getMillisecond()); long newValue = timeline.toMillisecond(translatedValue); if (segment.inExcludeSegments() || segment.inExceptionSegments()) { // the reverse transformed value will be in the start of the // next non-excluded and non-exception segment SegmentedTimeline.Segment tempSegment = segment.copy(); tempSegment.moveIndexToStart(); do { tempSegment.inc(); } while (!tempSegment.inIncludeSegments()); assertEquals(tempSegment.getMillisecond(), newValue); } else { assertEquals(segment.getMillisecond(), newValue); } segment.inc(); } } }
Example #29
Source File: SegmentedTimelineTests.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Serialize an instance, restore it, and check for equality. */ public void testSerialization() { verifySerialization(this.msTimeline); verifySerialization(this.ms2Timeline); verifySerialization(this.ms2BaseTimeline); verifySerialization(SegmentedTimeline.newMondayThroughFridayTimeline()); verifySerialization(SegmentedTimeline.newFifteenMinuteTimeline()); }
Example #30
Source File: SegmentedTimelineTests.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Adds an array of exceptions relative to the base timeline. * * @param timeline The timeline where the exceptions will be stored * @param exceptionString The exceptions to load * @param fmt The date formatter to use to parse each exceptions[i] value * @throws ParseException If there is any exception parsing each * exceptions[i] value. */ private void fillInBaseTimelineExceptions(SegmentedTimeline timeline, String[] exceptionString, Format fmt) throws ParseException { SegmentedTimeline baseTimeline = timeline.getBaseTimeline(); for (int i = 0; i < exceptionString.length; i++) { long e; if (fmt instanceof NumberFormat) { e = ((NumberFormat) fmt).parse(exceptionString[i]).longValue(); } else { e = timeline.getTime(((SimpleDateFormat) fmt) .parse(exceptionString[i])); } timeline.addBaseTimelineException(e); // verify all timeline segments included in the // baseTimeline.segment are now exceptions SegmentedTimeline.Segment segment1 = baseTimeline.getSegment(e); for (SegmentedTimeline.Segment segment2 = timeline.getSegment(segment1.getSegmentStart()); segment2.getSegmentStart() <= segment1.getSegmentEnd(); segment2.inc()) { if (!segment2.inExcludeSegments()) { assertTrue(segment2.inExceptionSegments()); } } } }