本文整理汇总了Java中org.joda.time.Interval.getEnd方法的典型用法代码示例。如果您正苦于以下问题:Java Interval.getEnd方法的具体用法?Java Interval.getEnd怎么用?Java Interval.getEnd使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.joda.time.Interval
的用法示例。
在下文中一共展示了Interval.getEnd方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mergeSlots
import org.joda.time.Interval; //导入方法依赖的package包/类
public static List<Interval> mergeSlots(List<Interval> slots) {
if (slots.size() <= 1) {
return slots;
}
slots.sort(Comparator.comparing(AbstractInterval::getStart));
boolean isMerged = false;
List<Interval> merged = new ArrayList<>();
merged.add(slots.get(0));
for (int i = 1; i < slots.size(); ++i) {
Interval first = slots.get(i - 1);
Interval second = slots.get(i);
if (!second.getStart().isAfter(first.getEnd())) {
merged.remove(i - 1);
DateTime laterEnding = first.getEnd().isAfter(second.getEnd()) ? first.getEnd() : second.getEnd();
merged.add(new Interval(first.getStart(), laterEnding));
isMerged = true;
} else {
merged.add(second);
}
}
if (isMerged) {
merged = mergeSlots(merged);
}
// Nothing to merge anymore
return merged;
}
示例2: findGaps
import org.joda.time.Interval; //导入方法依赖的package包/类
public static List<Interval> findGaps(List<Interval> reserved, Interval searchInterval) {
List<Interval> gaps = new ArrayList<>();
DateTime searchStart = searchInterval.getStart();
DateTime searchEnd = searchInterval.getEnd();
if (hasNoOverlap(reserved, searchStart, searchEnd)) {
gaps.add(searchInterval);
return gaps;
}
// create a sub-list that excludes interval which does not overlap with
// searchInterval
List<Interval> subReservedList = removeNonOverlappingIntervals(reserved, searchInterval);
DateTime subEarliestStart = subReservedList.get(0).getStart();
DateTime subLatestEnd = subReservedList.get(subReservedList.size() - 1).getEnd();
// in case the searchInterval is wider than the union of the existing
// include searchInterval.start => earliestExisting.start
if (searchStart.isBefore(subEarliestStart)) {
gaps.add(new Interval(searchStart, subEarliestStart));
}
// get all the gaps in the existing list
gaps.addAll(getExistingIntervalGaps(subReservedList));
// include latestExisting.end => searchInterval.end
if (searchEnd.isAfter(subLatestEnd)) {
gaps.add(new Interval(subLatestEnd, searchEnd));
}
return gaps;
}
示例3: sliceIntervals
import org.joda.time.Interval; //导入方法依赖的package包/类
/**
* Slices the intervals into smaller intervals of the timeGrain duration.
*
* @param interval interval to be sliced
* @param timeGrain size of the slice
*
* @return list of intervals obtained by slicing the larger interval
*
* @throws java.lang.IllegalArgumentException if the interval is not an even multiple of the time grain
*/
public static List<Interval> sliceIntervals(Interval interval, TimeGrain timeGrain) {
// TODO: Refactor me to use a Period
DateTime intervalEnd = interval.getEnd();
DateTime sliceStart = interval.getStart();
DateTime periodStart = timeGrain.roundFloor(sliceStart);
if (!sliceStart.equals(periodStart)) {
LOG.info("Interval {} is not aligned to TimeGrain {} starting {}", interval, timeGrain, periodStart);
throw new IllegalArgumentException("Interval must be aligned to the TimeGrain starting " + periodStart);
}
List<Interval> intervalSlices = new ArrayList<>();
while (sliceStart.isBefore(intervalEnd)) {
// Find the end of the next slice
DateTime sliceEnd = DateTimeUtils.addTimeGrain(sliceStart, timeGrain);
// Make the next slice
Interval slicedInterval = new Interval(sliceStart, sliceEnd);
// Make sure that our slice is fully contained within our interval
if (!interval.contains(slicedInterval)) {
LOG.info("Interval {} is not a multiple of TimeGrain {}", interval, timeGrain);
throw new IllegalArgumentException("Interval must be a multiple of the TimeGrain");
}
// Add the slice
intervalSlices.add(slicedInterval);
// Move the slicer forward
sliceStart = sliceEnd;
}
LOG.debug("Sliced interval {} into {} slices of {} grain", interval, intervalSlices.size(), timeGrain);
return intervalSlices;
}
示例4: IntervalPeriodIterator
import org.joda.time.Interval; //导入方法依赖的package包/类
/**
* Constructor.
*
* @param period The period to divide the interval by
* @param baseInterval The raw interval which is to be divided
*/
public IntervalPeriodIterator(@NotNull ReadablePeriod period, Interval baseInterval) {
this.period = period;
intervalStart = baseInterval.getStart();
intervalEnd = baseInterval.getEnd();
position = 0;
currentPosition = boundaryAt(0);
// Chronology accepts null periods, we must not do so or this iterator is non-terminating
if (period == null) {
throw new IllegalArgumentException("Period cannot be null");
}
}
示例5: of
import org.joda.time.Interval; //导入方法依赖的package包/类
public static Range of(Interval interval) {
return new Range(interval.getStart(), interval.getEnd());
}
示例6: setLrpPeriod
import org.joda.time.Interval; //导入方法依赖的package包/类
public Builder setLrpPeriod(@Nullable Interval lrpPeriod) {
getInstance().lrpPeriodStart = (lrpPeriod == null ? null : lrpPeriod.getStart());
getInstance().lrpPeriodEnd = (lrpPeriod == null ? null : lrpPeriod.getEnd());
return this;
}