Java Code Examples for org.jfree.chart.axis.SegmentedTimeline#addException()

The following examples show how to use org.jfree.chart.axis.SegmentedTimeline#addException() . 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: SegmentedTimelineTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 2
Source File: SegmentedTimelineTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 3
Source File: SegmentedTimelineTests2.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Test 8.
 */
public void test8() {
    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, 10);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    Date date = cal.getTime();

    SegmentedTimeline timeline = getTimeline();

    // Add exception in included segments
    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, 15);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    timeline.addException(cal.getTime());

    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, 10);
    expectedReverted.set(Calendar.MINUTE, 0);
    expectedReverted.set(Calendar.SECOND, 0);
    expectedReverted.set(Calendar.MILLISECOND, 0);

    assertTrue(
        "test8", value == (900000 * 34 * 2 + 900000 * (4 - 1))
        && expectedReverted.getTime().getTime() == reverted.getTime()
    );
    TimeZone.setDefault(savedZone);
}
 
Example 4
Source File: SegmentedTimelineTests2.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Test 8.
 */
public void test8() {
    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, 10);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    Date date = cal.getTime();
              
    SegmentedTimeline timeline = getTimeline();      
  
    // Add exception in included segments
    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, 15);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    timeline.addException(cal.getTime());
        
    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, 10);
    expectedReverted.set(Calendar.MINUTE, 0);
    expectedReverted.set(Calendar.SECOND, 0);
    expectedReverted.set(Calendar.MILLISECOND, 0);
  
    assertTrue(
        "test8", value == (900000 * 34 * 2 + 900000 * (4 - 1)) 
        && expectedReverted.getTime().getTime() == reverted.getTime()
    );
    TimeZone.setDefault(savedZone);
}