本文整理汇总了Java中org.joda.time.Interval类的典型用法代码示例。如果您正苦于以下问题:Java Interval类的具体用法?Java Interval怎么用?Java Interval使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Interval类属于org.joda.time包,在下文中一共展示了Interval类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: formatDuration
import org.joda.time.Interval; //导入依赖的package包/类
public static String formatDuration(long duration)
{
// Using Joda Time
DateTime now = new DateTime(); // Now
DateTime plus = now.plus(new Duration(duration * 1000));
// Define and calculate the interval of time
Interval interval = new Interval(now.getMillis(), plus.getMillis());
Period period = interval.toPeriod(PeriodType.time());
// Define the period formatter for pretty printing
String ampersand = " & ";
PeriodFormatter pf = new PeriodFormatterBuilder().appendHours().appendSuffix(ds("hour"), ds("hours"))
.appendSeparator(" ", ampersand).appendMinutes().appendSuffix(ds("minute"), ds("minutes"))
.appendSeparator(ampersand).appendSeconds().appendSuffix(ds("second"), ds("seconds")).toFormatter();
return pf.print(period).trim();
}
示例2: rowToInavail
import org.joda.time.Interval; //导入依赖的package包/类
@Nullable
private MBPlaceInavailability rowToInavail(Object[] row) {
try {
Interval interval = getInterval(BasicUtils.getTypeSafeString(row[3]),
BasicUtils.getTypeSafeString(row[4]));
MBPlaceInavailability in = new MBPlaceInavailability();
in.setProviderId(BasicUtils.getTypeSafeString(row[0]));
in.setPlaceId(BasicUtils.getTypeSafeString(row[1]));
in.setBookingTargetId(BasicUtils.getTypeSafeString(row[2]));
in.setInavailability(interval);
return in;
} catch (Exception e) {
return null;
}
}
示例3: overlaps
import org.joda.time.Interval; //导入依赖的package包/类
protected static boolean overlaps(SharingStation station, Interval interval) {
List<VehicleStatus> vehicleStatusList = station.getVehicleStatusList();
for (VehicleStatus vs : vehicleStatusList) {
List<Interval> inavailabilities = vs.getInavailabilities();
if (!contains(inavailabilities, interval)) {
// as long as there is a vehicle with non-overlapping inavailabilities,
// the station can be used during the routing.
return false;
}
}
// ok, there are two possible reasons for this outcome
// 1) there is no vehicle at the station
// 2) we have gone through all the vehicles and there is no available one (all inavailabilities overlap)
return true;
}
示例4: gatherSuitableSlots
import org.joda.time.Interval; //导入依赖的package包/类
protected Collection<Interval> gatherSuitableSlots(ExamRoom room, LocalDate date, Integer examDuration) {
Collection<Interval> examSlots = new ArrayList<>();
// Resolve the opening hours for room and day
List<ExamRoom.OpeningHours> openingHours = room.getWorkingHoursForDate(date);
if (!openingHours.isEmpty()) {
// Get suitable slots based on exam duration
for (Interval slot : allSlots(openingHours, room, date)) {
DateTime beginning = slot.getStart();
DateTime openUntil = getEndOfOpeningHours(beginning, openingHours);
if (!beginning.plusMinutes(examDuration).isAfter(openUntil)) {
DateTime end = beginning.plusMinutes(examDuration);
examSlots.add(new Interval(beginning, end));
}
}
}
return examSlots;
}
示例5: getExamSlots
import org.joda.time.Interval; //导入依赖的package包/类
/**
* Queries for slots for given room and day
*/
private Set<TimeSlot> getExamSlots(User user, ExamRoom room, Exam exam, LocalDate date,
Collection<Reservation> reservations, Collection<ExamMachine> machines) {
Integer examDuration = exam.getDuration();
Collection<Interval> examSlots = gatherSuitableSlots(room, date, examDuration);
Map<Interval, Optional<Integer>> map = examSlots.stream().collect(
Collectors.toMap(
Function.identity(),
es -> Optional.empty(),
(u, v) -> {
throw new IllegalStateException(String.format("Duplicate key %s", u));
},
LinkedHashMap::new));
// Check reservation status and machine availability for each slot
return handleReservations(map, reservations, exam, machines, user);
}
示例6: getExamSlots
import org.joda.time.Interval; //导入依赖的package包/类
private Set<TimeSlot> getExamSlots(ExamRoom room, Integer examDuration, LocalDate date, Collection<ExamMachine> machines) {
Set<TimeSlot> slots = new LinkedHashSet<>();
Collection<Interval> examSlots = gatherSuitableSlots(room, date, examDuration);
// Check machine availability for each slot
for (Interval slot : examSlots) {
// Check machine availability
int availableMachineCount = machines.stream()
.filter(m -> !isReservedDuring(m, slot))
.collect(Collectors.toList())
.size();
slots.add(new TimeSlot(slot, availableMachineCount, null));
}
return slots;
}
示例7: getExistingIntervalGaps
import org.joda.time.Interval; //导入依赖的package包/类
private static List<Interval> getExistingIntervalGaps(List<Interval> reserved) {
List<Interval> gaps = new ArrayList<>();
Interval current = reserved.get(0);
for (int i = 1; i < reserved.size(); i++) {
Interval next = reserved.get(i);
Interval gap = current.gap(next);
if (gap != null) {
gaps.add(gap);
}
current = next;
}
return gaps;
}
示例8: 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;
}
示例9: 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;
}
示例10: filterTripByDate
import org.joda.time.Interval; //导入依赖的package包/类
public void filterTripByDate(Interval dateRange) {
dateFilter = dateRange;
if (selectedTrips == null) return;
selectedTrips.clear();
if (allTrips == null) return;;
if (dateRange != null) {
for (Trip t : allTrips) {
DateTime begDate = DateTime.parse(t.getStartDate());
DateTime endDate = DateTime.parse(t.getEndDate());
if (dateRange.isAfter(endDate)) continue;
if (dateRange.isBefore(begDate)) continue;
selectedTrips.add(t);
}
} else
selectedTrips.addAll(allTrips);
adapter.reloadFrom(selectedTrips);
}
示例11: groupIntervalByColumn
import org.joda.time.Interval; //导入依赖的package包/类
/**
* Group interval in segment metadata by column.
*
* @param metadata Metadata containing the druid segments information
*
* @return map of data time to a map of segment id to segment info
*/
protected static Map<String, SimplifiedIntervalList> groupIntervalByColumn(DataSourceMetadata metadata) {
Map<String, Set<Interval>> currentByColumn = new LinkedHashMap<>();
// Accumulate all intervals by column name
for (DataSegment segment : metadata.getSegments()) {
SegmentInfo segmentInfo = new SegmentInfo(segment);
for (String column : segmentInfo.getColumnNames()) {
currentByColumn.computeIfAbsent(column, ignored -> new HashSet<>()).add(segmentInfo.getInterval());
}
}
// Simplify interval sets using SimplifiedIntervalList
return currentByColumn.entrySet().stream()
.collect(
Collectors.toMap(
Map.Entry::getKey,
entry -> new SimplifiedIntervalList(entry.getValue())
)
);
}
示例12: QueryPlanningConstraint
import org.joda.time.Interval; //导入依赖的package包/类
/**
* Constructor.
*
* @param requestDimensions Dimensions contained in request
* @param filterDimensions Filtered dimensions
* @param metricDimensions Metric related dimensions
* @param metricNames Names of metrics
* @param apiFilters Map of dimension to its set of API filters
* @param logicalTable The logical table requested by the request
* @param intervals The interval constraint of the request
* @param logicalMetrics The logical metrics requested by the request
* @param minimumGranularity The finest granularity that must be satisfied by table granularity
* @param requestGranularity The requested granularity of on the requested table
*/
public QueryPlanningConstraint(
Set<Dimension> requestDimensions,
Set<Dimension> filterDimensions,
Set<Dimension> metricDimensions,
Set<String> metricNames,
ApiFilters apiFilters,
LogicalTable logicalTable,
Set<Interval> intervals,
Set<LogicalMetric> logicalMetrics,
Granularity minimumGranularity,
Granularity requestGranularity
) {
super(requestDimensions, filterDimensions, metricDimensions, metricNames, apiFilters);
this.logicalTable = logicalTable;
this.intervals = intervals;
this.logicalMetrics = logicalMetrics;
this.minimumGranularity = minimumGranularity;
this.requestGranularity = requestGranularity;
this.logicalMetricNames = generateLogicalMetricNames();
}
示例13: collectBucketedIntervalsIntersectingIntervalList
import org.joda.time.Interval; //导入依赖的package包/类
/**
* Collect all subintervals of an interval list of a grain bucketed size which are subintervals of another supply
* list of intervals.
*
* @param supplyIntervals The interval collection to match bucketedIntervals against
* @param bucketedIntervals The grain bucketed intervals to collect if they overlap the supply
* @param granularity Grain at which to split the bucketingIntervals
*
* @return a simplified list of subintervals of the bucketedIntervals list
*/
public static SimplifiedIntervalList collectBucketedIntervalsIntersectingIntervalList(
SimplifiedIntervalList supplyIntervals,
SimplifiedIntervalList bucketedIntervals,
Granularity granularity
) {
// Stream the from intervals, split by grain
Iterable<Interval> bucketedIterable = granularity.intervalsIterable(bucketedIntervals);
// Predicate to find buckets which overlap
Predicate<Interval> isIntersecting =
new SimplifiedIntervalList.SkippingIntervalPredicate(
supplyIntervals,
AbstractInterval::overlaps,
false
);
return StreamSupport.stream(bucketedIterable.spliterator(), false)
.filter(isIntersecting)
.collect(SimplifiedIntervalList.getCollector());
}
示例14: findHarvestsLinkedToHuntingDayAndPermitOfRhy
import org.joda.time.Interval; //导入依赖的package包/类
@Override
@Transactional(readOnly = true)
public List<Harvest> findHarvestsLinkedToHuntingDayAndPermitOfRhy(final Riistanhoitoyhdistys rhy,
final GameSpecies species,
final Interval interval) {
final QHarvest harvest = QHarvest.harvest;
final QGroupHuntingDay huntingDay = QGroupHuntingDay.groupHuntingDay;
final QHuntingClubGroup group = QHuntingClubGroup.huntingClubGroup;
final QHarvestPermit permit = QHarvestPermit.harvestPermit;
return new JPAQuery<>(entityManager)
.from(harvest)
.join(harvest.huntingDayOfGroup, huntingDay)
.join(huntingDay.group, group)
.join(group.harvestPermit, permit)
.select(harvest)
.where(permit.rhy.eq(rhy)
.and(harvest.species.eq(species))
.and(harvest.pointOfTime.between(
new Timestamp(interval.getStart().getMillis()),
new Timestamp(interval.getEnd().getMillis()))))
.fetch();
}
示例15: getActiveUsersByMethod
import org.joda.time.Interval; //导入依赖的package包/类
@Override
public Map<String, Double> getActiveUsersByMethod(Interval interval,
ActiveMethod method,
int resultSize,
boolean withBots) {
if (method == ActiveMethod.ToTV) {
return occurrenceStatsDAO.getActiveColumnsByToTV("username", interval, resultSize,
withBots);
} else if (method == ActiveMethod.ToMV) {
return occurrenceStatsDAO.getActiveColumnsByToMV("username", interval, resultSize,
withBots);
} else {
throw new UnsupportedOperationException(String.format("Method %s not supported",
method));
}
}