Example usage for org.jfree.data.time TimePeriodValues clone

List of usage examples for org.jfree.data.time TimePeriodValues clone

Introduction

In this page you can find the example usage for org.jfree.data.time TimePeriodValues clone.

Prototype

@Override
public Object clone() throws CloneNotSupportedException 

Source Link

Document

Returns a clone of the collection.

Usage

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

/**
 * Set up a quarter equal to Q1 1900.  Request the previous quarter, it 
 * should be null./*from   ww w  .ja  v a  2s . com*/
 */
@Test
public void testClone() throws CloneNotSupportedException {
    TimePeriodValues series = new TimePeriodValues("Test Series");
    RegularTimePeriod jan1st2002 = new Day(1, MonthConstants.JANUARY, 2002);
    series.add(jan1st2002, new Integer(42));
    TimePeriodValues clone = (TimePeriodValues) series.clone();
    clone.setKey("Clone Series");
    clone.update(0, new Integer(10));

    int seriesValue = series.getValue(0).intValue();
    int cloneValue = clone.getValue(0).intValue();

    assertEquals(42, seriesValue);
    assertEquals(10, cloneValue);
    assertEquals("Test Series", series.getKey());
    assertEquals("Clone Series", clone.getKey());
}

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

/**
 * Set up a quarter equal to Q1 1900.  Request the previous quarter, it 
 * should be null./*from  ww w  .ja  va 2s. c om*/
 */
public void testClone() {

    TimePeriodValues series = new TimePeriodValues("Test Series");

    RegularTimePeriod jan1st2002 = new Day(1, MonthConstants.JANUARY, 2002);
    try {
        series.add(jan1st2002, new Integer(42));
    } catch (SeriesException e) {
        System.err.println("Problem adding to collection.");
    }

    TimePeriodValues clone = null;
    try {
        clone = (TimePeriodValues) series.clone();
        clone.setKey("Clone Series");
        try {
            clone.update(0, new Integer(10));
        } catch (SeriesException e) {
            System.err.println("Problem updating series.");
        }
    } catch (CloneNotSupportedException e) {
        assertTrue(false);
    }

    int seriesValue = series.getValue(0).intValue();
    int cloneValue = clone.getValue(0).intValue();

    assertEquals(42, seriesValue);
    assertEquals(10, cloneValue);
    assertEquals("Test Series", series.getKey());
    assertEquals("Clone Series", clone.getKey());

}