Example usage for org.jfree.data.time Day previous

List of usage examples for org.jfree.data.time Day previous

Introduction

In this page you can find the example usage for org.jfree.data.time Day previous.

Prototype

@Override
public RegularTimePeriod previous() 

Source Link

Document

Returns the day preceding this one.

Usage

From source file:org.jfree.data.time.DayTest.java

/**
 * Set up a day equal to 1 January 1900.  Request the previous day, it
 * should be null./*from   w  w  w  .  j  a v a2s  .  com*/
 */
@Test
public void test1Jan1900Previous() {
    Day jan1st1900 = new Day(1, MonthConstants.JANUARY, 1900);
    Day previous = (Day) jan1st1900.previous();
    assertNull(previous);
}

From source file:org.jfree.data.time.DayTest.java

/**
 * Set up a day equal to 31 December 9999.  Request the previous day, it
 * should be 30 December 9999.//from   w w w  .  j a  v a2  s  .co m
 */
@Test
public void test31Dec9999Previous() {
    Day dec31st9999 = new Day(31, MonthConstants.DECEMBER, 9999);
    Day previous = (Day) dec31st9999.previous();
    assertEquals(30, previous.getDayOfMonth());
}

From source file:org.jfree.data.time.junit.DayTest.java

/**
 * Set up a day equal to 1 January 1900.  Request the previous day, it
 * should be null.// w  ww .ja v  a2  s . c  om
 */
public void test1Jan1900Previous() {
    Day jan1st1900 = new Day(1, MonthConstants.JANUARY, 1900);
    Day previous = (Day) jan1st1900.previous();
    assertNull(previous);
}

From source file:org.jfree.data.time.junit.DayTest.java

/**
 * Set up a day equal to 31 December 9999.  Request the previous day, it
 * should be 30 December 9999.//from  w  ww  .  jav  a 2s  .  c om
 */
public void test31Dec9999Previous() {
    Day dec31st9999 = new Day(31, MonthConstants.DECEMBER, 9999);
    Day previous = (Day) dec31st9999.previous();
    assertEquals(30, previous.getDayOfMonth());
}

From source file:org.jfree.data.time.TimeSeriesCollectionTest.java

/**
 * Test the getSurroundingItems() method to ensure it is returning the
 * values we expect.//from ww w  .  j a va  2s  .  c o  m
 */
@Test
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);
}