本文整理匯總了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));
}
}