Java Code Examples for org.jfree.data.time.TimeSeries#createCopy()

The following examples show how to use org.jfree.data.time.TimeSeries#createCopy() . 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: TimeSeriesTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Checks that the min and max y values are updated correctly when copying
 * a subset.
 *
 * @throws java.lang.CloneNotSupportedException
 */
public void testCreateCopy3() throws CloneNotSupportedException {
    TimeSeries s1 = new TimeSeries("S1");
    s1.add(new Year(2009), 100.0);
    s1.add(new Year(2010), 101.0);
    s1.add(new Year(2011), 102.0);
    assertEquals(100.0, s1.getMinY(), EPSILON);
    assertEquals(102.0, s1.getMaxY(), EPSILON);

    TimeSeries s2 = s1.createCopy(0, 1);
    assertEquals(100.0, s2.getMinY(), EPSILON);
    assertEquals(101.0, s2.getMaxY(), EPSILON);

    TimeSeries s3 = s1.createCopy(1, 2);
    assertEquals(101.0, s3.getMinY(), EPSILON);
    assertEquals(102.0, s3.getMaxY(), EPSILON);
}
 
Example 2
Source File: TimeSeriesTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test for bug report 1864222.
 */
public void testBug1864222() {
    TimeSeries s = new TimeSeries("S");
    s.add(new Day(19, 8, 2005), 1);
    s.add(new Day(31, 1, 2006), 1);
    boolean pass = true;
    try {
        s.createCopy(new Day(1, 12, 2005), new Day(18, 1, 2006));
    }
    catch (CloneNotSupportedException e) {
        pass = false;
    }
    assertTrue(pass);
}
 
Example 3
Source File: TimeSeriesTests.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Some tests to ensure that the createCopy(RegularTimePeriod,
 * RegularTimePeriod) method is functioning correctly.
 */
public void testCreateCopy1() {

    TimeSeries series = new TimeSeries("Series");
    series.add(new Month(MonthConstants.JANUARY, 2003), 45.0);
    series.add(new Month(MonthConstants.FEBRUARY, 2003), 55.0);
    series.add(new Month(MonthConstants.JUNE, 2003), 35.0);
    series.add(new Month(MonthConstants.NOVEMBER, 2003), 85.0);
    series.add(new Month(MonthConstants.DECEMBER, 2003), 75.0);

    try {
        // copy a range before the start of the series data...
        TimeSeries result1 = series.createCopy(
                new Month(MonthConstants.NOVEMBER, 2002),
                new Month(MonthConstants.DECEMBER, 2002));
        assertEquals(0, result1.getItemCount());

        // copy a range that includes only the first item in the series...
        TimeSeries result2 = series.createCopy(
                new Month(MonthConstants.NOVEMBER, 2002),
                new Month(MonthConstants.JANUARY, 2003));
        assertEquals(1, result2.getItemCount());

        // copy a range that begins before and ends in the middle of the
        // series...
        TimeSeries result3 = series.createCopy(
                new Month(MonthConstants.NOVEMBER, 2002),
                new Month(MonthConstants.APRIL, 2003));
        assertEquals(2, result3.getItemCount());

        TimeSeries result4 = series.createCopy(
                new Month(MonthConstants.NOVEMBER, 2002),
                new Month(MonthConstants.DECEMBER, 2003));
        assertEquals(5, result4.getItemCount());

        TimeSeries result5 = series.createCopy(
                new Month(MonthConstants.NOVEMBER, 2002),
                new Month(MonthConstants.MARCH, 2004));
        assertEquals(5, result5.getItemCount());

        TimeSeries result6 = series.createCopy(
                new Month(MonthConstants.JANUARY, 2003),
                new Month(MonthConstants.JANUARY, 2003));
        assertEquals(1, result6.getItemCount());

        TimeSeries result7 = series.createCopy(
                new Month(MonthConstants.JANUARY, 2003),
                new Month(MonthConstants.APRIL, 2003));
        assertEquals(2, result7.getItemCount());

        TimeSeries result8 = series.createCopy(
                new Month(MonthConstants.JANUARY, 2003),
                new Month(MonthConstants.DECEMBER, 2003));
        assertEquals(5, result8.getItemCount());

        TimeSeries result9 = series.createCopy(
                new Month(MonthConstants.JANUARY, 2003),
                new Month(MonthConstants.MARCH, 2004));
        assertEquals(5, result9.getItemCount());

        TimeSeries result10 = series.createCopy(
                new Month(MonthConstants.MAY, 2003),
                new Month(MonthConstants.DECEMBER, 2003));
        assertEquals(3, result10.getItemCount());

        TimeSeries result11 = series.createCopy(
                new Month(MonthConstants.MAY, 2003),
                new Month(MonthConstants.MARCH, 2004));
        assertEquals(3, result11.getItemCount());

        TimeSeries result12 = series.createCopy(
                new Month(MonthConstants.DECEMBER, 2003),
                new Month(MonthConstants.DECEMBER, 2003));
        assertEquals(1, result12.getItemCount());

        TimeSeries result13 = series.createCopy(
                new Month(MonthConstants.DECEMBER, 2003),
                new Month(MonthConstants.MARCH, 2004));
        assertEquals(1, result13.getItemCount());

        TimeSeries result14 = series.createCopy(
                new Month(MonthConstants.JANUARY, 2004),
                new Month(MonthConstants.MARCH, 2004));
        assertEquals(0, result14.getItemCount());
    }
    catch (CloneNotSupportedException e) {
        assertTrue(false);
    }

}
 
Example 4
Source File: TimeSeriesTests.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Some tests to ensure that the createCopy(RegularTimePeriod, 
 * RegularTimePeriod) method is functioning correctly.
 */
public void testCreateCopy1() {
    
    TimeSeries series = new TimeSeries("Series", Month.class);
    series.add(new Month(MonthConstants.JANUARY, 2003), 45.0);
    series.add(new Month(MonthConstants.FEBRUARY, 2003), 55.0);
    series.add(new Month(MonthConstants.JUNE, 2003), 35.0);
    series.add(new Month(MonthConstants.NOVEMBER, 2003), 85.0);
    series.add(new Month(MonthConstants.DECEMBER, 2003), 75.0);
    
    try {
        // copy a range before the start of the series data...
        TimeSeries result1 = series.createCopy(
                new Month(MonthConstants.NOVEMBER, 2002),
                new Month(MonthConstants.DECEMBER, 2002));
        assertEquals(0, result1.getItemCount());
    
        // copy a range that includes only the first item in the series...
        TimeSeries result2 = series.createCopy(
                new Month(MonthConstants.NOVEMBER, 2002),
                new Month(MonthConstants.JANUARY, 2003));
        assertEquals(1, result2.getItemCount());
    
        // copy a range that begins before and ends in the middle of the 
        // series...
        TimeSeries result3 = series.createCopy(
                new Month(MonthConstants.NOVEMBER, 2002),
                new Month(MonthConstants.APRIL, 2003));
        assertEquals(2, result3.getItemCount());
    
        TimeSeries result4 = series.createCopy(
                new Month(MonthConstants.NOVEMBER, 2002),
                new Month(MonthConstants.DECEMBER, 2003));
        assertEquals(5, result4.getItemCount());

        TimeSeries result5 = series.createCopy(
                new Month(MonthConstants.NOVEMBER, 2002),
                new Month(MonthConstants.MARCH, 2004));
        assertEquals(5, result5.getItemCount());
    
        TimeSeries result6 = series.createCopy(
                new Month(MonthConstants.JANUARY, 2003),
                new Month(MonthConstants.JANUARY, 2003));
        assertEquals(1, result6.getItemCount());

        TimeSeries result7 = series.createCopy(
                new Month(MonthConstants.JANUARY, 2003),
                new Month(MonthConstants.APRIL, 2003));
        assertEquals(2, result7.getItemCount());

        TimeSeries result8 = series.createCopy(
                new Month(MonthConstants.JANUARY, 2003),
                new Month(MonthConstants.DECEMBER, 2003));
        assertEquals(5, result8.getItemCount());

        TimeSeries result9 = series.createCopy(
                new Month(MonthConstants.JANUARY, 2003),
                new Month(MonthConstants.MARCH, 2004));
        assertEquals(5, result9.getItemCount());
    
        TimeSeries result10 = series.createCopy(
                new Month(MonthConstants.MAY, 2003),
                new Month(MonthConstants.DECEMBER, 2003));
        assertEquals(3, result10.getItemCount());

        TimeSeries result11 = series.createCopy(
                new Month(MonthConstants.MAY, 2003),
                new Month(MonthConstants.MARCH, 2004));
        assertEquals(3, result11.getItemCount());

        TimeSeries result12 = series.createCopy(
                new Month(MonthConstants.DECEMBER, 2003),
                new Month(MonthConstants.DECEMBER, 2003));
        assertEquals(1, result12.getItemCount());

        TimeSeries result13 = series.createCopy(
                new Month(MonthConstants.DECEMBER, 2003),
                new Month(MonthConstants.MARCH, 2004));
        assertEquals(1, result13.getItemCount());

        TimeSeries result14 = series.createCopy(
                new Month(MonthConstants.JANUARY, 2004),
                new Month(MonthConstants.MARCH, 2004));
        assertEquals(0, result14.getItemCount());
    }
    catch (CloneNotSupportedException e) {
        assertTrue(false);
    }

}