Java Code Examples for org.joda.time.Interval#getEnd()

The following examples show how to use org.joda.time.Interval#getEnd() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IntervalUtils.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
/**
 * This method is designed to merge a list of intervals to a list of intervals with no overlap in between
 * @param intervals
 * @return
 * a list of intervals with no overlap in between
 */
public static List<Interval> mergeIntervals (List<Interval> intervals) {
  if(intervals == null || intervals.size() == 0) {
    return intervals;
  }
  // Sort Intervals
  Collections.sort(intervals, new Comparator<Interval>() {
    @Override
    public int compare(Interval o1, Interval o2) {
      return o1.getStart().compareTo(o2.getStart());
    }
  });

  // Merge intervals
  Stack<Interval> intervalStack = new Stack<>();
  intervalStack.push(intervals.get(0));

  for(int i = 1; i < intervals.size(); i++) {
    Interval top = intervalStack.peek();
    Interval target = intervals.get(i);

    if(top.overlap(target) == null && (top.getEnd() != target.getStart())) {
      intervalStack.push(target);
    }
    else if(top.equals(target)) {
      continue;
    }
    else {
      Interval newTop = new Interval(Math.min(top.getStart().getMillis(), target.getStart().getMillis()),
          Math.max(top.getEnd().getMillis(), target.getEnd().getMillis()));
      intervalStack.pop();
      intervalStack.push(newTop);
    }
  }

  return intervalStack;
}
 
Example 2
Source File: ManageEnrolementPeriodsDA.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
public AbstractEnrolmentPeriodConfiguration(Interval interval, ExecutionSemester semester) {
    if (interval != null) {
        this.start = interval.getStart();
        this.end = interval.getEnd();
    }
    this.semester = semester;
}
 
Example 3
Source File: Lesson.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
public boolean overlaps(final Interval interval) {
    if (wasFinished()) {
        return false;
    }
    final YearMonthDay startDateToSearch = getLessonStartDay();
    if (startDateToSearch == null) {
        return false;
    }
    final YearMonthDay endDateToSearch = getLessonEndDay();
    if (endDateToSearch == null) {
        return false;
    }
    final DateTime intervalStart = interval.getStart();
    if (intervalStart.isAfter(endDateToSearch.toDateTimeAtMidnight().plusDays(1))) {
        return false;
    }
    final DateTime intervalEnd = interval.getEnd();
    if (intervalEnd.isBefore(startDateToSearch.toDateTimeAtMidnight())) {
        return false;
    }
    final HourMinuteSecond b = getBeginHourMinuteSecond();
    final HourMinuteSecond e = getEndHourMinuteSecond();
    for (final YearMonthDay yearMonthDay : getAllValidLessonDatesWithoutInstancesDates(startDateToSearch, endDateToSearch)) {
        if (new Interval(toDateTime(yearMonthDay, b), toDateTime(yearMonthDay, e)).overlaps(interval)) {
            return true;
        }
    }
    return false;
}
 
Example 4
Source File: PersistentInterval.java    From jadira with Apache License 2.0 4 votes vote down vote up
@Override
protected Object[] toConvertedColumns(Interval value) {

    return new Object[] { value.getStart(), value.getEnd() };
}
 
Example 5
Source File: TimePeriod.java    From arctic-sea with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new {@code TimePeriod} from an {@code Interval}.
 *
 * @param interval the interval
 */
public TimePeriod(Interval interval) {
    this(interval.getStart(), interval.getEnd());
}