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

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

Introduction

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

Prototype

public void removeAgedItems(long latest, boolean notify) 

Source Link

Document

Age items in the series.

Usage

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

/**
 * Calling removeAgedItems() on an empty series should not throw any
 * exception./*from  w w w  . j a v a2  s. c  o m*/
 */
public void testRemoveAgedItems3() {
    TimeSeries s = new TimeSeries("Test");
    boolean pass = true;
    try {
        s.removeAgedItems(0L, true);
    } catch (Exception e) {
        pass = false;
    }
    assertTrue(pass);
}

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

/**
 * Calling removeAgedItems() on an empty series should not throw any
 * exception.//from   w w  w  . ja va  2 s. c o  m
 */
@Test
public void testRemoveAgedItems3() {
    TimeSeries s = new TimeSeries("Test");
    boolean pass = true;
    try {
        s.removeAgedItems(0L, true);
    } catch (Exception e) {
        pass = false;
    }
    assertTrue(pass);
}

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

/**
 * Check that the item bounds are determined correctly after a call to
 * removeAgedItems().//from   w w w . j av a 2  s  . com
 */
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);
}

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

/**
 * Check that the item bounds are determined correctly after a call to
 * removeAgedItems()./*  ww  w  .ja  va 2s . c  om*/
 */
@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);
}

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

/**
 * Some checks for the removeAgedItems(long, boolean) method.
 *///  www .  j  a v  a 2  s .  co 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

/**
 * Some checks for the removeAgedItems(long, boolean) method.
 *///from w ww .  ja  v a2s.com
@Test
public void testRemoveAgedItems2() {
    long y2006 = 1157087372534L; // milliseconds somewhere in 2006
    TimeSeries series = new TimeSeries("Test Series", Year.class);
    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:com.android.ddmuilib.log.event.DisplayGraph.java

/**
* Updates the chart with the {@link EventContainer} by adding the values/occurrences defined
* by the {@link ValueDisplayDescriptor} and {@link OccurrenceDisplayDescriptor} objects from
* the two lists./*w w  w .j a v a  2 s.c  o  m*/
* <p/>This method is only called when at least one of the descriptor list is non empty.
* @param event
* @param logParser
* @param valueDescriptors
* @param occurrenceDescriptors
*/
private void updateChart(EventContainer event, EventLogParser logParser,
        ArrayList<ValueDisplayDescriptor> valueDescriptors,
        ArrayList<OccurrenceDisplayDescriptor> occurrenceDescriptors) {
    Map<Integer, String> tagMap = logParser.getTagMap();

    Millisecond millisecondTime = null;
    long msec = -1;

    // If the event container is a cpu container (tag == 2721), and there is no descriptor
    // for the total CPU load, then we do accumulate all the values.
    boolean accumulateValues = false;
    double accumulatedValue = 0;

    if (event.mTag == 2721) {
        accumulateValues = true;
        for (ValueDisplayDescriptor descriptor : valueDescriptors) {
            accumulateValues &= (descriptor.valueIndex != 0);
        }
    }

    for (ValueDisplayDescriptor descriptor : valueDescriptors) {
        try {
            // get the hashmap for this descriptor
            HashMap<Integer, TimeSeries> map = mValueDescriptorSeriesMap.get(descriptor);

            // if it's not there yet, we create it.
            if (map == null) {
                map = new HashMap<Integer, TimeSeries>();
                mValueDescriptorSeriesMap.put(descriptor, map);
            }

            // get the TimeSeries for this pid
            TimeSeries timeSeries = map.get(event.pid);

            // if it doesn't exist yet, we create it
            if (timeSeries == null) {
                // get the series name
                String seriesFullName = null;
                String seriesLabel = getSeriesLabel(event, descriptor);

                switch (mValueDescriptorCheck) {
                case EVENT_CHECK_SAME_TAG:
                    seriesFullName = String.format("%1$s / %2$s", seriesLabel, descriptor.valueName);
                    break;
                case EVENT_CHECK_SAME_VALUE:
                    seriesFullName = String.format("%1$s", seriesLabel);
                    break;
                default:
                    seriesFullName = String.format("%1$s / %2$s: %3$s", seriesLabel,
                            tagMap.get(descriptor.eventTag), descriptor.valueName);
                    break;
                }

                // get the data set for this ValueType
                TimeSeriesCollection dataset = getValueDataset(
                        logParser.getEventInfoMap().get(event.mTag)[descriptor.valueIndex].getValueType(),
                        accumulateValues);

                // create the series
                timeSeries = new TimeSeries(seriesFullName, Millisecond.class);
                if (mMaximumChartItemAge != -1) {
                    timeSeries.setMaximumItemAge(mMaximumChartItemAge * 1000);
                }

                dataset.addSeries(timeSeries);

                // add it to the map.
                map.put(event.pid, timeSeries);
            }

            // update the timeSeries.

            // get the value from the event
            double value = event.getValueAsDouble(descriptor.valueIndex);

            // accumulate the values if needed.
            if (accumulateValues) {
                accumulatedValue += value;
                value = accumulatedValue;
            }

            // get the time
            if (millisecondTime == null) {
                msec = (long) event.sec * 1000L + (event.nsec / 1000000L);
                millisecondTime = new Millisecond(new Date(msec));
            }

            // add the value to the time series
            timeSeries.addOrUpdate(millisecondTime, value);
        } catch (InvalidTypeException e) {
            // just ignore this descriptor if there's a type mismatch
        }
    }

    for (OccurrenceDisplayDescriptor descriptor : occurrenceDescriptors) {
        try {
            // get the hashmap for this descriptor
            HashMap<Integer, TimeSeries> map = mOcurrenceDescriptorSeriesMap.get(descriptor);

            // if it's not there yet, we create it.
            if (map == null) {
                map = new HashMap<Integer, TimeSeries>();
                mOcurrenceDescriptorSeriesMap.put(descriptor, map);
            }

            // get the TimeSeries for this pid
            TimeSeries timeSeries = map.get(event.pid);

            // if it doesn't exist yet, we create it.
            if (timeSeries == null) {
                String seriesLabel = getSeriesLabel(event, descriptor);

                String seriesFullName = String.format("[%1$s:%2$s]", tagMap.get(descriptor.eventTag),
                        seriesLabel);

                timeSeries = new TimeSeries(seriesFullName, Millisecond.class);
                if (mMaximumChartItemAge != -1) {
                    timeSeries.setMaximumItemAge(mMaximumChartItemAge);
                }

                getOccurrenceDataSet().addSeries(timeSeries);

                map.put(event.pid, timeSeries);
            }

            // update the series

            // get the time
            if (millisecondTime == null) {
                msec = (long) event.sec * 1000L + (event.nsec / 1000000L);
                millisecondTime = new Millisecond(new Date(msec));
            }

            // add the value to the time series
            timeSeries.addOrUpdate(millisecondTime, 0); // the value is unused
        } catch (InvalidTypeException e) {
            // just ignore this descriptor if there's a type mismatch
        }
    }

    // go through all the series and remove old values.
    if (msec != -1 && mMaximumChartItemAge != -1) {
        Collection<HashMap<Integer, TimeSeries>> pidMapValues = mValueDescriptorSeriesMap.values();

        for (HashMap<Integer, TimeSeries> pidMapValue : pidMapValues) {
            Collection<TimeSeries> seriesCollection = pidMapValue.values();

            for (TimeSeries timeSeries : seriesCollection) {
                timeSeries.removeAgedItems(msec, true);
            }
        }

        pidMapValues = mOcurrenceDescriptorSeriesMap.values();
        for (HashMap<Integer, TimeSeries> pidMapValue : pidMapValues) {
            Collection<TimeSeries> seriesCollection = pidMapValue.values();

            for (TimeSeries timeSeries : seriesCollection) {
                timeSeries.removeAgedItems(msec, true);
            }
        }
    }
}