List of usage examples for org.joda.time Interval overlaps
public boolean overlaps(ReadableInterval interval)
From source file:org.apache.druid.timeline.VersionedIntervalTimeline.java
License:Apache License
private List<TimelineObjectHolder<VersionType, ObjectType>> lookup(Interval interval, boolean incompleteOk) { List<TimelineObjectHolder<VersionType, ObjectType>> retVal = new ArrayList<>(); NavigableMap<Interval, TimelineEntry> timeline = (incompleteOk) ? incompletePartitionsTimeline : completePartitionsTimeline; for (Entry<Interval, TimelineEntry> entry : timeline.entrySet()) { Interval timelineInterval = entry.getKey(); TimelineEntry val = entry.getValue(); if (timelineInterval.overlaps(interval)) { retVal.add(new TimelineObjectHolder<>(timelineInterval, val.getTrueInterval(), val.getVersion(), new PartitionHolder<>(val.getPartitionHolder()))); }// w w w.j a va2 s .co m } if (retVal.isEmpty()) { return retVal; } TimelineObjectHolder<VersionType, ObjectType> firstEntry = retVal.get(0); if (interval.overlaps(firstEntry.getInterval()) && interval.getStart().isAfter(firstEntry.getInterval().getStart())) { retVal.set(0, new TimelineObjectHolder<>(new Interval(interval.getStart(), firstEntry.getInterval().getEnd()), firstEntry.getTrueInterval(), firstEntry.getVersion(), firstEntry.getObject())); } TimelineObjectHolder<VersionType, ObjectType> lastEntry = retVal.get(retVal.size() - 1); if (interval.overlaps(lastEntry.getInterval()) && interval.getEnd().isBefore(lastEntry.getInterval().getEnd())) { retVal.set(retVal.size() - 1, new TimelineObjectHolder<>(new Interval(lastEntry.getInterval().getStart(), interval.getEnd()), lastEntry.getTrueInterval(), lastEntry.getVersion(), lastEntry.getObject())); } return retVal; }
From source file:org.fenixedu.academic.service.factory.RoomSiteComponentBuilder.java
License:Open Source License
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);/*from w w w . ja va 2s . com*/ } 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; }
From source file:org.fenixedu.academic.ui.struts.action.resourceAllocationManager.SearchOccupationsDA.java
License:Open Source License
@Atomic public static Collection<SpaceOccupationEventBean> run(Space building, DateTime start, DateTime end, List<OccupationType> types) { final Set<SpaceOccupationEventBean> beans = new HashSet<SpaceOccupationEventBean>(); end = end.plusDays(1);// w w w . j a v a 2 s. c om final Interval searchInterval = new Interval(start, end); for (Space space : getAllChildren(building)) { final Map<Occupation, Collection<Interval>> map = getEventSpaceOccupations(space, searchInterval) .asMap(); final Set<Occupation> spaceOccupations = map.keySet(); if (spaceOccupations.isEmpty()) { continue; } for (Occupation occupation : spaceOccupations) { OccupationType occupationType = getType(occupation); if (!types.contains(occupationType)) { continue; } if (occupation instanceof WrittenEvaluationSpaceOccupation) { WrittenEvaluationSpaceOccupation evalOccupation = (WrittenEvaluationSpaceOccupation) occupation; for (WrittenEvaluation eval : evalOccupation.getWrittenEvaluationsSet()) { final Interval durationInterval = eval.getDurationInterval(); if (searchInterval.overlaps(durationInterval)) { String desc; if (eval instanceof WrittenTest) { desc = String.format("(%s) %s - %s", eval.getEvaluationType(), eval.getName(), ((WrittenTest) eval).getDescription()); } else { desc = String.format("(%s) %s", eval.getEvaluationType(), eval.getName()); } beans.add(new SpaceOccupationEventBean(space, durationInterval, desc, occupationType)); } } } else { final String desc = getPresentationString(occupation); for (Interval interval : map.get(occupation)) { beans.add(new SpaceOccupationEventBean(space, interval, desc, occupationType)); } } } } return beans; }
From source file:org.fenixedu.academic.ui.struts.action.resourceAllocationManager.SearchOccupationsDA.java
License:Open Source License
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); }/*from w w w .j a v a 2s.c om*/ } } return result; }
From source file:org.fenixedu.spaces.domain.occupation.Occupation.java
License:Open Source License
public Boolean overlaps(List<Interval> intervals) { for (final Interval interval : intervals) { for (final Interval occupationInterval : getIntervals()) { if (occupationInterval.overlaps(interval)) { return true; }/* ww w.j av a 2s . c om*/ } } return false; }
From source file:org.fenixedu.spaces.domain.occupation.Occupation.java
License:Open Source License
public boolean overlaps(Interval... intervals) { for (final Interval interval : intervals) { for (final Interval occupationInterval : getIntervals()) { if (occupationInterval.overlaps(interval)) { return true; }//from www. j a va 2s .c om } } return false; }
From source file:org.fenixedu.spaces.ui.services.OccupationService.java
License:Open Source License
public String getOccupations(Space space, Interval search) { JsonArray events = new JsonArray(); int id = 1;// ww w . j a v a 2s . co m for (Occupation occupation : space.getOccupationSet()) { boolean hasEvents = false; for (Interval interval : occupation.getIntervals()) { if (interval.overlaps(search)) { JsonObject event = new JsonObject(); String start = new Long(interval.getStart().getMillis() / 1000).toString(); String end = new Long(interval.getEnd().getMillis() / 1000).toString(); event.addProperty("id", id); event.addProperty("start", start); event.addProperty("end", end); event.addProperty("title", occupation.getSubject()); String url = occupation.getUrl(); if (url != null && !url.isEmpty()) { event.addProperty("url", url); } event.addProperty("allDay", false); event.addProperty("backgroundColor", colors[id % colors.length]); event.addProperty("info", occupation.getInfo()); events.add(event); if (!hasEvents) { hasEvents = true; } } } if (hasEvents) { id++; } } return events.toString(); }
From source file:org.jasig.portlet.calendar.adapter.CalendarEventsDao.java
License:Apache License
/** * Get a JSON-appropriate representation of each recurrence of an event * within the specified time period./*w ww. j a va2 s. c om*/ * * @param e * @param interval * @param usersConfiguredDateTimeZone * @return * @throws IOException * @throws URISyntaxException * @throws ParseException */ protected Set<CalendarDisplayEvent> getDisplayEvents(VEvent e, Interval interval, Locale locale, DateTimeZone usersConfiguredDateTimeZone) throws IOException, URISyntaxException, ParseException { final VEvent event = (VEvent) e.copy(); DateTime eventStart; DateTime eventEnd = null; if (event.getStartDate().getTimeZone() == null && !event.getStartDate().isUtc()) { if (log.isDebugEnabled()) { log.debug("Identified event " + event.getSummary() + " as a floating event"); } int offset = usersConfiguredDateTimeZone.getOffset(event.getStartDate().getDate().getTime()); eventStart = new DateTime(event.getStartDate().getDate().getTime() - offset, usersConfiguredDateTimeZone); if (event.getEndDate() != null) { eventEnd = new DateTime(event.getEndDate().getDate().getTime() - offset, usersConfiguredDateTimeZone); } } else { eventStart = new DateTime(event.getStartDate().getDate(), usersConfiguredDateTimeZone); if (event.getEndDate() != null) { eventEnd = new DateTime(event.getEndDate().getDate(), usersConfiguredDateTimeZone); } } if (eventEnd == null) { eventEnd = eventStart; } // Multi-day events may begin in the past; make sure to choose a date in range for the first pass... final Date firstDayToProcess = interval.contains(event.getStartDate().getDate().getTime()) ? event.getStartDate().getDate() : interval.getStart().toDate(); DateMidnight startOfTheSpecificDay = new DateMidnight(firstDayToProcess, usersConfiguredDateTimeZone); DateMidnight endOfTheSpecificDay = startOfTheSpecificDay.plusDays(1); final DateTimeFormatter df = getDateFormatter(locale, usersConfiguredDateTimeZone); final DateTimeFormatter tf = getTimeFormatter(locale, usersConfiguredDateTimeZone); final Set<CalendarDisplayEvent> events = new HashSet<CalendarDisplayEvent>(); final Interval eventInterval = new Interval(eventStart, eventEnd); do { final Interval theSpecificDay = new Interval(startOfTheSpecificDay.getMillis(), endOfTheSpecificDay.getMillis(), usersConfiguredDateTimeZone); /* * Test if the event interval abuts the start of the day or is within the day. * This start time check is needed for the corner case where a zero duration interval * is set for midnight. * The start times are tested directly as opposed to using abuts() because that method * also returns true if the intervals abut at the end of the day. We want to associate * instant events that start at midnight with the starting day, not the ending day. */ if (theSpecificDay.getStart().isEqual(eventStart) || theSpecificDay.overlaps(eventInterval)) { final CalendarDisplayEvent json = new CalendarDisplayEvent(event, eventInterval, theSpecificDay, df, tf); events.add(json); } startOfTheSpecificDay = startOfTheSpecificDay.plusDays(1); endOfTheSpecificDay = endOfTheSpecificDay.plusDays(1); } while (!startOfTheSpecificDay.isAfter(eventEnd) && interval.contains(startOfTheSpecificDay)); return events; }
From source file:org.jasig.portlet.calendar.mvc.CalendarDisplayEvent.java
License:Apache License
/** * Constructs an object from specified data. * * @param event "Raw" Event object// w w w. j a va2 s. c om * @param eventInterval Interval portion of the event that applies to this specific day * @param theSpecificDay Interval of the specific day in question * @param df date formatter to represent date displays * @param tf time formatter to represent time displays */ public CalendarDisplayEvent(VEvent event, Interval eventInterval, Interval theSpecificDay, DateTimeFormatter df, DateTimeFormatter tf) { assert theSpecificDay.abuts(eventInterval) || theSpecificDay.overlaps(eventInterval) : "Event interval is not in the specified day!"; this.summary = event.getSummary() != null ? event.getSummary().getValue() : null; this.description = event.getDescription() != null ? event.getDescription().getValue() : null; this.location = event.getLocation() != null ? event.getLocation().getValue() : null; boolean multi = false; if (eventInterval.getStart().isBefore(theSpecificDay.getStart())) { dayStart = theSpecificDay.getStart(); multi = true; } else { dayStart = eventInterval.getStart(); } if (event.getEndDate() == null) { dayEnd = dayStart; } else if (eventInterval.getEnd().isAfter(theSpecificDay.getEnd())) { dayEnd = theSpecificDay.getEnd(); multi = true; } else { dayEnd = eventInterval.getEnd(); } this.isMultiDay = multi; this.dateStartTime = tf.print(dayStart); this.startTime = tf.print(eventInterval.getStart()); this.startDate = df.print(eventInterval.getStart()); if (event.getEndDate() != null) { this.dateEndTime = tf.print(dayEnd); this.endTime = tf.print(eventInterval.getEnd()); this.endDate = df.print(eventInterval.getEnd()); } else { this.dateEndTime = null; this.endTime = null; this.endDate = null; } Interval dayEventInterval = new Interval(dayStart, dayEnd); this.isAllDay = dayEventInterval.equals(theSpecificDay); }
From source file:org.kalypso.ui.rrm.internal.calccase.CatchmentModelHelper.java
License:Open Source License
/** * This function compares the validity ranges of the generators. * * @param compareGenerator/*from w ww. ja va2s .c o m*/ * The compare generator. * @param generators * All generators the compare generator will be compared against. If the compare generator is contained, it * will be ignored. * @return <ul> * <li>True: The validity range of the compare generator does not overlap the validity ranges of the other * generators.</li> * <li>False: The validity range of the compare generator overlaps one validity range of the other generators. * </li> * </ul> */ private static boolean compareGeneratorValidityOverlap(final IRainfallGenerator compareGenerator, final IRainfallGenerator[] generators) { /* No generators available, to compare to. */ if (generators.length == 0) return true; /* The interval of the compare generator. */ final Interval compareInterval = new Interval(new DateTime(compareGenerator.getValidFrom()), new DateTime(compareGenerator.getValidTo())); /* Check if the interval overlaps one of the other intervals. */ for (final IRainfallGenerator generator : generators) { /* Do not compare the compare generator with itself. */ if (compareGenerator.getId().equals(generator.getId())) continue; /* The interval of the generator. */ final Interval interval = new Interval(new DateTime(generator.getValidFrom()), new DateTime(generator.getValidTo())); if (compareInterval.overlaps(interval)) { final Interval overlapInterval = compareInterval.overlap(interval); final Duration overlapDuration = overlapInterval.toDuration(); final long standardMinutes = overlapDuration.getStandardMinutes(); if (standardMinutes > 0) return false; } } return true; }