本文整理汇总了Java中org.joda.time.Interval.contains方法的典型用法代码示例。如果您正苦于以下问题:Java Interval.contains方法的具体用法?Java Interval.contains怎么用?Java Interval.contains使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.joda.time.Interval
的用法示例。
在下文中一共展示了Interval.contains方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getExceptionEvents
import org.joda.time.Interval; //导入方法依赖的package包/类
public static List<Interval> getExceptionEvents(List<ExceptionWorkingHours> hours, LocalDate date, RestrictionType restrictionType) {
List<Interval> exceptions = new ArrayList<>();
for (ExceptionWorkingHours ewh : hours) {
boolean isApplicable =
(restrictionType == RestrictionType.RESTRICTIVE && ewh.isOutOfService()) ||
(restrictionType == RestrictionType.NON_RESTRICTIVE && !ewh.isOutOfService());
if (isApplicable) {
DateTime start = new DateTime(ewh.getStartDate()).plusMillis(ewh.getStartDateTimezoneOffset());
DateTime end = new DateTime(ewh.getEndDate()).plusMillis(ewh.getEndDateTimezoneOffset());
Interval exception = new Interval(start, end);
Interval wholeDay = date.toInterval();
if (exception.contains(wholeDay) || exception.equals(wholeDay)) {
exceptions.clear();
exceptions.add(wholeDay);
break;
}
if (exception.overlaps(wholeDay)) {
exceptions.add(new Interval(exception.getStart(), exception.getEnd()));
}
}
}
return exceptions;
}
示例2: getMessages
import org.joda.time.Interval; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public List<Message> getMessages(DateTime start, DateTime end, Room room) {
DateTime curDate = start;
List<Message> messages = Lists.newArrayList();
WebResource roomsResource = resource.path("rooms/history");
roomsResource = roomsResource.queryParam("room_id", room.getRoomId())
.queryParam("timezone", timeZoneStr);
Interval messageInterval = new Interval(start, end);
while (curDate.isBefore(end) || curDate.equals(end)) {
roomsResource = roomsResource.queryParam("date", curDate.toString(apiDateFormat));
String jsonStr = getJsonResultWithRetries(roomsResource, apiRetries);
Collection<Message> messageCol = deserializeJsonStr(jsonStr, "messages", Message.class,
objMapper);
for (Message message : messageCol) {
if (messageInterval.contains(message.getDate())) {
messages.add(message);
}
}
curDate = curDate.plusDays(1);
}
return messages;
}
示例3: contains
import org.joda.time.Interval; //导入方法依赖的package包/类
public static boolean contains(List<Interval> intervals, DateTime query) {
try {
for (Interval in : intervals) {
if (in.contains(query)) {
return true;
}
}
return false;
} catch (Exception e) {
log.warn("Failed to check whether {} is contained within {}", query, intervals);
return false;
}
}
示例4: overlaps
import org.joda.time.Interval; //导入方法依赖的package包/类
@Override
public boolean overlaps(int stayTime, RouteLegList legs,
SharingStation startStation, RouteLegWrapper bikeWrapper) {
// We always set stay time. Depending on DurationCheckStrategy it will be used or not.
bikeWrapper.setStayTime(stayTime);
// -------------------------------------------------------------------------
// 1) If in future, be optimistic and assume always available
// -------------------------------------------------------------------------
Interval nowTimeWindow = DateTimeUtils.getNowTimeWindow();
DateTime timeAtStartStation = legs.getAfterLastLeg();
boolean startIsNow = nowTimeWindow.contains(timeAtStartStation);
if (!startIsNow) {
return false;
}
// -------------------------------------------------------------------------
// 2) Check actual intervals for availability
// -------------------------------------------------------------------------
int duration = durationCheckStrategy.getDurationToCheck(bikeWrapper);
Interval interval = legs.getIntervalAfterPossibleLeg(duration);
return overlaps(startStation, interval);
}
开发者ID:RWTH-i5-IDSG,项目名称:xsharing-services-router,代码行数:30,代码来源:DefaultBikeInavailabilityStrategy.java
示例5: listWorkflows
import org.joda.time.Interval; //导入方法依赖的package包/类
@Override
public List<OnlineWorkflowDetails> listWorkflows(Interval basecaseInterval) {
LOGGER.info("Getting list of stored workflows run on basecases within the interval {}", basecaseInterval);
String dateFormatPattern = "yyyyMMdd_HHmm";
DateTimeFormatter formatter = DateTimeFormat.forPattern(dateFormatPattern);
List<OnlineWorkflowDetails> workflowIds = new ArrayList<OnlineWorkflowDetails>();
File[] files = config.getOnlineDbDir().toFile().listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.toLowerCase().startsWith(STORED_WORKFLOW_PREFIX);
}
});
for (File file : files) {
if (file.isFile()) {
String workflowId = file.getName().substring(STORED_WORKFLOW_PREFIX.length());
if (workflowId.length() > dateFormatPattern.length() && workflowId.substring(dateFormatPattern.length(), dateFormatPattern.length() + 1).equals("_")) {
String basecaseName = workflowId.substring(0, dateFormatPattern.length() - 1);
DateTime basecaseDate = DateTime.parse(basecaseName, formatter);
if (basecaseInterval.contains(basecaseDate.getMillis())) {
OnlineWorkflowDetails workflowDetails = new OnlineWorkflowDetails(workflowId);
workflowDetails.setWorkflowDate(getWorkflowDate(workflowId));
workflowIds.add(workflowDetails);
}
}
}
}
Collections.sort(workflowIds, new Comparator<OnlineWorkflowDetails>() {
@Override
public int compare(OnlineWorkflowDetails wfDetails1, OnlineWorkflowDetails wfDetails2) {
return wfDetails1.getWorkflowDate().compareTo(wfDetails2.getWorkflowDate());
}
});
LOGGER.info("Found {} workflow(s)", workflowIds.size());
return workflowIds;
}
示例6: startScheduledScan
import org.joda.time.Interval; //导入方法依赖的package包/类
/**
* Starts a scheduled scan and upload which had been scheduled to start at the given time. This method will
* throw an exception if the current time isn't reasonably close to the scheduled time or if the scan for
* the scheduled time has already started.
*/
@VisibleForTesting
synchronized ScanStatus startScheduledScan(ScheduledDailyScanUpload scheduledScan, DateTime scheduledTime)
throws RepeatScanException, ScanExecutionTimeException {
// Verify that the scan either doesn't require requests or has at least one request
if (scheduledScan.isRequestRequired() && _stashRequestManager.getRequestsForStash(scheduledScan.getId(), scheduledTime).isEmpty()) {
_log.info("Scan {} did not receive any requests and will not be executed for {}",
scheduledScan.getId(), DateTimeFormat.mediumDateTime().print(scheduledTime));
return null;
}
// Name the scan ID and directory for when the scan was scheduled
String scanId = scheduledScan.getScanIdFormat().print(scheduledTime);
String directory = scheduledScan.getDirectoryFormat().print(scheduledTime);
ScanDestination destination = scheduledScan.getRootDestination().getDestinationWithSubpath(directory);
// Verify this scan hasn't already been started
if (_scanUploader.getStatus(scanId) != null) {
throw new RepeatScanException("Scan has already been started: " + scanId);
}
// Allow the scan to start up to 30 seconds early or 10 minutes late
DateTime now = now();
Interval acceptableInterval = new Interval(scheduledTime.minusSeconds(30), scheduledTime.plusMinutes(10));
if (!acceptableInterval.contains(now)) {
throw new ScanExecutionTimeException(format(
"Scheduled scan to %s is not running at the expected time: expected = %s, actual = %s",
destination, scheduledTime, now));
}
ScanOptions scanOptions = new ScanOptions(scheduledScan.getPlacements())
.addDestination(destination)
.setMaxConcurrentSubRangeScans(scheduledScan.getMaxRangeConcurrency())
.setScanByAZ(scheduledScan.isScanByAZ());
_log.info("Starting scheduled scan and upload to {} for time {}", destination, scheduledTime);
return _scanUploader.scanAndUpload(scanId, scanOptions);
}
示例7: canDetermineAvailability
import org.joda.time.Interval; //导入方法依赖的package包/类
/**
* Check to see if we can determine availability from the given available and needed intervals.
*
* @param available Available interval
* @param needed Needed interval
*
* @return True if we can determine availability, false if not
*/
private static boolean canDetermineAvailability(Interval available, Interval needed) {
if (available != null && needed != null) {
if (available.contains(needed) || available.getStart().isAfter(needed.getStart())) {
return true;
}
}
return false;
}
示例8: 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;
}
示例9: overlaps
import org.joda.time.Interval; //导入方法依赖的package包/类
/**
* start | end | overlaps?
* ---------+--------+--------------------------------------------------
* now | now | check inavailability at both stations
* now | future | check inavailability at start station, be optimistic about end station
* future | now | false. cannot happen, chronologically not possible
* future | future | false. both in future => be optimistic, no check
*/
@Override
public boolean overlaps(int stayTime, RouteLegList legs,
SharingStation startStation, RouteLegWrapper bikeWrapper,
SharingStation endStation, RouteLegWrapper walkWrapper) {
// We always set stay time. Depending on DurationCheckStrategy it will be used or not.
walkWrapper.setStayTime(stayTime);
// -------------------------------------------------------------------------
// 1) If in future, be optimistic and assume always available
// -------------------------------------------------------------------------
Interval nowTimeWindow = getNowTimeWindow();
DateTime timeAtStartStation = legs.getAfterLastLeg();
boolean startIsNow = nowTimeWindow.contains(timeAtStartStation);
if (!startIsNow) {
return false;
}
// -------------------------------------------------------------------------
// 2) Check actual intervals for availability
// -------------------------------------------------------------------------
int bikeLegDuration = bikeWrapper.getLeg().getDuration();
int durationAfterStartStation = bikeLegDuration + durationCheckStrategy.getDurationToCheck(walkWrapper);
DateTime timeAtReturnStation = timeAtStartStation.plusSeconds(durationAfterStartStation);
boolean endIsNow = nowTimeWindow.contains(timeAtReturnStation);
if (endIsNow) {
// Check bike availability for "HinFahrt" at start station and "RückFahrt" at end station
return overlapsAtStation(legs, startStation, bikeLegDuration)
|| overlapsAtStation(legs, endStation, durationAfterStartStation);
} else {
// Check bike availability for "HinFahrt" at start station
return overlapsAtStation(legs, startStation, bikeLegDuration);
}
}
开发者ID:RWTH-i5-IDSG,项目名称:xsharing-services-router,代码行数:49,代码来源:WithReturnBikeInavailabilityStrategy.java
示例10: findFullAvailabilityGaps
import org.joda.time.Interval; //导入方法依赖的package包/类
/**
* Finds the gaps in available vs needed interval sets.
*
* @param availableIntervals availability intervals
* @param neededIntervals needed intervals
*
* @return set of intervals that are needed, but not fully available.
*/
public static SortedSet<Interval> findFullAvailabilityGaps(
Set<Interval> availableIntervals,
Set<Interval> neededIntervals
) {
// Use just one comparator
Comparator<Interval> intervalStartComparator = new IntervalStartComparator();
// Sort the intervals by start time, earliest to latest so we iterate over them in order
SortedSet<Interval> sortedAvailableIntervals = new TreeSet<>(intervalStartComparator);
sortedAvailableIntervals.addAll(availableIntervals);
SortedSet<Interval> sortedNeededIntervals = new TreeSet<>(intervalStartComparator);
sortedNeededIntervals.addAll(neededIntervals);
// TODO: Consolidate available intervals to remove false misses
// Get the 1st available interval
Iterator<Interval> availableIntervalsIterator = sortedAvailableIntervals.iterator();
if (!availableIntervalsIterator.hasNext()) {
// We have no available intervals so all needed intervals are missing
return sortedNeededIntervals;
}
Interval available = availableIntervalsIterator.next();
// Walk through the needed intervals, adding missing ones
SortedSet<Interval> missingIntervals = new TreeSet<>(intervalStartComparator);
for (Interval needed : sortedNeededIntervals) {
// Get the next available interval that can determine availability of the needed interval
while (!canDetermineAvailability(available, needed) && availableIntervalsIterator.hasNext()) {
available = availableIntervalsIterator.next();
}
// If current available interval contains the needed interval, it's not missing. Next!
if (available.contains(needed)) {
continue;
}
// Either the needed interval starts before the available interval, or we have no other available intervals.
missingIntervals.add(needed);
}
return missingIntervals;
}