Example usage for org.jfree.data.time RegularTimePeriod compareTo

List of usage examples for org.jfree.data.time RegularTimePeriod compareTo

Introduction

In this page you can find the example usage for org.jfree.data.time RegularTimePeriod compareTo.

Prototype

public int compareTo(T o);

Source Link

Document

Compares this object with the specified object for order.

Usage

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

/**
 * Creates a new timeseries by copying a subset of the data in this time
 * series.//from ww  w . j a v  a  2s  .  c  o  m
 *
 * @param start  the first time period to copy (<code>null</code> not
 *         permitted).
 * @param end  the last time period to copy (<code>null</code> not
 *         permitted).
 *
 * @return A time series containing a copy of this time series from start
 *         until end.
 *
 * @throws CloneNotSupportedException if there is a cloning problem.
 */
public TimeSeries createCopy(RegularTimePeriod start, RegularTimePeriod end) throws CloneNotSupportedException {

    ParamChecks.nullNotPermitted(start, "start");
    ParamChecks.nullNotPermitted(end, "end");
    if (start.compareTo(end) > 0) {
        throw new IllegalArgumentException("Requires start on or before end.");
    }
    boolean emptyRange = false;
    int startIndex = getIndex(start);
    if (startIndex < 0) {
        startIndex = -(startIndex + 1);
        if (startIndex == this.data.size()) {
            emptyRange = true; // start is after last data item
        }
    }
    int endIndex = getIndex(end);
    if (endIndex < 0) { // end period is not in original series
        endIndex = -(endIndex + 1); // this is first item AFTER end period
        endIndex = endIndex - 1; // so this is last item BEFORE end
    }
    if ((endIndex < 0) || (endIndex < startIndex)) {
        emptyRange = true;
    }
    if (emptyRange) {
        TimeSeries copy = (TimeSeries) super.clone();
        copy.data = new java.util.ArrayList();
        return copy;
    }
    return createCopy(startIndex, endIndex);
}