Java Code Examples for org.jfree.data.time.Day#previous()

The following examples show how to use org.jfree.data.time.Day#previous() . 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: DayTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Set up a day equal to 1 January 1900.  Request the previous day, it
 * should be null.
 */
public void test1Jan1900Previous() {

    Day jan1st1900 = new Day(1, MonthConstants.JANUARY, 1900);
    Day previous = (Day) jan1st1900.previous();
    assertNull(previous);

}
 
Example 2
Source File: DayTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Set up a day equal to 31 December 9999.  Request the previous day, it
 * should be 30 December 9999.
 */
public void test31Dec9999Previous() {

    Day dec31st9999 = new Day(31, MonthConstants.DECEMBER, 9999);
    Day previous = (Day) dec31st9999.previous();
    assertEquals(30, previous.getDayOfMonth());

}
 
Example 3
Source File: DayTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Set up a day equal to 1 January 1900.  Request the previous day, it 
 * should be null.
 */
public void test1Jan1900Previous() {

    Day jan1st1900 = new Day(1, MonthConstants.JANUARY, 1900);
    Day previous = (Day) jan1st1900.previous();
    assertNull(previous);

}
 
Example 4
Source File: DayTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Set up a day equal to 31 December 9999.  Request the previous day, it 
 * should be 30 December 9999.
 */
public void test31Dec9999Previous() {

    Day dec31st9999 = new Day(31, MonthConstants.DECEMBER, 9999);
    Day previous = (Day) dec31st9999.previous();
    assertEquals(30, previous.getDayOfMonth());

}
 
Example 5
Source File: TimeSeriesCollectionTests.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Test the getSurroundingItems() method to ensure it is returning the
 * values we expect.
 */
public void testGetSurroundingItems() {

    TimeSeries series = new TimeSeries("Series 1");
    TimeSeriesCollection collection = new TimeSeriesCollection(series);
    collection.setXPosition(TimePeriodAnchor.MIDDLE);

    // for a series with no data, we expect {-1, -1}...
    int[] result = collection.getSurroundingItems(0, 1000L);
    assertTrue(result[0] == -1);
    assertTrue(result[1] == -1);

    // now test with a single value in the series...
    Day today = new Day();
    long start1 = today.getFirstMillisecond();
    long middle1 = today.getMiddleMillisecond();
    long end1 = today.getLastMillisecond();

    series.add(today, 99.9);
    result = collection.getSurroundingItems(0, start1);
    assertTrue(result[0] == -1);
    assertTrue(result[1] == 0);

    result = collection.getSurroundingItems(0, middle1);
    assertTrue(result[0] == 0);
    assertTrue(result[1] == 0);

    result = collection.getSurroundingItems(0, end1);
    assertTrue(result[0] == 0);
    assertTrue(result[1] == -1);

    // now add a second value to the series...
    Day tomorrow = (Day) today.next();
    long start2 = tomorrow.getFirstMillisecond();
    long middle2 = tomorrow.getMiddleMillisecond();
    long end2 = tomorrow.getLastMillisecond();

    series.add(tomorrow, 199.9);
    result = collection.getSurroundingItems(0, start2);
    assertTrue(result[0] == 0);
    assertTrue(result[1] == 1);

    result = collection.getSurroundingItems(0, middle2);
    assertTrue(result[0] == 1);
    assertTrue(result[1] == 1);

    result = collection.getSurroundingItems(0, end2);
    assertTrue(result[0] == 1);
    assertTrue(result[1] == -1);

    // now add a third value to the series...
    Day yesterday = (Day) today.previous();
    long start3 = yesterday.getFirstMillisecond();
    long middle3 = yesterday.getMiddleMillisecond();
    long end3 = yesterday.getLastMillisecond();

    series.add(yesterday, 1.23);
    result = collection.getSurroundingItems(0, start3);
    assertTrue(result[0] == -1);
    assertTrue(result[1] == 0);

    result = collection.getSurroundingItems(0, middle3);
    assertTrue(result[0] == 0);
    assertTrue(result[1] == 0);

    result = collection.getSurroundingItems(0, end3);
    assertTrue(result[0] == 0);
    assertTrue(result[1] == 1);

}
 
Example 6
Source File: TimeSeriesCollectionTests.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Test the getSurroundingItems() method to ensure it is returning the 
 * values we expect.
 */
public void testGetSurroundingItems() {
    
    TimeSeries series = new TimeSeries("Series 1", Day.class);
    TimeSeriesCollection collection = new TimeSeriesCollection(series);
    collection.setXPosition(TimePeriodAnchor.MIDDLE);
    
    // for a series with no data, we expect {-1, -1}...
    int[] result = collection.getSurroundingItems(0, 1000L);
    assertTrue(result[0] == -1);
    assertTrue(result[1] == -1);
    
    // now test with a single value in the series...
    Day today = new Day();
    long start1 = today.getFirstMillisecond();
    long middle1 = today.getMiddleMillisecond();
    long end1 = today.getLastMillisecond();
    
    series.add(today, 99.9);
    result = collection.getSurroundingItems(0, start1);
    assertTrue(result[0] == -1);
    assertTrue(result[1] == 0);
    
    result = collection.getSurroundingItems(0, middle1);
    assertTrue(result[0] == 0);
    assertTrue(result[1] == 0);
    
    result = collection.getSurroundingItems(0, end1);
    assertTrue(result[0] == 0);
    assertTrue(result[1] == -1);
    
    // now add a second value to the series...
    Day tomorrow = (Day) today.next();
    long start2 = tomorrow.getFirstMillisecond();
    long middle2 = tomorrow.getMiddleMillisecond();
    long end2 = tomorrow.getLastMillisecond();
    
    series.add(tomorrow, 199.9);
    result = collection.getSurroundingItems(0, start2);
    assertTrue(result[0] == 0);
    assertTrue(result[1] == 1);
    
    result = collection.getSurroundingItems(0, middle2);
    assertTrue(result[0] == 1);
    assertTrue(result[1] == 1);
    
    result = collection.getSurroundingItems(0, end2);
    assertTrue(result[0] == 1);
    assertTrue(result[1] == -1);
    
    // now add a third value to the series...
    Day yesterday = (Day) today.previous();
    long start3 = yesterday.getFirstMillisecond();
    long middle3 = yesterday.getMiddleMillisecond();
    long end3 = yesterday.getLastMillisecond();
    
    series.add(yesterday, 1.23);
    result = collection.getSurroundingItems(0, start3);
    assertTrue(result[0] == -1);
    assertTrue(result[1] == 0);
    
    result = collection.getSurroundingItems(0, middle3);
    assertTrue(result[0] == 0);
    assertTrue(result[1] == 0);
    
    result = collection.getSurroundingItems(0, end3);
    assertTrue(result[0] == 0);
    assertTrue(result[1] == 1);
    
}