java.time.temporal.ChronoUnit.equals()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(5.1k)|赞(0)|评价(0)|浏览(115)

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

ChronoUnit.equals介绍

暂无

代码示例

代码示例来源: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: JanusGraph/janusgraph

@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 pretend to have 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(ChronoUnit.MILLIS))
    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={} {}", now, futureTime, delta, unit);
    }
    Temporals.timeUnit(unit).sleep(delta);
  }
  return now;
}

代码示例来源:origin: io.smallrye/smallrye-fault-tolerance

private boolean isAfterDelay() {
  long openedAt = circuitOpenedAt.get();
  long delay = config.get(CircuitBreakerConfig.DELAY);
  if (delay == 0) {
    return true;
  }
  ChronoUnit delayUnit = config.get(CircuitBreakerConfig.DELAY_UNIT);
  long elapsed;
  if (delayUnit.equals(ChronoUnit.MILLIS)) {
    elapsed = System.currentTimeMillis() - openedAt;
  } else {
    Instant start = Instant.ofEpochMilli(openedAt);
    Instant now = Instant.now();
    elapsed = delayUnit.between(start, now);
  }
  return elapsed >= delay;
}

代码示例来源:origin: com.github.almex/raildelays-api

/**
 * Create an an instance of {@link TimeDelay} with the {@code expectedTime} and the {@code delay}
 * of a certain {@code unit}.
 *
 * @param expectedTime the expected time such as : 1st January 2000 at 12:00
 * @param delay        delay in the {@code unit} counting from the {@code expectedTime}
 * @param unit         unit of the delay (unsupported units are {@code ChronoUnit.MICROS}, {@code ChronoUnit.NANOS}
 *                     and all not supported by {@link LocalTime#isSupported(TemporalUnit)})
 * @return a {@link TimeDelay} with the {@code expectedTime} and the {@code delay},
 * {@code null} if the {@code expectedTime} is {@code null}.
 * @throws UnsupportedTemporalTypeException if the unit is not supported
 */
public static TimeDelay of(LocalTime expectedTime, Long delay, TemporalUnit unit) {
  TimeDelay result = null;
  Objects.requireNonNull(unit);
  if (expectedTime != null) {
    Duration duration = Duration.of(DEFAULT_DELAY, DELAY_UNIT);
    if (delay != null) {
      if (!unit.isSupportedBy(expectedTime) ||
          ChronoUnit.NANOS.equals(unit) ||
          ChronoUnit.MICROS.equals(unit)) {
        throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
      }
      duration = Duration.of(delay, unit);
    }
    result = new TimeDelay(expectedTime, duration.toMillis());
  }
  return result;
}

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

@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;
}

相关文章