Example usage for org.jfree.data.time TimeSeries getItemCount

List of usage examples for org.jfree.data.time TimeSeries getItemCount

Introduction

In this page you can find the example usage for org.jfree.data.time TimeSeries getItemCount.

Prototype

@Override
public int getItemCount() 

Source Link

Document

Returns the number of items in the series.

Usage

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

/**
 * Some tests to ensure that the createCopy(RegularTimePeriod,
 * RegularTimePeriod) method is functioning correctly.
 *//*from  w  w  w  . j  a  va  2s.  co m*/
@Test
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);
    }
}

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

/**
 * Check that the item bounds are determined correctly when there is a
 * maximum item count./*from ww  w . j  a  v a2s.  c o  m*/
 */
@Test
public void testRemoveAgedItems4() {
    TimeSeries s1 = new TimeSeries("S1");
    s1.setMaximumItemAge(2);
    s1.add(new Year(2010), 1.1);
    s1.add(new Year(2011), 2.2);
    s1.add(new Year(2012), 3.3);
    s1.add(new Year(2013), 2.5);
    assertEquals(3, s1.getItemCount());
    assertEquals(2.2, s1.getMinY(), EPSILON);
    assertEquals(3.3, s1.getMaxY(), EPSILON);
}

From source file:org.yccheok.jstock.gui.charting.ChartLayerUI.java

private Point2D.Double getPoint(int plotIndex, int seriesIndex, int dataIndex) {
    final TimeSeries timeSeries = this.getTimeSeries(plotIndex, seriesIndex);
    if (timeSeries == null) {
        // Possible this is candlestick?
        final XYPlot plot = this.chartJDialog.getPlot(plotIndex);
        if (plot.getDataset(seriesIndex) instanceof org.jfree.data.xy.DefaultHighLowDataset) {
            return this._getPointForCandlestick(plotIndex, seriesIndex, dataIndex);
        }//from w  w  w .  j a  v a 2 s. co  m
        return null;
    }

    if (dataIndex >= timeSeries.getItemCount()) {
        /* Not ready yet. */
        return null;
    }

    final ChartPanel chartPanel = this.chartJDialog.getChartPanel();
    final XYPlot plot = this.chartJDialog.getPlot(plotIndex);
    final ValueAxis domainAxis = plot.getDomainAxis();
    final RectangleEdge domainAxisEdge = plot.getDomainAxisEdge();
    final ValueAxis rangeAxis = plot.getRangeAxis();
    final RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge();

    final TimeSeriesDataItem timeSeriesDataItem = timeSeries.getDataItem(dataIndex);
    final double xValue = timeSeriesDataItem.getPeriod().getFirstMillisecond();
    final double yValue = timeSeriesDataItem.getValue().doubleValue();
    final Rectangle2D plotArea = chartPanel.getChartRenderingInfo().getPlotInfo().getSubplotInfo(plotIndex)
            .getDataArea();
    final double xJava2D = domainAxis.valueToJava2D(xValue, plotArea, domainAxisEdge);
    final double yJava2D = rangeAxis.valueToJava2D(yValue, plotArea, rangeAxisEdge);
    // Use Double version, to avoid from losing precision.
    return new Point2D.Double(xJava2D, yJava2D);
}

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

/**
 * Test the setMaximumItemCount() method to ensure that it removes items
 * from the series if necessary.//  w ww.j  a v  a2 s .c o m
 */
@Test
public void testSetMaximumItemCount() {
    TimeSeries s1 = new TimeSeries("S1", Year.class);
    s1.add(new Year(2000), 13.75);
    s1.add(new Year(2001), 11.90);
    s1.add(new Year(2002), null);
    s1.add(new Year(2005), 19.32);
    s1.add(new Year(2007), 16.89);
    assertTrue(s1.getItemCount() == 5);

    s1.setMaximumItemCount(3);
    assertTrue(s1.getItemCount() == 3);
    TimeSeriesDataItem item = s1.getDataItem(0);
    assertTrue(item.getPeriod().equals(new Year(2002)));
    assertEquals(16.89, s1.getMinY(), EPSILON);
    assertEquals(19.32, s1.getMaxY(), EPSILON);
}

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

/**
 * Basic tests for the delete() method./*from  ww  w.j a  v  a  2 s. c  o  m*/
 */
public void testDelete2() {
    TimeSeries s1 = new TimeSeries("Series");
    s1.add(new Year(2000), 13.75);
    s1.add(new Year(2001), 11.90);
    s1.add(new Year(2002), null);
    s1.addChangeListener(this);
    this.gotSeriesChangeEvent = false;
    s1.delete(new Year(2001));
    assertTrue(this.gotSeriesChangeEvent);
    assertEquals(2, s1.getItemCount());
    assertEquals(null, s1.getValue(new Year(2001)));

    // try deleting a time period that doesn't exist...
    this.gotSeriesChangeEvent = false;
    s1.delete(new Year(2006));
    assertFalse(this.gotSeriesChangeEvent);

    // try deleting null
    try {
        s1.delete(null);
        fail("Expected IllegalArgumentException.");
    } catch (IllegalArgumentException e) {
        // expected
    }
}

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

/**
 * A test for the bug report 1075255./*from  w  ww  .j  av a 2 s  .  co m*/
 */
public void testBug1075255() {
    TimeSeries ts = new TimeSeries("dummy");
    ts.add(new FixedMillisecond(0L), 0.0);
    TimeSeries ts2 = new TimeSeries("dummy2");
    ts2.add(new FixedMillisecond(0L), 1.0);
    try {
        ts.addAndOrUpdate(ts2);
    } catch (Exception e) {
        e.printStackTrace();
        assertTrue(false);
    }
    assertEquals(1, ts.getItemCount());
}

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

/**
 * Some checks for the removeAgedItems() method.
 *//*from  ww  w .j a  v  a  2s. c o m*/
public void testRemoveAgedItems() {
    TimeSeries series = new TimeSeries("Test Series");
    series.addChangeListener(this);
    assertEquals(Long.MAX_VALUE, series.getMaximumItemAge());
    assertEquals(Integer.MAX_VALUE, series.getMaximumItemCount());
    this.gotSeriesChangeEvent = false;

    // test empty series
    series.removeAgedItems(true);
    assertEquals(0, series.getItemCount());
    assertFalse(this.gotSeriesChangeEvent);

    // test series with one item
    series.add(new Year(1999), 1.0);
    series.setMaximumItemAge(0);
    this.gotSeriesChangeEvent = false;
    series.removeAgedItems(true);
    assertEquals(1, series.getItemCount());
    assertFalse(this.gotSeriesChangeEvent);

    // test series with two items
    series.setMaximumItemAge(10);
    series.add(new Year(2001), 2.0);
    this.gotSeriesChangeEvent = false;
    series.setMaximumItemAge(2);
    assertEquals(2, series.getItemCount());
    assertEquals(0, series.getIndex(new Year(1999)));
    assertFalse(this.gotSeriesChangeEvent);
    series.setMaximumItemAge(1);
    assertEquals(1, series.getItemCount());
    assertEquals(0, series.getIndex(new Year(2001)));
    assertTrue(this.gotSeriesChangeEvent);
}

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

/**
 * Some checks for the delete(int, int) method.
 *//*w  w  w  .j ava  2s .com*/
@Test
public void testDelete3() {
    TimeSeries s1 = new TimeSeries("S1");
    s1.add(new Year(2011), 1.1);
    s1.add(new Year(2012), 2.2);
    s1.add(new Year(2013), 3.3);
    s1.add(new Year(2014), 4.4);
    s1.add(new Year(2015), 5.5);
    s1.add(new Year(2016), 6.6);
    s1.delete(2, 5);
    assertEquals(2, s1.getItemCount());
    assertEquals(new Year(2011), s1.getTimePeriod(0));
    assertEquals(new Year(2012), s1.getTimePeriod(1));
    assertEquals(1.1, s1.getMinY(), EPSILON);
    assertEquals(2.2, s1.getMaxY(), EPSILON);
}

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

/**
 * Some checks for the removeAgedItems(long, boolean) method.
 *//*from w ww. j  av a 2 s. c  o  m*/
public void testRemoveAgedItems2() {
    long y2006 = 1157087372534L; // milliseconds somewhere in 2006
    TimeSeries series = new TimeSeries("Test Series");
    series.addChangeListener(this);
    assertEquals(Long.MAX_VALUE, series.getMaximumItemAge());
    assertEquals(Integer.MAX_VALUE, series.getMaximumItemCount());
    this.gotSeriesChangeEvent = false;

    // test empty series
    series.removeAgedItems(y2006, true);
    assertEquals(0, series.getItemCount());
    assertFalse(this.gotSeriesChangeEvent);

    // test a series with 1 item
    series.add(new Year(2004), 1.0);
    series.setMaximumItemAge(1);
    this.gotSeriesChangeEvent = false;
    series.removeAgedItems(new Year(2005).getMiddleMillisecond(), true);
    assertEquals(1, series.getItemCount());
    assertFalse(this.gotSeriesChangeEvent);
    series.removeAgedItems(y2006, true);
    assertEquals(0, series.getItemCount());
    assertTrue(this.gotSeriesChangeEvent);

    // test a series with two items
    series.setMaximumItemAge(2);
    series.add(new Year(2003), 1.0);
    series.add(new Year(2005), 2.0);
    assertEquals(2, series.getItemCount());
    this.gotSeriesChangeEvent = false;
    assertEquals(2, series.getItemCount());

    series.removeAgedItems(new Year(2005).getMiddleMillisecond(), true);
    assertEquals(2, series.getItemCount());
    assertFalse(this.gotSeriesChangeEvent);
    series.removeAgedItems(y2006, true);
    assertEquals(1, series.getItemCount());
    assertTrue(this.gotSeriesChangeEvent);
}

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

/**
 * Check that the item bounds are determined correctly after a call to
 * removeAgedItems()./*from w  w  w.j av  a 2  s  . c o  m*/
 */
@Test
public void testRemoveAgedItems5() {
    TimeSeries s1 = new TimeSeries("S1");
    s1.setMaximumItemAge(4);
    s1.add(new Year(2010), 1.1);
    s1.add(new Year(2011), 2.2);
    s1.add(new Year(2012), 3.3);
    s1.add(new Year(2013), 2.5);
    s1.removeAgedItems(new Year(2015).getMiddleMillisecond(), true);
    assertEquals(3, s1.getItemCount());
    assertEquals(2.2, s1.getMinY(), EPSILON);
    assertEquals(3.3, s1.getMaxY(), EPSILON);
}