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

The following examples show how to use org.joda.time.Interval#overlaps() . 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: SearchOccupationsDA.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static Multimap<Occupation, Interval> getEventSpaceOccupations(Space space, Interval searchInterval) {
    Multimap<Occupation, Interval> result = HashMultimap.create();
    for (Occupation occupation : space.getOccupationSet()) {
        for (Interval occupationInterval : occupation.getIntervals()) {
            if (occupationInterval.overlaps(searchInterval)) {
                result.put(occupation, occupationInterval);
            }
        }
    }
    return result;
}
 
Example 2
Source File: WrittenEvaluationSpaceOccupation.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected boolean overlaps(final Interval interval) {
    for (final WrittenEvaluation writtenEvaluation : getWrittenEvaluationsSet()) {
        final Interval evaluationInterval = writtenEvaluation.getInterval();
        if (interval.overlaps(evaluationInterval)) {
            return true;
        }
    }
    return false;
}
 
Example 3
Source File: EventSpaceOccupation.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
public List<Interval> getEventSpaceOccupationIntervals(DateTime start, DateTime end) {
    final Interval i = new Interval(start, end);
    final List<Interval> intervals = getEventSpaceOccupationIntervals(start.toYearMonthDay(), end.toYearMonthDay());
    for (final Iterator<Interval> iterator = intervals.iterator(); iterator.hasNext();) {
        final Interval interval = iterator.next();
        if (!interval.overlaps(i)) {
            iterator.remove();
        }
    }
    return intervals;
}
 
Example 4
Source File: LessonInstanceSpaceOccupation.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected boolean overlaps(final Interval interval) {
    for (final LessonInstance instance : getLessonInstancesSet()) {
        final Interval lessonInterval = instance.getInterval();
        if (interval.overlaps(lessonInterval)) {
            return true;
        }
    }
    return false;
}
 
Example 5
Source File: RoomSiteComponentBuilder.java    From fenixedu-academic with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static InfoSiteRoomTimeTable getInfoSiteRoomTimeTable(Calendar day, Space room, ExecutionSemester executionSemester) {

        List<InfoObject> infoShowOccupations = new ArrayList<InfoObject>();

        Calendar startDay = Calendar.getInstance();
        startDay.setTimeInMillis(day.getTimeInMillis());
        startDay.add(Calendar.DATE, Calendar.MONDAY - day.get(Calendar.DAY_OF_WEEK));

        Calendar endDay = Calendar.getInstance();
        endDay.setTimeInMillis(startDay.getTimeInMillis());
        endDay.add(Calendar.DATE, 6);

        // final boolean isCurrentUserRoomManager =
        // isCurrentUserRoomManager(room);

        final YearMonthDay weekStartYearMonthDay = YearMonthDay.fromCalendarFields(startDay);
        final YearMonthDay weekEndYearMonthDay = YearMonthDay.fromCalendarFields(endDay);

        final Interval search =
                new Interval(weekStartYearMonthDay.toDateTimeAtMidnight(), weekEndYearMonthDay.toDateTimeAtMidnight());

        for (final Occupation roomOccupation : room.getOccupationSet()) {

            if (roomOccupation instanceof WrittenEvaluationSpaceOccupation) {
                Collection<WrittenEvaluation> writtenEvaluations =
                        ((WrittenEvaluationSpaceOccupation) roomOccupation).getWrittenEvaluationsSet();
                getWrittenEvaluationRoomOccupations(infoShowOccupations, weekStartYearMonthDay, weekEndYearMonthDay,
                        writtenEvaluations);
            } else if (roomOccupation instanceof LessonSpaceOccupation) {
                final Lesson lesson = ((LessonSpaceOccupation) roomOccupation).getLesson();
                getLessonOccupations(infoShowOccupations, weekStartYearMonthDay, weekEndYearMonthDay, lesson);
            } else if (roomOccupation instanceof LessonInstanceSpaceOccupation) {
                Collection<LessonInstance> lessonInstances =
                        ((LessonInstanceSpaceOccupation) roomOccupation).getLessonInstancesSet();
                getLessonInstanceOccupations(infoShowOccupations, weekStartYearMonthDay, weekEndYearMonthDay, lessonInstances);
            } else {
                for (Interval interval : roomOccupation.getIntervals()) {
                    if (search.overlaps(interval)) {
                        infoShowOccupations.add(new InfoOccupation(roomOccupation, interval));
                    }
                }
            }
        }
        InfoSiteRoomTimeTable component = new InfoSiteRoomTimeTable();

        component.setInfoShowOccupation(infoShowOccupations);
        component.setInfoRoom(InfoRoom.newInfoFromDomain(room));

        return component;
    }