List of usage examples for org.joda.time Interval gap
public Interval gap(ReadableInterval interval)
From source file:com.yahoo.bard.webservice.util.SimplifiedIntervalList.java
License:Apache License
/** * Given a sorted linked list of intervals, add the following interval to the end, merging the incoming interval * to any tail intervals which overlap or abut with it. * <p>//from w w w. j av a2 s. c om * In the case where added intervals are at the end of the list, this is efficient. In the case where they are not, * this degrades to an insertion sort. * * @param interval The interval to be merged and added to this list */ private void appendWithMerge(Interval interval) { // Do not store empty intervals if (interval.toDurationMillis() == 0) { return; } if (isEmpty()) { addLast(interval); return; } final Interval previous = peekLast(); // If this interval does not belong at the end, removeLast until it does if (interval.getStart().isBefore(previous.getStart())) { mergeInner(interval); return; } if (previous.gap(interval) != null) { addLast(interval); return; } removeLast(); Interval newEnd = new Interval(Math.min(previous.getStartMillis(), interval.getStartMillis()), Math.max(previous.getEndMillis(), interval.getEndMillis())); addLast(newEnd); }