Java Code Examples for org.jfree.data.time.TimePeriodValues#add()

The following examples show how to use org.jfree.data.time.TimePeriodValues#add() . 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: TimePeriodValuesCollectionTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the getDomainBounds() method.
 */
public void testGetDomainBoundsWithoutInterval() {
    // check empty dataset
    TimePeriodValuesCollection dataset = new TimePeriodValuesCollection();
    Range r = dataset.getDomainBounds(false);
    assertNull(r);
    
    // check dataset with one time period
    TimePeriodValues s1 = new TimePeriodValues("S1");
    s1.add(new SimpleTimePeriod(1000L, 2000L), 1.0);
    dataset.addSeries(s1);
    r = dataset.getDomainBounds(false);
    assertEquals(1500.0, r.getLowerBound(), EPSILON);
    assertEquals(1500.0, r.getUpperBound(), EPSILON);
    
    // check dataset with two time periods
    s1.add(new SimpleTimePeriod(1500L, 3000L), 2.0);
    r = dataset.getDomainBounds(false);
    assertEquals(1500.0, r.getLowerBound(), EPSILON);
    assertEquals(2250.0, r.getUpperBound(), EPSILON);  
}
 
Example 2
Source File: TimePeriodValuesCollectionTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * A test for bug report 1161340.  I wasn't able to reproduce the problem
 * with this test.
 */
public void test1161340() {
    TimePeriodValuesCollection dataset = new TimePeriodValuesCollection();
    TimePeriodValues v1 = new TimePeriodValues("V1");
    v1.add(new Day(11, 3, 2005), 1.2);
    v1.add(new Day(12, 3, 2005), 3.4);
    dataset.addSeries(v1);
    assertEquals(1, dataset.getSeriesCount());
    dataset.removeSeries(v1);
    assertEquals(0, dataset.getSeriesCount());
    
    TimePeriodValues v2 = new TimePeriodValues("V2");
    v1.add(new Day(5, 3, 2005), 1.2);
    v1.add(new Day(6, 3, 2005), 3.4);
    dataset.addSeries(v2);
    assertEquals(1, dataset.getSeriesCount());
}
 
Example 3
Source File: TimePeriodValuesTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the add() methods.
 */
public void testAdd() {
    TimePeriodValues tpv = new TimePeriodValues("Test");
    MySeriesChangeListener listener = new MySeriesChangeListener();
    tpv.addChangeListener(listener);
    tpv.add(new TimePeriodValue(new SimpleTimePeriod(new Date(1L), 
            new Date(3L)), 99.0));
    assertEquals(99.0, tpv.getValue(0).doubleValue(), EPSILON);
    assertEquals(tpv, listener.getLastEvent().getSource());
    
    // a null item should throw an IllegalArgumentException
    boolean pass = false;
    try {
        tpv.add((TimePeriodValue) null);
    }
    catch (IllegalArgumentException e) {
        pass = true;
    }
    assertTrue(pass);
}
 
Example 4
Source File: ChartUtil.java    From ezScrum with GNU General Public License v2.0 6 votes vote down vote up
private XYDataset createBarDataset() {
	final TimePeriodValuesCollection result = new TimePeriodValuesCollection();
	Set<String> nameSet = this.m_dataSetMap.keySet();

	for (String name : nameSet) {
		final TimePeriodValues series = new TimePeriodValues(name);

		Map<Date, ? extends Number> map = m_dataSetMap.get(name);

		Iterator<Date> ir = map.keySet().iterator();

		while (ir.hasNext()) {
			Date key = ir.next();
			series.add(new SimpleTimePeriod(key, new Date(key.getTime()
					+ (m_interval * OneDay))), map.get(key));
		}

		result.addSeries(series);
	}
	return result;
}
 
Example 5
Source File: TimePeriodValuesCollectionTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some more checks for the getDomainBounds() method.
 * 
 * @see #testGetDomainBoundsWithoutInterval()
 */
public void testGetDomainBoundsWithInterval() {
    // check empty dataset
    TimePeriodValuesCollection dataset = new TimePeriodValuesCollection();
    Range r = dataset.getDomainBounds(true);
    assertNull(r);
    
    // check dataset with one time period
    TimePeriodValues s1 = new TimePeriodValues("S1");
    s1.add(new SimpleTimePeriod(1000L, 2000L), 1.0);
    dataset.addSeries(s1);
    r = dataset.getDomainBounds(true);
    assertEquals(1000.0, r.getLowerBound(), EPSILON);
    assertEquals(2000.0, r.getUpperBound(), EPSILON);
    
    // check dataset with two time periods
    s1.add(new SimpleTimePeriod(1500L, 3000L), 2.0);
    r = dataset.getDomainBounds(true);
    assertEquals(1000.0, r.getLowerBound(), EPSILON);
    assertEquals(3000.0, r.getUpperBound(), EPSILON);  
}
 
Example 6
Source File: TimePeriodValuesCollectionTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the getDomainBounds() method.
 */
public void testGetDomainBoundsWithoutInterval() {
    // check empty dataset
    TimePeriodValuesCollection dataset = new TimePeriodValuesCollection();
    Range r = dataset.getDomainBounds(false);
    assertNull(r);
    
    // check dataset with one time period
    TimePeriodValues s1 = new TimePeriodValues("S1");
    s1.add(new SimpleTimePeriod(1000L, 2000L), 1.0);
    dataset.addSeries(s1);
    r = dataset.getDomainBounds(false);
    assertEquals(1500.0, r.getLowerBound(), EPSILON);
    assertEquals(1500.0, r.getUpperBound(), EPSILON);
    
    // check dataset with two time periods
    s1.add(new SimpleTimePeriod(1500L, 3000L), 2.0);
    r = dataset.getDomainBounds(false);
    assertEquals(1500.0, r.getLowerBound(), EPSILON);
    assertEquals(2250.0, r.getUpperBound(), EPSILON);  
}
 
Example 7
Source File: TimePeriodValuesCollectionTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * A test for bug report 1161340.  I wasn't able to reproduce the problem
 * with this test.
 */
public void test1161340() {
    TimePeriodValuesCollection dataset = new TimePeriodValuesCollection();
    TimePeriodValues v1 = new TimePeriodValues("V1");
    v1.add(new Day(11, 3, 2005), 1.2);
    v1.add(new Day(12, 3, 2005), 3.4);
    dataset.addSeries(v1);
    assertEquals(1, dataset.getSeriesCount());
    dataset.removeSeries(v1);
    assertEquals(0, dataset.getSeriesCount());
    
    TimePeriodValues v2 = new TimePeriodValues("V2");
    v1.add(new Day(5, 3, 2005), 1.2);
    v1.add(new Day(6, 3, 2005), 3.4);
    dataset.addSeries(v2);
    assertEquals(1, dataset.getSeriesCount());
}
 
Example 8
Source File: TimePeriodValuesTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some tests for the getMaxEndIndex() method.
 */
public void getMaxEndIndex() {
    TimePeriodValues s = new TimePeriodValues("Test");
    assertEquals(-1, s.getMaxEndIndex());
    s.add(new SimpleTimePeriod(100L, 200L), 1.0);
    assertEquals(0, s.getMaxEndIndex());
    s.add(new SimpleTimePeriod(300L, 400L), 2.0);
    assertEquals(1, s.getMaxEndIndex());
    s.add(new SimpleTimePeriod(0L, 50L), 3.0);
    assertEquals(1, s.getMaxEndIndex());
}
 
Example 9
Source File: TimePeriodValuesTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * A test for bug report 1161329.
 */
public void test1161329() {
    TimePeriodValues tpv = new TimePeriodValues("Test");
    RegularTimePeriod t = new Day();
    tpv.add(t, 1.0);
    t = t.next();
    tpv.add(t, 2.0);
    tpv.delete(0, 1);
    assertEquals(0, tpv.getItemCount());
    tpv.add(t, 2.0);
    assertEquals(1, tpv.getItemCount());
}
 
Example 10
Source File: TimePeriodValuesTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add a value to series A for 1999.  It should be added at index 0.
 */
public void testAddValue() {

    TimePeriodValues tpvs = new TimePeriodValues("Test");
    try {
        tpvs.add(new Year(1999), new Integer(1));
    }
    catch (SeriesException e) {
        System.err.println("Problem adding to series.");
    }

    int value = tpvs.getValue(0).intValue();
    assertEquals(1, value);

}
 
Example 11
Source File: TimePeriodValuesCollectionTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some more checks for the getDomainBounds() method.
 * 
 * @see #testGetDomainBoundsWithoutInterval()
 */
public void testGetDomainBoundsWithInterval() {
    // check empty dataset
    TimePeriodValuesCollection dataset = new TimePeriodValuesCollection();
    Range r = dataset.getDomainBounds(true);
    assertNull(r);
    
    // check dataset with one time period
    TimePeriodValues s1 = new TimePeriodValues("S1");
    s1.add(new SimpleTimePeriod(1000L, 2000L), 1.0);
    dataset.addSeries(s1);
    r = dataset.getDomainBounds(true);
    assertEquals(1000.0, r.getLowerBound(), EPSILON);
    assertEquals(2000.0, r.getUpperBound(), EPSILON);
    
    // check dataset with two time periods
    s1.add(new SimpleTimePeriod(1500L, 3000L), 2.0);
    r = dataset.getDomainBounds(true);
    assertEquals(1000.0, r.getLowerBound(), EPSILON);
    assertEquals(3000.0, r.getUpperBound(), EPSILON);
    
    // add a third time period
    s1.add(new SimpleTimePeriod(6000L, 7000L), 1.5);
    r = dataset.getDomainBounds(true);
    assertEquals(1000.0, r.getLowerBound(), EPSILON);
    assertEquals(7000.0, r.getUpperBound(), EPSILON);

    // add a fourth time period
    s1.add(new SimpleTimePeriod(4000L, 5000L), 1.4);
    r = dataset.getDomainBounds(true);
    assertEquals(1000.0, r.getLowerBound(), EPSILON);
    assertEquals(7000.0, r.getUpperBound(), EPSILON);    
}
 
Example 12
Source File: ConvertChartContext.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
private XYDataset createTimePeriodDataset()
{
	if (sampleTimePeriodDataset == null)
	{
		TimePeriodValuesCollection dataset = new TimePeriodValuesCollection();

		Day today = new Day();
		TimePeriodValues series1 = new TimePeriodValues("First");
		TimePeriodValues series2 = new TimePeriodValues("Second");
		
		for (int i = 0; i < 24; i++) 
		{
			Minute m0 = new Minute(0, new Hour(i, today));
			Minute m1 = new Minute(15, new Hour(i, today));
			Minute m2 = new Minute(30, new Hour(i, today));
			Minute m3 = new Minute(45, new Hour(i, today));
			Minute m4 = new Minute(0, new Hour(i + 1, today));
			series1.add(new SimpleTimePeriod(m0.getStart(), m1.getStart()), Math.random());
			series2.add(new SimpleTimePeriod(m1.getStart(), m2.getStart()), Math.random());
			series1.add(new SimpleTimePeriod(m2.getStart(), m3.getStart()), Math.random());
			series2.add(new SimpleTimePeriod(m3.getStart(), m4.getStart()), Math.random());
		}

		dataset.addSeries(series1);
		dataset.addSeries(series2);
		
		sampleTimePeriodDataset = dataset;
	}

	return sampleTimePeriodDataset;
}
 
Example 13
Source File: TimePeriodValuesTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some tests for the getMinEndIndex() method.
 */
public void getMinEndIndex() {
    TimePeriodValues s = new TimePeriodValues("Test");
    assertEquals(-1, s.getMinEndIndex());
    s.add(new SimpleTimePeriod(100L, 200L), 1.0);
    assertEquals(0, s.getMinEndIndex());
    s.add(new SimpleTimePeriod(300L, 400L), 2.0);
    assertEquals(0, s.getMinEndIndex());
    s.add(new SimpleTimePeriod(0L, 50L), 3.0);
    assertEquals(2, s.getMinEndIndex());
}
 
Example 14
Source File: TimePeriodValuesTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some tests for the getMaxMiddleIndex() method.
 */
public void testGetMaxMiddleIndex() {
    TimePeriodValues s = new TimePeriodValues("Test");
    assertEquals(-1, s.getMaxMiddleIndex());
    s.add(new SimpleTimePeriod(100L, 200L), 1.0);
    assertEquals(0, s.getMaxMiddleIndex());
    s.add(new SimpleTimePeriod(300L, 400L), 2.0);
    assertEquals(1, s.getMaxMiddleIndex());
    s.add(new SimpleTimePeriod(0L, 50L), 3.0);
    assertEquals(1, s.getMaxMiddleIndex());
    s.add(new SimpleTimePeriod(150L, 200L), 4.0);
    assertEquals(1, s.getMaxMiddleIndex());
}
 
Example 15
Source File: TimePeriodValuesTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some tests for the getMaxStartIndex() method.
 */
public void testGetMaxStartIndex() {
    TimePeriodValues s = new TimePeriodValues("Test");
    assertEquals(-1, s.getMaxStartIndex());
    s.add(new SimpleTimePeriod(100L, 200L), 1.0);
    assertEquals(0, s.getMaxStartIndex());
    s.add(new SimpleTimePeriod(300L, 400L), 2.0);
    assertEquals(1, s.getMaxStartIndex());
    s.add(new SimpleTimePeriod(0L, 50L), 3.0);
    assertEquals(1, s.getMaxStartIndex());
}
 
Example 16
Source File: TimePeriodValuesTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some tests for the getMinStartIndex() method.
 */
public void testGetMinStartIndex() {
    TimePeriodValues s = new TimePeriodValues("Test");
    assertEquals(-1, s.getMinStartIndex());
    s.add(new SimpleTimePeriod(100L, 200L), 1.0);
    assertEquals(0, s.getMinStartIndex());
    s.add(new SimpleTimePeriod(300L, 400L), 2.0);
    assertEquals(0, s.getMinStartIndex());
    s.add(new SimpleTimePeriod(0L, 50L), 3.0);
    assertEquals(2, s.getMinStartIndex());
}
 
Example 17
Source File: TimePeriodValuesTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * A test for bug report 1161329.
 */
public void test1161329() {
    TimePeriodValues tpv = new TimePeriodValues("Test");
    RegularTimePeriod t = new Day();
    tpv.add(t, 1.0);
    t = t.next();
    tpv.add(t, 2.0);
    tpv.delete(0, 1);
    assertEquals(0, tpv.getItemCount());
    tpv.add(t, 2.0);
    assertEquals(1, tpv.getItemCount());
}
 
Example 18
Source File: TimePeriodValuesTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add a value to series A for 1999.  It should be added at index 0.
 */
public void testAddValue() {

    TimePeriodValues tpvs = new TimePeriodValues("Test");
    try {
        tpvs.add(new Year(1999), new Integer(1));
    }
    catch (SeriesException e) {
        System.err.println("Problem adding to series.");
    }

    int value = tpvs.getValue(0).intValue();
    assertEquals(1, value);

}
 
Example 19
Source File: TimePeriodValuesTests.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Tests the equals method.
 */
public void testEquals() {
    TimePeriodValues s1 = new TimePeriodValues("Time Series 1");
    TimePeriodValues s2 = new TimePeriodValues("Time Series 2");
    boolean b1 = s1.equals(s2);
    assertFalse("b1", b1);

    s2.setKey("Time Series 1");
    boolean b2 = s1.equals(s2);
    assertTrue("b2", b2);

    // domain description
    s1.setDomainDescription("XYZ");
    assertFalse(s1.equals(s2));
    s2.setDomainDescription("XYZ");
    assertTrue(s1.equals(s2));
    
    // domain description - null
    s1.setDomainDescription(null);
    assertFalse(s1.equals(s2));
    s2.setDomainDescription(null);
    assertTrue(s1.equals(s2));
    
    // range description
    s1.setRangeDescription("XYZ");
    assertFalse(s1.equals(s2));
    s2.setRangeDescription("XYZ");
    assertTrue(s1.equals(s2));
    
    // range description - null
    s1.setRangeDescription(null);
    assertFalse(s1.equals(s2));
    s2.setRangeDescription(null);
    assertTrue(s1.equals(s2));

    RegularTimePeriod p1 = new Day();
    RegularTimePeriod p2 = p1.next();
    s1.add(p1, 100.0);
    s1.add(p2, 200.0);
    boolean b3 = s1.equals(s2);
    assertFalse("b3", b3);

    s2.add(p1, 100.0);
    s2.add(p2, 200.0);
    boolean b4 = s1.equals(s2);
    assertTrue("b4", b4);

}
 
Example 20
Source File: TimePeriodValuesTests.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Tests the equals method.
 */
public void testEquals() {
    TimePeriodValues s1 = new TimePeriodValues("Time Series 1");
    TimePeriodValues s2 = new TimePeriodValues("Time Series 2");
    boolean b1 = s1.equals(s2);
    assertFalse("b1", b1);

    s2.setKey("Time Series 1");
    boolean b2 = s1.equals(s2);
    assertTrue("b2", b2);

    // domain description
    s1.setDomainDescription("XYZ");
    assertFalse(s1.equals(s2));
    s2.setDomainDescription("XYZ");
    assertTrue(s1.equals(s2));
    
    // domain description - null
    s1.setDomainDescription(null);
    assertFalse(s1.equals(s2));
    s2.setDomainDescription(null);
    assertTrue(s1.equals(s2));
    
    // range description
    s1.setRangeDescription("XYZ");
    assertFalse(s1.equals(s2));
    s2.setRangeDescription("XYZ");
    assertTrue(s1.equals(s2));
    
    // range description - null
    s1.setRangeDescription(null);
    assertFalse(s1.equals(s2));
    s2.setRangeDescription(null);
    assertTrue(s1.equals(s2));

    RegularTimePeriod p1 = new Day();
    RegularTimePeriod p2 = p1.next();
    s1.add(p1, 100.0);
    s1.add(p2, 200.0);
    boolean b3 = s1.equals(s2);
    assertFalse("b3", b3);

    s2.add(p1, 100.0);
    s2.add(p2, 200.0);
    boolean b4 = s1.equals(s2);
    assertTrue("b4", b4);

}