本文整理汇总了Java中java.time.LocalDateTime.compareTo方法的典型用法代码示例。如果您正苦于以下问题:Java LocalDateTime.compareTo方法的具体用法?Java LocalDateTime.compareTo怎么用?Java LocalDateTime.compareTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.LocalDateTime
的用法示例。
在下文中一共展示了LocalDateTime.compareTo方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: compareTo
import java.time.LocalDateTime; //导入方法依赖的package包/类
@Override
public final int compareTo(Entry<?> other) {
if (isFullDay() && other.isFullDay()) {
return getStartDate().compareTo(other.getStartDate());
}
if (isFullDay()) {
return -1;
}
if (other.isFullDay()) {
return +1;
}
LocalDateTime a = LocalDateTime.of(getStartDate(), getStartTime());
LocalDateTime b = LocalDateTime.of(other.getStartDate(), other.getStartTime());
int result = a.compareTo(b);
if (result == 0) {
String titleA = getTitle() != null ? getTitle() : ""; //$NON-NLS-1$
String titleB = other.getTitle() != null ? other.getTitle() : ""; //$NON-NLS-1$
result = titleA.compareTo(titleB);
}
return result;
}
示例2: splitDatesIntoMonths
import java.time.LocalDateTime; //导入方法依赖的package包/类
public static List<Date[]> splitDatesIntoMonths(Date from, Date to) throws IllegalArgumentException {
List<Date[]> dates = new ArrayList<>();
LocalDateTime dFrom = asLocalDateTime(from);
LocalDateTime dTo = asLocalDateTime(to);
if (dFrom.compareTo(dTo) >= 0) {
throw new IllegalArgumentException("Provide a to-date greater than the from-date");
}
while (dFrom.compareTo(dTo) < 0) {
// check if current time frame is last
boolean isLastTimeFrame = dFrom.getMonthValue() == dTo.getMonthValue() && dFrom.getYear() == dTo.getYear();
// define day of month based on timeframe. if last - take boundaries from end date, else end of month and date
int dayOfMonth = isLastTimeFrame ? dTo.getDayOfMonth() : dFrom.with(TemporalAdjusters.lastDayOfMonth()).getDayOfMonth();
LocalTime time = isLastTimeFrame ? dTo.toLocalTime() : LocalTime.MAX;
// build timeframe
Date[] dar = new Date[2];
dar[0] = asDate(dFrom);
dar[1] = asDate(dFrom.withDayOfMonth(dayOfMonth).toLocalDate().atTime(time));
// add current timeframe
dates.add(dar);
// jump to beginning of next month
dFrom = dFrom.plusMonths(1).withDayOfMonth(1).toLocalDate().atStartOfDay();
}
return dates;
}
示例3: determineDateRanges
import java.time.LocalDateTime; //导入方法依赖的package包/类
public void determineDateRanges() {
for(MatchableTableRow row : records.get()) {
for(MatchableTableColumn col : schema.get()) {
if(col.getType()==DataType.date) {
LocalDateTime[] range = MapUtils.get(dateRanges, col.getColumnIndex(), new LocalDateTime[2]);
Map<Integer, Integer> indexTranslation = getPropertyIndices().get(row.getTableId());
if(indexTranslation==null) {
System.err.println("Missing property index translation for table " + row.getTableId());
}
// 'secondColumnIndex' ('globalId' of dbpedia property) is used to get 'columnIndex' of dbpedia property in a respective table
Integer translatedIndex = indexTranslation.get(col.getColumnIndex());
if(translatedIndex!=null) {
Object obj = row.get(translatedIndex);
if(obj!=null && obj instanceof LocalDateTime) {
LocalDateTime value = (LocalDateTime)row.get(translatedIndex);
if(range[0]==null || value.compareTo(range[0]) < 0) {
range[0] = value;
}
if(range[1]==null || value.compareTo(range[1]) > 0) {
range[1] = value;
}
} else {
if(obj!=null && !(obj instanceof LocalDateTime)) {
System.err.println(String.format("{%s} row %d property %s has value of invalid type: '%s' (%s)", this.classIndices.get(row.getTableId()), row.getRowNumber(), col.getIdentifier(), obj, obj.getClass()));
}
}
}
}
}
}
}
示例4: RangeOfLocalDateTimes
import java.time.LocalDateTime; //导入方法依赖的package包/类
/**
* Constructor
* @param start the start for range, inclusive
* @param end the end for range, exclusive
* @param step the step increment
* @param excludes optional predicate to exclude elements in this range
*/
RangeOfLocalDateTimes(LocalDateTime start, LocalDateTime end, Duration step, Predicate<LocalDateTime> excludes) {
super(start, end);
this.step = step;
this.ascend = start.compareTo(end) <= 0;
this.excludes = excludes;
}
示例5: inBounds
import java.time.LocalDateTime; //导入方法依赖的package包/类
/**
* Checks that the value specified is in the bounds of this range
* @param value the value to check if in bounds
* @return true if in bounds
*/
private boolean inBounds(LocalDateTime value) {
return ascend ? value.compareTo(start()) >=0 && value.isBefore(end()) : value.compareTo(start()) <=0 && value.isAfter(end());
}