List of usage examples for org.joda.time Interval overlaps
public boolean overlaps(ReadableInterval interval)
From source file:io.druid.timeline.VersionedIntervalTimeline.java
License:Apache License
/** * * @param timeline/*from ww w . j ava 2 s . c o m*/ * @param key * @param entry * @return boolean flag indicating whether or not we inserted or discarded something */ private boolean addAtKey(NavigableMap<Interval, TimelineEntry> timeline, Interval key, TimelineEntry entry) { boolean retVal = false; Interval currKey = key; Interval entryInterval = entry.getTrueInterval(); if (!currKey.overlaps(entryInterval)) { return false; } while (entryInterval != null && currKey != null && currKey.overlaps(entryInterval)) { Interval nextKey = timeline.higherKey(currKey); int versionCompare = versionComparator.compare(entry.getVersion(), timeline.get(currKey).getVersion()); if (versionCompare < 0) { if (currKey.contains(entryInterval)) { return true; } else if (currKey.getStart().isBefore(entryInterval.getStart())) { entryInterval = new Interval(currKey.getEnd(), entryInterval.getEnd()); } else { addIntervalToTimeline(new Interval(entryInterval.getStart(), currKey.getStart()), entry, timeline); if (entryInterval.getEnd().isAfter(currKey.getEnd())) { entryInterval = new Interval(currKey.getEnd(), entryInterval.getEnd()); } else { entryInterval = null; // discard this entry } } } else if (versionCompare > 0) { TimelineEntry oldEntry = timeline.remove(currKey); if (currKey.contains(entryInterval)) { addIntervalToTimeline(new Interval(currKey.getStart(), entryInterval.getStart()), oldEntry, timeline); addIntervalToTimeline(new Interval(entryInterval.getEnd(), currKey.getEnd()), oldEntry, timeline); addIntervalToTimeline(entryInterval, entry, timeline); return true; } else if (currKey.getStart().isBefore(entryInterval.getStart())) { addIntervalToTimeline(new Interval(currKey.getStart(), entryInterval.getStart()), oldEntry, timeline); } else if (entryInterval.getEnd().isBefore(currKey.getEnd())) { addIntervalToTimeline(new Interval(entryInterval.getEnd(), currKey.getEnd()), oldEntry, timeline); } } else { if (timeline.get(currKey).equals(entry)) { // This occurs when restoring segments timeline.remove(currKey); } else { throw new UnsupportedOperationException( String.format("Cannot add overlapping segments [%s and %s] with the same version [%s]", currKey, entryInterval, entry.getVersion())); } } currKey = nextKey; retVal = true; } addIntervalToTimeline(entryInterval, entry, timeline); return retVal; }
From source file:julian.lylly.model.Task.java
static void checkDistinctness(List<Interval> intervals) { for (int i = 0; i < intervals.size(); i++) { Interval x = intervals.get(i); for (int j = i + 1; j < intervals.size(); j++) { Interval y = intervals.get(j); if (x.overlaps(y)) { throw new IllegalArgumentException(x.toString() + " overlaps " + y.toString()); }//from w w w . ja v a 2s .co m } } }
From source file:julian.lylly.model.Task.java
private Duration computeOverlap(Interval x, Interval y) { if (x.overlaps(y)) { return x.overlap(y).toDuration(); } else {/* ww w. j ava 2s. c om*/ return Duration.ZERO; } }
From source file:module.mission.domain.NationalMission.java
License:Open Source License
private boolean overlapsMeal(final Interval interval, final DateTime dateTime, final int hour) { final Interval mealTime = new Interval(dateTime.withTime(hour, 0, 0, 0), Hours.ONE); return interval.overlaps(mealTime); }
From source file:net.oauth.jsontoken.SystemClock.java
License:Apache License
/** * Determines whether the current time (plus minus the acceptableClockSkew) falls within the * interval defined by the start and intervalLength parameters. *///from ww w .j a v a 2s . co m @Override public boolean isCurrentTimeInInterval(Instant start, Instant end) { Interval interval = new Interval(start, end); Instant now = now(); Interval currentTimeWithSkew = new Interval(now.minus(acceptableClockSkew), now.plus(acceptableClockSkew)); return interval.overlaps(currentTimeWithSkew); }
From source file:net.sourceforge.fenixedu.applicationTier.Factory.RoomSiteComponentBuilder.java
License:Open Source License
private ISiteComponent getInfoSiteRoomTimeTable(InfoSiteRoomTimeTable component, Calendar day, Space room, ExecutionSemester executionSemester) throws Exception { 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);//from ww w . java2 s. co m } else { for (Interval interval : roomOccupation.getIntervals()) { if (search.overlaps(interval)) { infoShowOccupations.add(new InfoOccupation(roomOccupation, interval)); } } } } component.setInfoShowOccupation(infoShowOccupations); component.setInfoRoom(InfoRoom.newInfoFromDomain(room)); return component; }
From source file:net.sourceforge.fenixedu.domain.personnelSection.contracts.PersonContractSituation.java
License:Open Source License
public boolean overlaps(final Interval interval) { Interval situationInterval = getInterval(); return getBeginDate() != null && ((situationInterval != null && situationInterval.overlaps(interval)) || (situationInterval == null && !getBeginDate().isAfter(interval.getEnd().toLocalDate()))); }
From source file:net.sourceforge.fenixedu.domain.personnelSection.contracts.PersonProfessionalCategory.java
License:Open Source License
public boolean overlaps(final Interval interval) { Interval categoryInterval = getInterval(); return getBeginDate() != null && ((categoryInterval != null && categoryInterval.overlaps(interval)) || (categoryInterval == null && !getBeginDate().isAfter(interval.getEnd().toLocalDate()))); }
From source file:net.sourceforge.fenixedu.domain.personnelSection.contracts.PersonProfessionalRegime.java
License:Open Source License
public boolean overlaps(final Interval interval) { Interval regimeInterval = getInterval(); return getBeginDate() != null && ((regimeInterval != null && regimeInterval.overlaps(interval)) || (regimeInterval == null && !getBeginDate().isAfter(interval.getEnd().toLocalDate()))); }
From source file:net.sourceforge.fenixedu.domain.phd.PhdIndividualProgramProcess.java
License:Open Source License
public boolean isActive(Interval interval) { List<Interval> activeStatesIntervals = new ArrayList<Interval>(); Set<PhdProgramProcessState> states = new TreeSet<PhdProgramProcessState>(new Comparator<PhdProcessState>() { @Override/*from w w w. j a v a 2s . co m*/ public int compare(PhdProcessState o1, PhdProcessState o2) { DateTime o1StateDate = o1.getStateDate() == null ? o1.getWhenCreated() : o1.getStateDate(); DateTime o2StateDate = o2.getStateDate() == null ? o2.getWhenCreated() : o2.getStateDate(); int result = o1StateDate.compareTo(o2StateDate); return result != 0 ? result : o1.getExternalId().compareTo(o2.getExternalId()); } }); states.addAll(getStates()); DateTime beginActiveDate = null; for (PhdProgramProcessState state : states) { if (state.getType().isActive() && beginActiveDate == null) { beginActiveDate = state.getStateDate() == null ? state.getWhenCreated() : state.getStateDate(); } if ((!state.getType().isActive()) && beginActiveDate != null) { activeStatesIntervals.add(new Interval(beginActiveDate, state.getStateDate() == null ? state.getWhenCreated() : state.getStateDate())); beginActiveDate = null; } } for (Interval activeInterval : activeStatesIntervals) { if (interval.overlaps(activeInterval)) { return true; } } return (activeStatesIntervals.size() == 0 && beginActiveDate != null); }