java.time.Duration.get()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(9.8k)|赞(0)|评价(0)|浏览(188)

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

Duration.get介绍

[英]Gets the number of nanoseconds within the second in this duration.

The length of the duration is stored using two fields - seconds and nanoseconds. The nanoseconds part is a value from 0 to 999,999,999 that is an adjustment to the length in seconds. The total duration is defined by calling this method and #getSeconds().

A Duration represents a directed distance between two points on the time-line. A negative duration is expressed by the negative sign of the seconds part. A duration of -1 nanosecond is stored as -1 seconds plus 999,999,999 nanoseconds.
[中]获取此持续时间内秒内的纳秒数。
持续时间的长度使用两个字段存储-秒和纳秒。纳秒部分是一个从0到99999999的值,它是对以秒为单位的长度的调整。通过调用此方法和#getSeconds()定义总持续时间。
持续时间表示时间线上两点之间的定向距离。负持续时间由秒部分的负号表示。-1纳秒的持续时间存储为-1秒加9999999纳秒。

代码示例

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

@Override
public int getMaxInactiveInterval() {
  return (int) this.session.getMetaData().getMaxInactiveInterval().get(ChronoUnit.SECONDS);
}

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

@Override
public Flux<PopResponse> bPop(Publisher<BPopCommand> commands) {
  return connection.executeDedicated(cmd -> Flux.from(commands).concatMap(command -> {
    Assert.notNull(command.getKeys(), "Keys must not be null!");
    Assert.notNull(command.getDirection(), "Direction must not be null!");
    long timeout = command.getTimeout().get(ChronoUnit.SECONDS);
    Mono<PopResult> mappedMono = (ObjectUtils.nullSafeEquals(Direction.RIGHT, command.getDirection())
        ? cmd.brpop(timeout, command.getKeys().stream().toArray(ByteBuffer[]::new))
        : cmd.blpop(timeout, command.getKeys().stream().toArray(ByteBuffer[]::new)))
            .map(kv -> Arrays.asList(kv.getKey(), kv.getValue())).map(PopResult::new);
    return mappedMono.map(value -> new PopResponse(command, value));
  }));
}

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

@Override
public Flux<ByteBufferResponse<BRPopLPushCommand>> bRPopLPush(Publisher<BRPopLPushCommand> commands) {
  return connection.executeDedicated(cmd -> Flux.from(commands).concatMap(command -> {
    Assert.notNull(command.getKey(), "Key must not be null!");
    Assert.notNull(command.getDestination(), "Destination key must not be null!");
    Assert.notNull(command.getTimeout(), "Timeout must not be null!");
    return cmd.brpoplpush(command.getTimeout().get(ChronoUnit.SECONDS), command.getKey(), command.getDestination())
        .map(value -> new ByteBufferResponse<>(command, value));
  }));
}

代码示例来源:origin: HuygensING/timbuctoo

@JsonIgnore
 public synchronized String getSpeed() {
  if (startMoment != null) {
   long duration = Duration.between(startMoment, Instant.now()).get(ChronoUnit.SECONDS);
   return String.format("%d quads/s", duration > 0 ? numberOfTriplesProcessed / duration : numberOfTriplesProcessed);
  }
  return "";
 }
}

代码示例来源:origin: com.github.robozonky/robozonky-app

public ZonkyApiTokenSupplier(final ZonkyScope scope, final ApiProvider apis, final SecretProvider secrets,
               final Duration refreshAfter) {
  this.scope = scope;
  this.apis = apis;
  this.secrets = secrets;
  // fit refresh interval between 1 and 4 minutes
  final long refreshSeconds = Math.min(240, Math.max(60, refreshAfter.get(ChronoUnit.SECONDS) - 60));
  LOGGER.debug("Token refresh may be attempted any time past {} seconds before expiration.", refreshSeconds);
  refresh = Duration.ofSeconds(refreshSeconds);
}

代码示例来源:origin: it.tidalwave.bluemarine2/it-tidalwave-bluemarine2-commons

/*******************************************************************************************************************
 *
 *
 ******************************************************************************************************************/
@Nonnull
public static String format (final @Nonnull Duration duration)
 {
  final long s = duration.get(ChronoUnit.SECONDS);
  final long hours = s / 3600;
  final long minutes = (s / 60) % 60;
  final long seconds = s % 60;
  return (hours == 0) ? String.format("%02d:%02d", minutes, seconds)
            : String.format("%02d:%02d:%02d", hours, minutes, seconds);
 }

代码示例来源:origin: com.palantir.conjure.java.api/service-config

@Override
public long get(TemporalUnit temporalUnit) {
  return toJavaDuration().get(temporalUnit);
}

代码示例来源:origin: walmartlabs/concord

private static Long parseTimeout(Object timeout) {
    if (timeout == null) {
      return null;
    }

    if (timeout instanceof String) {
      Duration duration = Duration.parse((CharSequence) timeout);
      return duration.get(ChronoUnit.SECONDS);
    }

    throw new IllegalArgumentException("Invalid process timeout value type: expected an ISO-8601 value, got: " + timeout);
  }
}

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

java.time.Duration d = java.time.Duration.parse("PT1H2M34S");
System.out.println("Duration in seconds: " + d.get(java.time.temporal.ChronoUnit.SECONDS));

代码示例来源:origin: theotherp/nzbhydra2

public FileDownloadEntity(SearchResultEntity searchResult, FileDownloadAccessType nzbAccessType, SearchSource accessSource, FileDownloadStatus status, String error) {
  this.searchResult = searchResult;
  this.nzbAccessType = nzbAccessType;
  this.accessSource = accessSource;
  this.status = status;
  this.time = Instant.now();
  this.username = SessionStorage.username.get();
  this.userAgent = SessionStorage.userAgent.get();
  this.ip = SessionStorage.IP.get();
  this.age = (int) (Duration.between(searchResult.getPubDate(), searchResult.getFirstFound()).get(ChronoUnit.SECONDS) / (24 * 60 * 60));
  setError(error);
}

代码示例来源:origin: metatron-app/metatron-discovery

@Override
public long get(final TemporalUnit unit) {
 return period.getUnits().contains(unit) ? period.get(unit) : duration.get(unit);
}

代码示例来源:origin: org.jboss.eap/wildfly-clustering-web-spi

@Override
public int getMaxInactiveInterval() {
  return (int) this.session.getMetaData().getMaxInactiveInterval().get(ChronoUnit.SECONDS);
}

代码示例来源:origin: org.wildfly/wildfly-clustering-web-spi

@Override
public int getMaxInactiveInterval() {
  return (int) this.session.getMetaData().getMaxInactiveInterval().get(ChronoUnit.SECONDS);
}

代码示例来源:origin: RoboZonky/robozonky

/**
 * If protected by CAPTCHA, gives the first instant when the CAPTCHA protection is over.
 * @return Present if loan protected by CAPTCHA, otherwise empty.
 */
public Optional<OffsetDateTime> getLoanCaptchaProtectionEndDateTime() {
  final Duration captchaDelay = loan.getRating().getCaptchaDelay();
  if (captchaDelay.get(ChronoUnit.SECONDS) == 0) {
    return Optional.empty();
  } else {
    return Optional.of(loan.getDatePublished().plus(captchaDelay));
  }
}

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

/**
 * If protected by CAPTCHA, gives the first instant when the CAPTCHA protection is over.
 * @return Present if loan protected by CAPTCHA, otherwise empty.
 */
public Optional<OffsetDateTime> getLoanCaptchaProtectionEndDateTime() {
  final Duration captchaDelay = loan.getRating().getCaptchaDelay();
  if (captchaDelay.get(ChronoUnit.SECONDS) == 0) {
    return Optional.empty();
  } else {
    return Optional.of(loan.getDatePublished().plus(captchaDelay));
  }
}

代码示例来源:origin: org.springframework.data/spring-data-redis

@Override
public Flux<PopResponse> bPop(Publisher<BPopCommand> commands) {
  return connection.executeDedicated(cmd -> Flux.from(commands).concatMap(command -> {
    Assert.notNull(command.getKeys(), "Keys must not be null!");
    Assert.notNull(command.getDirection(), "Direction must not be null!");
    long timeout = command.getTimeout().get(ChronoUnit.SECONDS);
    Mono<PopResult> mappedMono = (ObjectUtils.nullSafeEquals(Direction.RIGHT, command.getDirection())
        ? cmd.brpop(timeout, command.getKeys().stream().toArray(ByteBuffer[]::new))
        : cmd.blpop(timeout, command.getKeys().stream().toArray(ByteBuffer[]::new)))
            .map(kv -> Arrays.asList(kv.getKey(), kv.getValue())).map(PopResult::new);
    return mappedMono.map(value -> new PopResponse(command, value));
  }));
}

代码示例来源:origin: apache/servicemix-bundles

@Override
public Flux<PopResponse> bPop(Publisher<BPopCommand> commands) {
  return connection.executeDedicated(cmd -> Flux.from(commands).concatMap(command -> {
    Assert.notNull(command.getKeys(), "Keys must not be null!");
    Assert.notNull(command.getDirection(), "Direction must not be null!");
    long timeout = command.getTimeout().get(ChronoUnit.SECONDS);
    Mono<PopResult> mappedMono = (ObjectUtils.nullSafeEquals(Direction.RIGHT, command.getDirection())
        ? cmd.brpop(timeout, command.getKeys().stream().toArray(ByteBuffer[]::new))
        : cmd.blpop(timeout, command.getKeys().stream().toArray(ByteBuffer[]::new)))
            .map(kv -> Arrays.asList(kv.getKey(), kv.getValue())).map(PopResult::new);
    return mappedMono.map(value -> new PopResponse(command, value));
  }));
}

代码示例来源:origin: io.github.factoryfx/javafxDataEditing

private void setFields(Duration duration, TextField textField, ComboBox<ChronoUnit> comboBox) {
  if (duration != null) {
    textField.setText(String.valueOf(duration.get(ChronoUnit.SECONDS)));
    comboBox.setValue(ChronoUnit.SECONDS);
  } else {
    textField.setText(null);
    comboBox.setValue(null);
  }
}

代码示例来源:origin: org.springframework.data/spring-data-redis

@Override
public Flux<ByteBufferResponse<BRPopLPushCommand>> bRPopLPush(Publisher<BRPopLPushCommand> commands) {
  return connection.executeDedicated(cmd -> Flux.from(commands).concatMap(command -> {
    Assert.notNull(command.getKey(), "Key must not be null!");
    Assert.notNull(command.getDestination(), "Destination key must not be null!");
    Assert.notNull(command.getTimeout(), "Timeout must not be null!");
    return cmd.brpoplpush(command.getTimeout().get(ChronoUnit.SECONDS), command.getKey(), command.getDestination())
        .map(value -> new ByteBufferResponse<>(command, value));
  }));
}

代码示例来源:origin: apache/servicemix-bundles

@Override
public Flux<ByteBufferResponse<BRPopLPushCommand>> bRPopLPush(Publisher<BRPopLPushCommand> commands) {
  return connection.executeDedicated(cmd -> Flux.from(commands).concatMap(command -> {
    Assert.notNull(command.getKey(), "Key must not be null!");
    Assert.notNull(command.getDestination(), "Destination key must not be null!");
    Assert.notNull(command.getTimeout(), "Timeout must not be null!");
    return cmd.brpoplpush(command.getTimeout().get(ChronoUnit.SECONDS), command.getKey(), command.getDestination())
        .map(value -> new ByteBufferResponse<>(command, value));
  }));
}

相关文章