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

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

Introduction

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

Prototype

public void delete(RegularTimePeriod period) 

Source Link

Document

Deletes the data item for the given time period and sends a SeriesChangeEvent to all registered listeners.

Usage

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

/**
 * Check that the item bounds are determined correctly when there is a
 * maximum item count and a new value is added.
 *///from  www.  j  a  v a2  s.  c  o m
public void testDelete_RegularTimePeriod() {
    TimeSeries s1 = new TimeSeries("S1");
    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), 4.4);
    s1.delete(new Year(2010));
    s1.delete(new Year(2013));
    assertEquals(2.2, s1.getMinY(), EPSILON);
    assertEquals(3.3, s1.getMaxY(), EPSILON);
}

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

/**
 * Basic tests for the delete() method./*from   www.  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.TimeSeriesTest.java

/**
 * Check that the item bounds are determined correctly when there is a
 * maximum item count and a new value is added.
 *//*w  ww .  ja v  a  2s  .co m*/
@Test
public void testDelete_RegularTimePeriod() {
    TimeSeries s1 = new TimeSeries("S1");
    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), 4.4);
    s1.delete(new Year(2010));
    s1.delete(new Year(2013));
    assertEquals(2.2, s1.getMinY(), EPSILON);
    assertEquals(3.3, s1.getMaxY(), EPSILON);
}

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

/**
 * Basic tests for the delete() method./*  w w w .  j av  a  2s.  co m*/
 */
@Test
public void testDelete2() {
    TimeSeries s1 = new TimeSeries("Series", Year.class);
    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:com.peterbochs.instrument.InstrumentPanel.java

private void runTimer() {
    if (interruptTimer != null) {
        interruptTimer.cancel();/*from  w  w  w  . ja v a2s  .  com*/
    }

    interruptTimer = new Timer();
    interruptTimer.schedule(new TimerTask() {
        Hashtable<Long, Integer> oldInterruptRecords;

        public void run() {
            try {
                synchronized (allSeries) {
                    ArrayList<Long> list = Collections.list(InterruptSocketServer.interruptRecords.keys());
                    Date d = new Date();
                    // int noOfFrame = getTimeframe() / getSpeed();
                    oldInterruptRecords = (Hashtable<Long, Integer>) InterruptSocketServer.interruptRecords
                            .clone();
                    ((InterruptTableModel) jInterruptTable.getModel()).fireTableDataChanged();

                    for (int x = 0; x < list.size(); x++) {
                        long interuptNoL = list.get(x);
                        int interruptNo = (int) interuptNoL;
                        if (allSeries.get(interruptNo) != null) {
                            TimeSeries series = allSeries.get(interruptNo);
                            List<TimeSeriesDataItem> items = series.getItems();
                            for (int z = items.size() - 1; z >= 0; z--) {
                                RegularTimePeriod pd = items.get(z).getPeriod();
                                Calendar cal1 = Calendar.getInstance();
                                cal1.add(Calendar.MILLISECOND, -1 * getTimeframe());
                                Calendar cal2 = Calendar.getInstance();
                                cal2.setTime(pd.getEnd());
                                if (cal1.after(cal2)) {
                                    series.delete(pd);
                                }
                            }
                            series.add(new Millisecond(d),
                                    InterruptSocketServer.interruptRecords.get(interuptNoL)
                                            - oldInterruptRecords.get(interuptNoL));
                            //                     InterruptSocketServer.interruptRecords.put(interuptNoL, 0);
                        } else {
                            TimeSeries newSeries = new TimeSeries("Int 0x" + Integer.toHexString(interruptNo));
                            interruptDataset.addSeries(newSeries);
                            allSeries.put(interruptNo, newSeries);
                        }
                    }

                    interruptChart.fireChartChanged();
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }, 0, getSpeed());
}