List of usage examples for org.joda.time Interval getEnd
public DateTime getEnd()
From source file:cz.cesnet.shongo.controller.booking.room.RoomEndpoint.java
/** * @param slot//from w w w . j ava 2 s .c om * @param slotBefore * @param slotAfter * @return original slot from given {@code slot} and {@code slotBefore} and {@code slotAfter} */ public static Interval getOriginalSlot(Interval slot, Period slotBefore, Period slotAfter) { DateTime start = slot.getStart().plus(slotBefore); DateTime end = slot.getEnd().minus(slotAfter); if (end.isBefore(start)) { end = start; } return new Interval(start, end); }
From source file:cz.cesnet.shongo.controller.booking.room.RoomReservationTask.java
/** * Constructor./*from w ww . j a v a 2s .c o m*/ * * @param schedulerContext sets the {@link #schedulerContext} * @param slot sets the {@link #slot} * @param slotMinutesBefore sets the {@link #slotMinutesBefore} * @param slotMinutesAfter sets the {@link #slotMinutesAfter} */ public RoomReservationTask(SchedulerContext schedulerContext, Interval slot, int slotMinutesBefore, int slotMinutesAfter) { super(schedulerContext, new Interval(slot.getStart().minusMinutes(slotMinutesBefore), slot.getEnd().plusMinutes(slotMinutesAfter))); this.slotMinutesBefore = slotMinutesBefore; this.slotMinutesAfter = slotMinutesAfter; }
From source file:cz.cesnet.shongo.controller.scheduler.SchedulerContext.java
/** * @param roomProviderCapability/* w w w.j a v a 2 s . c o m*/ * @param slot * @param reservationTask * @return {@link AvailableRoom} for given {@code roomProviderCapability} in given {@code interval} */ public AvailableRoom getAvailableRoom(RoomProviderCapability roomProviderCapability, Interval slot, ReservationTask reservationTask) { int usedLicenseCount = 0; ResourceCache resourceCache = cache.getResourceCache(); if (resourceCache.isResourceAvailable(roomProviderCapability.getResource(), slot, this, reservationTask)) { ReservationManager reservationManager = new ReservationManager(entityManager); List<RoomReservation> roomReservations = reservationManager.getRoomReservations(roomProviderCapability, slot); state.applyReservations(roomProviderCapability.getId(), slot, roomReservations, RoomReservation.class); RangeSet<RoomReservation, DateTime> rangeSet = new RangeSet<RoomReservation, DateTime>() { @Override protected Bucket<DateTime, RoomReservation> createBucket(DateTime rangeValue) { return new RoomBucket(rangeValue); } }; for (RoomReservation roomReservation : roomReservations) { rangeSet.add(roomReservation, roomReservation.getSlotStart(), roomReservation.getSlotEnd()); } List<RoomBucket> roomBuckets = new LinkedList<RoomBucket>(); roomBuckets.addAll(rangeSet.getBuckets(slot.getStart(), slot.getEnd(), RoomBucket.class)); Collections.sort(roomBuckets, new Comparator<RoomBucket>() { @Override public int compare(RoomBucket roomBucket1, RoomBucket roomBucket2) { return -Double.compare(roomBucket1.getLicenseCount(), roomBucket2.getLicenseCount()); } }); if (roomBuckets.size() > 0) { RoomBucket roomBucket = roomBuckets.get(0); usedLicenseCount = roomBucket.getLicenseCount(); } } else { usedLicenseCount = roomProviderCapability.getLicenseCount(); } return new AvailableRoom(roomProviderCapability, usedLicenseCount); }
From source file:de.alpharogroup.date.IntervalUtils.java
License:Open Source License
public static boolean isBetween(final Interval timeRange, final Interval timeRangeToCheck) { if (timeRange.getStart() != null && !timeRange.getStart().isAfter(timeRangeToCheck.getEnd())) { if (timeRange.getEnd() != null && !timeRange.getEnd().isBefore(timeRangeToCheck.getStart())) { return true; }/*from w ww . ja v a 2 s .com*/ } return false; }
From source file:de.avanux.smartapplianceenabler.appliance.DayTimeframe.java
License:Open Source License
@Override public List<TimeframeInterval> getIntervals(LocalDateTime now) { List<TimeframeInterval> intervals = new ArrayList<>(); if (start != null && end != null) { Interval interval = buildMidnightAdjustedInterval(now); List<Integer> dowValues = getDaysOfWeekValues(); // if today's interval already ended we ignore today int dayOffset = (interval.getEnd().isBefore(now.toDateTime()) ? 1 : 0); for (int i = dayOffset; i < 7 + dayOffset; i++) { DateTime timeFrameStart = interval.getStart().plusDays(i); DateTime timeFrameEnd = interval.getEnd().plusDays(i); if (dowValues != null) { int dow = timeFrameStart.getDayOfWeek(); if (dowValues.contains(DOW_HOLIDAYS) && isHoliday(timeFrameStart.toLocalDate())) { dow = DOW_HOLIDAYS;/*from w ww .j a v a 2 s.co m*/ } if (dowValues.contains(dow)) { intervals.add(new TimeframeInterval(this, new Interval(timeFrameStart, timeFrameEnd))); } } else { intervals.add(new TimeframeInterval(this, new Interval(timeFrameStart, timeFrameEnd))); } } } return intervals; }
From source file:de.avanux.smartapplianceenabler.appliance.Schedule.java
License:Open Source License
/** * Returns the current or next timeframe if the remaining time is greater than maximum running time; otherwise the next timeframe is returned. * @param now the time reference//from ww w . ja v a 2s . c o m * @param schedules the list of timeframes to choose from (current timeframe has to be first) * @param onlyAlreadyStarted consider only timeframe intervals already started * @param onlySufficient if true consider timeframe already started only if time to interval end exceeds min running time * @return the next timeframe becoming valid or null */ public static TimeframeInterval getCurrentOrNextTimeframeInterval(LocalDateTime now, List<Schedule> schedules, boolean onlyAlreadyStarted, boolean onlySufficient) { if (schedules == null || schedules.size() == 0) { return null; } Map<Long, TimeframeInterval> startDelayOfTimeframeInterval = new TreeMap<>(); for (Schedule schedule : schedules) { Timeframe timeframe = schedule.getTimeframe(); timeframe.setSchedule(schedule); List<TimeframeInterval> timeframeIntervals = timeframe.getIntervals(now); for (TimeframeInterval timeframeInterval : timeframeIntervals) { Interval interval = timeframeInterval.getInterval(); if (interval.contains(now.toDateTime())) { // interval already started ... if (onlySufficient) { if (now.plusSeconds(schedule.getMaxRunningTime()).plusSeconds(additionalRunningTime) .isBefore(new LocalDateTime(interval.getEnd()))) { // ... with remaining running time sufficient return timeframeInterval; } } else { return timeframeInterval; } } else if (!onlyAlreadyStarted) { // interval starts in future startDelayOfTimeframeInterval.put(interval.getStartMillis() - now.toDateTime().getMillis(), timeframeInterval); } } } if (startDelayOfTimeframeInterval.size() > 0) { Long startDelay = startDelayOfTimeframeInterval.keySet().iterator().next(); return startDelayOfTimeframeInterval.get(startDelay); } return null; }
From source file:de.avanux.smartapplianceenabler.semp.webservice.SempController.java
License:Open Source License
protected de.avanux.smartapplianceenabler.semp.webservice.Timeframe createSempTimeFrame( ApplianceLogger applianceLogger, String deviceId, Schedule schedule, Interval interval, long minRunningTime, long maxRunningTime, LocalDateTime now) { Long earliestStart = 0l;/*from www.ja va 2 s . c o m*/ DateTime start = interval.getStart(); DateTime end = interval.getEnd(); if (start.isAfter(now.toDateTime())) { earliestStart = Double.valueOf(new Interval(now.toDateTime(), start).toDurationMillis() / 1000) .longValue(); } LocalDateTime nowBeforeEnd = new LocalDateTime(now); if (now.toDateTime().isAfter(end)) { nowBeforeEnd = now.minusHours(24); } Long latestEnd = Double.valueOf(new Interval(nowBeforeEnd.toDateTime(), end).toDurationMillis() / 1000) .longValue(); return createSempTimeFrame(applianceLogger, deviceId, earliestStart, latestEnd, minRunningTime, maxRunningTime); }
From source file:de.hpi.bpmn2_0.animation.AnimationJSONBuilder.java
License:Open Source License
protected JSONArray parseSequenceAnalysis() throws JSONException { JSONArray jsonSequences = new JSONArray(); JSONObject jsonObject;// ww w .j av a2s . com if (this.animations.size() >= 2) { Map<String, Map<Interval, Integer>> log1Map = TimeUtilities .aggregateIntervalMap(this.animations.get(0).getIntervalMap()); Map<String, Map<Interval, Integer>> log2Map = TimeUtilities .aggregateIntervalMap(this.animations.get(1).getIntervalMap()); Map<Interval, Integer> compare; for (String sequenceId : log1Map.keySet()) { if (log2Map.containsKey(sequenceId)) { compare = TimeUtilities.compareIntervalMaps(log1Map.get(sequenceId), log2Map.get(sequenceId)); for (Interval interval : compare.keySet()) { if (Math.abs(compare.get(interval)) > params.getSequenceTokenDiffThreshold()) { jsonObject = new JSONObject(); jsonObject.put("sequenceId", sequenceId); jsonObject.put("from", this.getEngineTime(interval.getStart())); jsonObject.put("to", this.getEngineTime(interval.getEnd())); jsonSequences.put(jsonObject); } } } } } return jsonSequences; }
From source file:de.hpi.bpmn2_0.replay.TimeUtilities.java
License:Open Source License
private static Map<Interval, Integer> aggregateIntervals(SortedSet<Interval> intervals) { SortedSet<DateTime> timeline = new TreeSet<>(new Comparator<DateTime>() { @Override//ww w.java 2 s. c o m public int compare(DateTime o1, DateTime o2) { if (o1.isBefore(o2)) { return -1; } else { return +1; } } }); //----------------------------------------------------- //First, create an ordered timeline based on intervals //The date milestone on the timeline is the start and end date of each interval //Note: if two datetime are equal, two duplicate elements are on the timeline //----------------------------------------------------- Set<DateTime> starts = new HashSet(); Set<DateTime> ends = new HashSet(); for (Interval interval : intervals) { timeline.add(interval.getStart()); //added datetime will be arranged in timing order starts.add(interval.getStart()); timeline.add(interval.getEnd()); ends.add(interval.getEnd()); } //------------------------------------------------ //Then, traverse the timeline to count tokens //current-next traverses every interval on the timeline formed by two //consecutive datetime points //------------------------------------------------ DateTime current = null; DateTime next = null; Iterator<DateTime> iterator = timeline.iterator(); int intervalCount = 0; Map<Interval, Integer> intervalCountMap = new HashMap(); while (iterator.hasNext()) { if (current == null) { current = iterator.next(); } else { current = next; } if (iterator.hasNext()) { next = iterator.next(); if (starts.contains(current)) { intervalCount++; } if (ends.contains(current)) { intervalCount--; } if (current.isBefore(next)) { intervalCountMap.put(new Interval(current, next), intervalCount); } } } return intervalCountMap; }
From source file:de.hpi.bpmn2_0.replay.TimeUtilities.java
License:Open Source License
public static Map<Interval, Integer> compareIntervalMaps(Map<Interval, Integer> map1, Map<Interval, Integer> map2) { Map<Interval, Integer> resultMap = new HashMap(); SortedSet<DateTime> timeline = new TreeSet<>(new Comparator<DateTime>() { @Override/*from ww w.j av a2 s. c o m*/ public int compare(DateTime o1, DateTime o2) { if (o1.isBefore(o2)) { return -1; } else if (o1.isEqual(o2)) { //if two points are the same, only one is added return 0; } else { return +1; } } }); //------------------------------------------- // Put all start and end points of all intervals on a timeline // Note: if two points of time are the same, only one is kept on timeline //------------------------------------------- for (Interval interval : map1.keySet()) { timeline.add(interval.getStart()); //added datetime will be arranged in timing order timeline.add(interval.getEnd()); } for (Interval interval : map2.keySet()) { timeline.add(interval.getStart()); timeline.add(interval.getEnd()); } //---------------------------------------------- //Traverse the timeline and compare intervals of map1,map2 //current-next traverses every interval on the timeline formed //by two consecutive datetime points //---------------------------------------------- DateTime current = null; DateTime next = null; Interval timelineInterval; Iterator<DateTime> iterator = timeline.iterator(); while (iterator.hasNext()) { if (current == null) { current = iterator.next(); } else { current = next; } if (iterator.hasNext()) { next = iterator.next(); if (current.isBefore(next)) { timelineInterval = new Interval(current, next); resultMap.put(timelineInterval, getIntervalCount(timelineInterval, map1) - getIntervalCount(timelineInterval, map2)); } } } return resultMap; }