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

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

Introduction

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

Prototype

public void setMaximumItemAge(long periods) 

Source Link

Document

Sets the number of time units in the 'history' for the series.

Usage

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

/**
 * Tests the equals method.// w w  w. j a  v  a  2s .  c  om
 */
public void testEquals() {
    TimeSeries s1 = new TimeSeries("Time Series 1");
    TimeSeries s2 = new TimeSeries("Time Series 2");
    boolean b1 = s1.equals(s2);
    assertFalse("b1", b1);

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

    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);

    s1.setMaximumItemCount(100);
    boolean b5 = s1.equals(s2);
    assertFalse("b5", b5);

    s2.setMaximumItemCount(100);
    boolean b6 = s1.equals(s2);
    assertTrue("b6", b6);

    s1.setMaximumItemAge(100);
    boolean b7 = s1.equals(s2);
    assertFalse("b7", b7);

    s2.setMaximumItemAge(100);
    boolean b8 = s1.equals(s2);
    assertTrue("b8", b8);
}

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

/**
 * Tests the equals method./*from  w  w  w  . j  av  a2  s  .co m*/
 */
@Test
public void testEquals() {
    TimeSeries s1 = new TimeSeries("Time Series 1");
    TimeSeries s2 = new TimeSeries("Time Series 2");
    boolean b1 = s1.equals(s2);
    assertFalse("b1", b1);

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

    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);

    s1.setMaximumItemCount(100);
    boolean b5 = s1.equals(s2);
    assertFalse("b5", b5);

    s2.setMaximumItemCount(100);
    boolean b6 = s1.equals(s2);
    assertTrue("b6", b6);

    s1.setMaximumItemAge(100);
    boolean b7 = s1.equals(s2);
    assertFalse("b7", b7);

    s2.setMaximumItemAge(100);
    boolean b8 = s1.equals(s2);
    assertTrue("b8", b8);
}

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./*from  w w  w  .  j  a v  a2s  .co  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);
            }
        }
    }
}