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

x33g5p2x  于2022-01-20 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(223)

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

Instant.compareTo介绍

[英]Compares this instant to the specified instant.

The comparison is based on the time-line position of the instants. It is "consistent with equals", as defined by Comparable.
[中]将此瞬间与指定瞬间进行比较。
比较是基于瞬间的时间线位置。它是“与相等一致的”,如Comparable所定义。

代码示例

代码示例来源:origin: codecentric/spring-boot-admin

private Instant getMax(Instant t1, Instant t2) {
  return t1.compareTo(t2) >= 0 ? t1 : t2;
}

代码示例来源:origin: embulk/embulk

@Override
public int compareTo(final Timestamp other) {
  return this.instant.compareTo(other.instant);
}

代码示例来源:origin: spring-projects/spring-framework

public boolean accept(E entity) {
    return (createdBy == null || createdBy.equals(entity.createdBy)) &&
        (createdBefore == null || createdBefore.compareTo(entity.createdDate) >= 0) &&
        (createdAfter == null || createdAfter.compareTo(entity.createdDate) >= 0);
  }
}

代码示例来源:origin: hibernate/hibernate-orm

public int compare(ZonedDateTime one, ZonedDateTime another) {
    return one.toInstant().compareTo( another.toInstant() );
  }
}

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

@Override
public int compareTo(TimestampTZ o) {
 return zonedDateTime.toInstant().compareTo(o.zonedDateTime.toInstant());
}

代码示例来源:origin: GoogleContainerTools/jib

@Override
public int compareTo(LayerEntryTemplate otherLayerEntryTemplate) {
 int sourceFileComparison = sourceFile.compareTo(otherLayerEntryTemplate.sourceFile);
 if (sourceFileComparison != 0) {
  return sourceFileComparison;
 }
 int extractionPathComparison =
   extractionPath.compareTo(otherLayerEntryTemplate.extractionPath);
 if (extractionPathComparison != 0) {
  return extractionPathComparison;
 }
 int lastModifiedTimeComparison =
   lastModifiedTime.compareTo(otherLayerEntryTemplate.lastModifiedTime);
 if (lastModifiedTimeComparison != 0) {
  return lastModifiedTimeComparison;
 }
 return permissions.compareTo(otherLayerEntryTemplate.permissions);
}

代码示例来源:origin: runelite/runelite

private boolean check6hrLogout()
{
  if (sixHourWarningTime == null)
  {
    return false;
  }
  if (Instant.now().compareTo(sixHourWarningTime) >= 0)
  {
    if (notify6HourLogout)
    {
      notify6HourLogout = false;
      return true;
    }
  }
  else
  {
    notify6HourLogout = true;
  }
  return false;
}

代码示例来源:origin: oracle/opengrok

@Override
public int compareTo(final AcceptedMessage o) {
  int cmpRes = acceptedTime.compareTo(o.acceptedTime);
  if (cmpRes == 0) {
    return message.compareTo(o.message);
  }
  return cmpRes;
}

代码示例来源:origin: AxonFramework/AxonFramework

@Override
public int compareTo(ScheduledDeadlineInfo other) {
  if (scheduleTime.equals(other.scheduleTime)) {
    return Integer.compare(counter, other.counter);
  }
  return scheduleTime.compareTo(other.scheduleTime);
}

代码示例来源:origin: AxonFramework/AxonFramework

@Override
public int compareTo(StubScheduleToken other) {
  if (scheduleTime.equals(other.scheduleTime)) {
    return (counter < other.counter) ? -1 : ((counter == other.counter) ? 0 : 1);
  }
  return scheduleTime.compareTo(other.scheduleTime);
}

代码示例来源:origin: thinkaurelius/titan

@Test
public void testTimeSequence() throws Exception {
  Random r = new Random();
  Instant[] times = new Instant[10];
  for (int i = 0; i < times.length; i++) {
    times[i] = TimestampProviders.NANO.getTime();
    if (i > 0) assertTrue(times[i] + " > " + times[i - 1], times[i].compareTo(times[i - 1])>0);
    Thread.sleep(r.nextInt(50) + 2);
  }
}

代码示例来源:origin: thinkaurelius/titan

private Duration timeSinceFirstMsg() {
  Duration sinceFirst =  Duration.ZERO;
  if (!toSend.isEmpty()) {
    Instant firstTimestamp = toSend.get(0).message.getMessage().getTimestamp();
    Instant nowTimestamp   = times.getTime();
    if (firstTimestamp.compareTo(nowTimestamp) < 0) {
      sinceFirst = Duration.between(firstTimestamp, nowTimestamp);
    }
  }
  return sinceFirst;
}

代码示例来源:origin: runelite/runelite

private boolean checkAnimationIdle(Duration waitDuration, Player local)
{
  if (lastAnimation == IDLE)
  {
    return false;
  }
  final int animation = local.getAnimation();
  if (animation == IDLE)
  {
    if (lastAnimating != null && Instant.now().compareTo(lastAnimating.plus(waitDuration)) >= 0)
    {
      lastAnimation = IDLE;
      lastAnimating = null;
      return true;
    }
  }
  else
  {
    lastAnimating = Instant.now();
  }
  return false;
}

代码示例来源:origin: JanusGraph/janusgraph

@Test
public void testTimeSequence() throws Exception {
  Random r = new Random();
  Instant[] times = new Instant[10];
  for (int i = 0; i < times.length; i++) {
    times[i] = TimestampProviders.NANO.getTime();
    if (i > 0) assertTrue(times[i] + " > " + times[i - 1], times[i].compareTo(times[i - 1])>0);
    Thread.sleep(r.nextInt(50) + 2);
  }
}

代码示例来源:origin: JanusGraph/janusgraph

private Duration timeSinceFirstMsg() {
  Duration sinceFirst =  Duration.ZERO;
  if (!toSend.isEmpty()) {
    Instant firstTimestamp = toSend.get(0).message.getMessage().getTimestamp();
    Instant nowTimestamp   = times.getTime();
    if (firstTimestamp.compareTo(nowTimestamp) < 0) {
      sinceFirst = Duration.between(firstTimestamp, nowTimestamp);
    }
  }
  return sinceFirst;
}

代码示例来源:origin: thinkaurelius/titan

@Override
public void forceCloseInstance(String instanceId) {
  Preconditions.checkArgument(!graph.getConfiguration().getUniqueGraphId().equals(instanceId),
      "Cannot force close this current instance [%s]. Properly shut down the graph instead.", instanceId);
  Preconditions.checkArgument(modifyConfig.has(REGISTRATION_TIME, instanceId), "Instance [%s] is not currently open", instanceId);
  Instant registrationTime = modifyConfig.get(REGISTRATION_TIME, instanceId);
  Preconditions.checkArgument(registrationTime.compareTo(txStartTime) < 0, "The to-be-closed instance [%s] was started after this transaction" +
      "which indicates a successful restart and can hence not be closed: %s vs %s", instanceId, registrationTime, txStartTime);
  modifyConfig.remove(REGISTRATION_TIME, instanceId);
}

代码示例来源:origin: spring-projects/spring-session

boolean isExpired(Instant now) {
  if (this.maxInactiveInterval.isNegative()) {
    return false;
  }
  return now.minus(this.maxInactiveInterval).compareTo(this.lastAccessedTime) >= 0;
}

代码示例来源:origin: JanusGraph/janusgraph

@Override
public void forceCloseInstance(String instanceId) {
  Preconditions.checkArgument(!graph.getConfiguration().getUniqueGraphId().equals(instanceId),
      "Cannot force close this current instance [%s]. Properly shut down the graph instead.", instanceId);
  Preconditions.checkArgument(modifyConfig.has(REGISTRATION_TIME, instanceId), "Instance [%s] is not currently open", instanceId);
  Instant registrationTime = modifyConfig.get(REGISTRATION_TIME, instanceId);
  Preconditions.checkArgument(registrationTime.compareTo(txStartTime) < 0, "The to-be-closed instance [%s] was started after this transaction" +
      "which indicates a successful restart and can hence not be closed: %s vs %s", instanceId, registrationTime, txStartTime);
  modifyConfig.remove(REGISTRATION_TIME, instanceId);
}

代码示例来源:origin: thinkaurelius/titan

@Override
public Instant sleepPast(Instant futureTime) throws InterruptedException {
  Instant now;
  ChronoUnit unit = getUnit();
  /*
   * Distributed storage managers that rely on timestamps play with the
   * least significant bit in timestamp longs, turning it on or off to
   * ensure that deletions are logically ordered before additions within a
   * single batch mutation. This is not a problem at microsecond
   * resolution because we pretendulate microsecond resolution by
   * multiplying currentTimeMillis by 1000, so the LSB can vary freely.
   * It's also not a problem with nanosecond resolution because the
   * resolution is just too fine, relative to how long a mutation takes,
   * for it to matter in practice. But it can lead to corruption at
   * millisecond resolution (and does, in testing).
   */
  if (unit.equals(TimeUnit.MILLISECONDS))
    futureTime = futureTime.plusMillis(1L);
  while ((now = getTime()).compareTo(futureTime) <= 0) {
    long delta = getTime(futureTime) - getTime(now);
    if (0L == delta)
      delta = 1L;
    if (log.isTraceEnabled()) {
      log.trace("Sleeping: now={} targettime={} delta={} {}",
          new Object[] { now, futureTime, delta, unit });
    }
    Temporals.timeUnit(unit).sleep(delta);
  }
  return now;
}

代码示例来源:origin: SonarSource/sonarqube

private Optional<Period> resolveByDate(DbSession dbSession, String projectUuid, Instant date, String propertyValue) {
 Instant now = Instant.ofEpochMilli(system2.now());
 checkPeriodProperty(date.compareTo(now) <= 0, propertyValue,
  "date is in the future (now: '%s')", supplierToString(() -> logDate(now)));
 LOG.debug("Resolving new code period by date: {}", supplierToString(() -> logDate(date)));
 Optional<Period> period = findFirstSnapshot(dbSession, createCommonQuery(projectUuid).setCreatedAfter(date.toEpochMilli()).setSort(BY_DATE, ASC))
  .map(dto -> newPeriod(LEAK_PERIOD_MODE_DATE, DateUtils.formatDate(date), dto));
 checkPeriodProperty(period.isPresent(), propertyValue, "No analysis found created after date '%s'", supplierToString(() -> logDate(date)));
 return period;
}

相关文章