java.time.LocalDateTime.compareTo()方法的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(264)

本文整理了Java中java.time.LocalDateTime.compareTo()方法的一些代码示例,展示了LocalDateTime.compareTo()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LocalDateTime.compareTo()方法的具体详情如下:
包路径:java.time.LocalDateTime
类名称:LocalDateTime
方法名:compareTo

LocalDateTime.compareTo介绍

[英]Compares this date-time to another date-time.

The comparison is primarily based on the date-time, from earliest to latest. It is "consistent with equals", as defined by Comparable.

If all the date-times being compared are instances of LocalDateTime, then the comparison will be entirely based on the date-time. If some dates being compared are in different chronologies, then the chronology is also considered, see ChronoLocalDateTime#compareTo.
[中]将此日期时间与另一个日期时间进行比较。
比较主要基于日期时间,从最早到最晚。它是“与相等一致的”,如Comparable所定义。
如果所有被比较的日期时间都是LocalDateTime的实例,那么比较将完全基于日期时间。如果正在比较的某些日期采用不同的年表,则也会考虑该年表,请参见ChronoLocalDateTime#compareTo。

代码示例

代码示例来源:origin: apache/hive

@Override
public int compareTo(Timestamp o) {
 return localDateTime.compareTo(o.localDateTime);
}

代码示例来源:origin: kiegroup/optaplanner

public boolean overlapsTime(Timeslot other) {
  if (this == other) {
    return true;
  }
  return startDateTime.compareTo(other.endDateTime) < 0
      && other.startDateTime.compareTo(endDateTime) < 0;
}

代码示例来源:origin: jtablesaw/tablesaw

@Override
public int compare(LocalDateTime o1, LocalDateTime o2) {
  return o1.compareTo(o2);
}

代码示例来源:origin: kiegroup/optaplanner

public boolean overlaps(Flight other) {
  return departureUTCDateTime.compareTo(other.arrivalUTCDateTime) < 0
    && other.departureUTCDateTime.compareTo(arrivalUTCDateTime) < 0;
}

代码示例来源:origin: kiegroup/optaplanner

public boolean startsAfter(Timeslot other) {
  return other.endDateTime.compareTo(startDateTime) <= 0;
}

代码示例来源:origin: kiegroup/optaplanner

public boolean endsBefore(Timeslot other) {
  return endDateTime.compareTo(other.startDateTime) <= 0;
}

代码示例来源:origin: kiegroup/optaplanner

public int getOverlapInMinutes(Timeslot other) {
  if (this == other) {
    return durationInMinutes;
  }
  LocalDateTime startMaximum = (startDateTime.compareTo(other.startDateTime) < 0) ? other.startDateTime : startDateTime;
  LocalDateTime endMinimum = (endDateTime.compareTo(other.endDateTime) < 0) ? endDateTime : other.endDateTime;
  return (int) Duration.between(startMaximum, endMinimum).toMinutes();
}

代码示例来源:origin: kiegroup/optaplanner

private void writeRoomTalks(List<Timeslot> dayTimeslotList, Room room, List<Talk> roomTalkList) {
  Timeslot mergePreviousTimeslot = null;
  int mergeStart = -1;
  for (Timeslot timeslot : dayTimeslotList) {
    List<Talk> talkList = roomTalkList.stream()
        .filter(talk -> talk.getTimeslot() == timeslot).collect(toList());
    if (talkList.isEmpty() && mergePreviousTimeslot != null
        && timeslot.getStartDateTime().compareTo(mergePreviousTimeslot.getEndDateTime()) < 0) {
      nextCellVertically();
    } else {
      if (mergePreviousTimeslot != null && mergeStart < currentRowNumber) {
        currentSheet.addMergedRegion(new CellRangeAddress(mergeStart, currentRowNumber, currentColumnNumber, currentColumnNumber));
      }
      boolean unavailable = room.getUnavailableTimeslotSet().contains(timeslot)
          || Collections.disjoint(room.getTalkTypeSet(), timeslot.getTalkTypeSet());
      nextTalkListCell(unavailable, talkList, talk -> StringUtils.abbreviate(talk.getTitle(), 50) + "\n"
          + StringUtils.abbreviate(talk.getSpeakerList().stream().map(Speaker::getName).collect(joining(", ")), 30), true);
      mergePreviousTimeslot = talkList.isEmpty() ? null : timeslot;
      mergeStart = currentRowNumber;
    }
  }
  if (mergePreviousTimeslot != null && mergeStart < currentRowNumber) {
    currentSheet.addMergedRegion(new CellRangeAddress(mergeStart, currentRowNumber, currentColumnNumber, currentColumnNumber));
  }
}

代码示例来源:origin: kiegroup/optaplanner

.filter(talk -> talk.getTimeslot() == timeslot).collect(toList());
if (talkList.isEmpty() && mergePreviousTimeslot != null
    && timeslot.getStartDateTime().compareTo(mergePreviousTimeslot.getEndDateTime()) < 0) {
  nextCell();
} else {

代码示例来源:origin: kiegroup/optaplanner

.filter(talk -> talk.getTimeslot() == timeslot).collect(toList());
if (talkList.isEmpty() && mergePreviousTimeslot != null
    && timeslot.getStartDateTime().compareTo(mergePreviousTimeslot.getEndDateTime()) < 0) {
  nextCell();
} else {

代码示例来源:origin: pholser/junit-quickcheck

/**
 * <p>Tells this generator to produce values within a specified
 * {@linkplain InRange#min() minimum} and/or {@linkplain InRange#max()
 * maximum}, inclusive, with uniform distribution, down to the
 * nanosecond.</p>
 *
 * <p>If an endpoint of the range is not specified, the generator will use
 * dates with values of either {@link LocalDateTime#MIN} or
 * {@link LocalDateTime#MAX} as appropriate.</p>
 *
 * <p>{@link InRange#format()} describes
 * {@linkplain DateTimeFormatter#ofPattern(String) how the generator is to
 * interpret the range's endpoints}.</p>
 *
 * @param range annotation that gives the range's constraints
 */
public void configure(InRange range) {
  DateTimeFormatter formatter = DateTimeFormatter.ofPattern(range.format());
  if (!defaultValueOf(InRange.class, "min").equals(range.min()))
    min = LocalDateTime.parse(range.min(), formatter);
  if (!defaultValueOf(InRange.class, "max").equals(range.max()))
    max = LocalDateTime.parse(range.max(), formatter);
  if (min.compareTo(max) > 0)
    throw new IllegalArgumentException(String.format("bad range, %s > %s", range.min(), range.max()));
}

代码示例来源:origin: com.sqlapp/sqlapp-core

@Override
public boolean hasNext() {
  if (this.step>0){
    return (next.compareTo(end)<0);
  } else{
    return (next.compareTo(end)>0);
  }
}

代码示例来源:origin: com.sqlapp/sqlapp-core

@Override
public boolean hasNext() {
  if (this.step.isPositive()){
    return (next.compareTo(end)<0);
  } else{
    return (next.compareTo(end)>0);
  }
}

代码示例来源:origin: org.optaplanner/optaplanner-examples

public int getOverlapInMinutes(Timeslot other) {
  if (this == other) {
    return durationInMinutes;
  }
  LocalDateTime startMaximum = (startDateTime.compareTo(other.startDateTime) < 0) ? other.startDateTime : startDateTime;
  LocalDateTime endMinimum = (endDateTime.compareTo(other.endDateTime) < 0) ? endDateTime : other.endDateTime;
  return (int) Duration.between(startMaximum, endMinimum).toMinutes();
}

代码示例来源:origin: IanDarwin/javasrc

/** Process the list yet another way - working version (comment out call to version3!) */
public static void version3b() {
  listOfReadings.stream().filter(
      r -> r.type == ReadingType.BG && (r.value1 < 2.8 || r.value1 > 15))
      .sorted((r1, r2) -> r1.when.compareTo(r2.when))
      .forEach(o->System.out.println(o));
}

代码示例来源:origin: kawasima/enkan

@SuppressWarnings("NullableProblems")
  @Override
  public int compareTo(LogKey another) {
    return this.dateTime.compareTo(another.getDateTime());
  }
}

代码示例来源:origin: stackoverflow.com

LocalDateTime currentDateTime = LocalDateTime.now();
LocalDate currentDate = LocalDate.now();
String cutOff = "05:00 AM";
DateTimeFormatter timeParser = DateTimeFormatter.ofPattern("hh:mm a");
LocalTime cutOffTime = timeParser.parse(cutOff, LocalTime::from);
LocalDateTime cutOffDateTime = LocalDateTime.of(currentDate, cutOffTime);
//After
cutOffDateTime.isAfter(currentDateTime);
//Before
cutOffDateTime.isBefore(currentDateTime);
//Compare
cutOffDateTime.compareTo(currentDateTime);

代码示例来源:origin: org.opennms.core.snmp/org.opennms.core.snmp.implementations.snmp4j

@Override
  public int compare(final SessionInfo o1, final SessionInfo o2) {
    return o1.getStart().compareTo(o2.getStart());
  }
}).limit(s_trackSummaryLimit).forEach((si) -> {

代码示例来源:origin: OpenNMS/opennms

@Override
  public int compare(final SessionInfo o1, final SessionInfo o2) {
    return o1.getStart().compareTo(o2.getStart());
  }
}).limit(s_trackSummaryLimit).forEach((si) -> {

代码示例来源:origin: zavtech/morpheus-core

/**
   * 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());
  }
}

相关文章

LocalDateTime类方法