Example usage for org.jfree.data.time DateRange getUpperMillis

List of usage examples for org.jfree.data.time DateRange getUpperMillis

Introduction

In this page you can find the example usage for org.jfree.data.time DateRange getUpperMillis.

Prototype

public long getUpperMillis() 

Source Link

Document

Returns the upper bound of the range in milliseconds.

Usage

From source file:org.cds06.speleograph.data.Series.java

public Series generateSampledSeries(long length) {
    final Series newSeries = new Series(origin, Type.WATER);
    newSeries.setStepped(true);/*from  w  w w.  j a v a 2 s  .co  m*/
    final int itemsCount = getItemCount();
    final ArrayList<Item> newItems = newSeries.items;
    double bufferValue = 0D;
    DateRange range = getRange();
    long lastStartBuffer = range.getLowerMillis();
    newItems.add(new Item(newSeries, new Date(lastStartBuffer), 0.0));
    for (int i = 1; i < itemsCount; i++) {
        final Item originalItem = items.get(i), previousOriginalItem = items.get(i - 1);
        if (lastStartBuffer + length <= originalItem.getDate().getTime()) {
            newItems.add(new Item(newSeries, new Date(lastStartBuffer), bufferValue));
            newItems.add(new Item(newSeries, new Date(lastStartBuffer + length), bufferValue));
            final long time = originalItem.getDate().getTime();
            lastStartBuffer = lastStartBuffer + length;
            if (lastStartBuffer + 2 * length < time) {
                newItems.add(new Item(newSeries, new Date(lastStartBuffer), 0));
                lastStartBuffer = time - ((originalItem.getDate().getTime() - lastStartBuffer) % length);
                newItems.add(new Item(newSeries, new Date(lastStartBuffer), 0));
            }
            bufferValue = 0D;
        }
        bufferValue = bufferValue + (originalItem.getValue() - previousOriginalItem.getValue());
    }
    newItems.add(new Item(newSeries, new Date(lastStartBuffer), bufferValue));
    newItems.add(new Item(newSeries, new Date(range.getUpperMillis()), bufferValue));
    return newSeries;
}