org.threeten.bp.Instant.plus()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(10.7k)|赞(0)|评价(0)|浏览(123)

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

Instant.plus介绍

[英]Returns a copy of this instant with the specified duration added.

This instance is immutable and unaffected by this method call.
[中]返回添加了指定持续时间的此瞬间的副本。
此实例是不可变的,不受此方法调用的影响。

代码示例

代码示例来源:origin: googleapis/google-cloud-java

private Instant getScheduledTime() {
 return creationTime.plus(delay);
}

代码示例来源:origin: ThreeTen/threetenbp

/**
 * {@inheritDoc}
 * @throws DateTimeException {@inheritDoc}
 * @throws ArithmeticException {@inheritDoc}
 */
@Override
public Instant plus(long amountToAdd, TemporalUnit unit) {
  if (unit instanceof ChronoUnit) {
    switch ((ChronoUnit) unit) {
      case NANOS: return plusNanos(amountToAdd);
      case MICROS: return plus(amountToAdd / 1000000, (amountToAdd % 1000000) * 1000);
      case MILLIS: return plusMillis(amountToAdd);
      case SECONDS: return plusSeconds(amountToAdd);
      case MINUTES: return plusSeconds(Jdk8Methods.safeMultiply(amountToAdd, SECONDS_PER_MINUTE));
      case HOURS: return plusSeconds(Jdk8Methods.safeMultiply(amountToAdd, SECONDS_PER_HOUR));
      case HALF_DAYS: return plusSeconds(Jdk8Methods.safeMultiply(amountToAdd, SECONDS_PER_DAY / 2));
      case DAYS: return plusSeconds(Jdk8Methods.safeMultiply(amountToAdd, SECONDS_PER_DAY));
    }
    throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
  }
  return unit.addTo(this, amountToAdd);
}

代码示例来源:origin: googleapis/gax-java

@Test
public void testTimeoutBeforeDeadline() {
 HttpJsonChannel mockChannel = Mockito.mock(HttpJsonChannel.class);
 String expectedRequest = "fake";
 HttpJsonDirectCallable<String, String> callable = new HttpJsonDirectCallable<>(API_DESCRIPTOR);
 // Mock the channel that captures the call options
 ArgumentCaptor<HttpJsonCallOptions> capturedCallOptions =
   ArgumentCaptor.forClass(HttpJsonCallOptions.class);
 Mockito.when(
     mockChannel.issueFutureUnaryCall(
       capturedCallOptions.capture(),
       Mockito.anyString(),
       Mockito.any(ApiMethodDescriptor.class)))
   .thenReturn(SettableApiFuture.create());
 // Compose the call context
 Duration timeout = Duration.ofSeconds(10);
 Instant subsequentDeadline = Instant.now().plusSeconds(15);
 Instant minExpectedDeadline = Instant.now().plus(timeout);
 HttpJsonCallContext callContext =
   HttpJsonCallContext.createDefault()
     .withChannel(mockChannel)
     .withDeadline(subsequentDeadline)
     .withTimeout(timeout);
 callable.futureCall(expectedRequest, callContext);
 Instant maxExpectedDeadline = Instant.now().plus(timeout);
 // Verify that the timeout was converted into a deadline
 assertThat(capturedCallOptions.getValue().getDeadline()).isAtLeast(minExpectedDeadline);
 assertThat(capturedCallOptions.getValue().getDeadline()).isAtMost(maxExpectedDeadline);
}

代码示例来源:origin: googleapis/google-cloud-java

if (currTime.isAfter(lastResetTime.plus(windowLength))) {
 int sessionsToKeep =
   Math.max(options.getMinSessions(), maxSessionsInUse + options.getMaxIdleSessions());

代码示例来源:origin: org.threeten/threetenbp

/**
 * {@inheritDoc}
 * @throws DateTimeException {@inheritDoc}
 * @throws ArithmeticException {@inheritDoc}
 */
@Override
public Instant plus(long amountToAdd, TemporalUnit unit) {
  if (unit instanceof ChronoUnit) {
    switch ((ChronoUnit) unit) {
      case NANOS: return plusNanos(amountToAdd);
      case MICROS: return plus(amountToAdd / 1000000, (amountToAdd % 1000000) * 1000);
      case MILLIS: return plusMillis(amountToAdd);
      case SECONDS: return plusSeconds(amountToAdd);
      case MINUTES: return plusSeconds(Jdk8Methods.safeMultiply(amountToAdd, SECONDS_PER_MINUTE));
      case HOURS: return plusSeconds(Jdk8Methods.safeMultiply(amountToAdd, SECONDS_PER_HOUR));
      case HALF_DAYS: return plusSeconds(Jdk8Methods.safeMultiply(amountToAdd, SECONDS_PER_DAY / 2));
      case DAYS: return plusSeconds(Jdk8Methods.safeMultiply(amountToAdd, SECONDS_PER_DAY));
    }
    throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit);
  }
  return unit.addTo(this, amountToAdd);
}

代码示例来源:origin: googleapis/google-cloud-java

Instant totalExpiration = now().plus(maxAckExtensionPeriod);
OutstandingMessageBatch outstandingBatch = new OutstandingMessageBatch(doneCallback);
for (ReceivedMessage message : messages) {

代码示例来源:origin: googleapis/google-cloud-java

break;
case FIXED_RATE:
 this.creationTime = this.creationTime.plus(delay);
 schedulePendingCallable(this);
 break;

代码示例来源:origin: ThreeTen/threetenbp

/**
 * {@inheritDoc}
 * @throws DateTimeException {@inheritDoc}
 * @throws ArithmeticException {@inheritDoc}
 */
@Override
public Instant minus(long amountToSubtract, TemporalUnit unit) {
  return (amountToSubtract == Long.MIN_VALUE ? plus(Long.MAX_VALUE, unit).plus(1, unit) : plus(-amountToSubtract, unit));
}

代码示例来源:origin: ThreeTen/threetenbp

/**
 * Returns a copy of this instant with the specified duration in nanoseconds added.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param nanosToAdd  the nanoseconds to add, positive or negative
 * @return an {@code Instant} based on this instant with the specified nanoseconds added, not null
 * @throws DateTimeException if the result exceeds the maximum or minimum instant
 * @throws ArithmeticException if numeric overflow occurs
 */
public Instant plusNanos(long nanosToAdd) {
  return plus(0, nanosToAdd);
}

代码示例来源:origin: org.threeten/threetenbp

/**
 * {@inheritDoc}
 * @throws DateTimeException {@inheritDoc}
 * @throws ArithmeticException {@inheritDoc}
 */
@Override
public Instant minus(long amountToSubtract, TemporalUnit unit) {
  return (amountToSubtract == Long.MIN_VALUE ? plus(Long.MAX_VALUE, unit).plus(1, unit) : plus(-amountToSubtract, unit));
}

代码示例来源:origin: org.threeten/threetenbp

/**
 * Returns a copy of this instant with the specified duration in nanoseconds added.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param nanosToAdd  the nanoseconds to add, positive or negative
 * @return an {@code Instant} based on this instant with the specified nanoseconds added, not null
 * @throws DateTimeException if the result exceeds the maximum or minimum instant
 * @throws ArithmeticException if numeric overflow occurs
 */
public Instant plusNanos(long nanosToAdd) {
  return plus(0, nanosToAdd);
}

代码示例来源:origin: ThreeTen/threetenbp

/**
 * Returns a copy of this instant with the specified duration in seconds added.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param secondsToAdd  the seconds to add, positive or negative
 * @return an {@code Instant} based on this instant with the specified seconds added, not null
 * @throws DateTimeException if the result exceeds the maximum or minimum instant
 * @throws ArithmeticException if numeric overflow occurs
 */
public Instant plusSeconds(long secondsToAdd) {
  return plus(secondsToAdd, 0);
}

代码示例来源:origin: ThreeTen/threetenbp

/**
 * Returns a copy of this instant with the specified duration in milliseconds added.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param millisToAdd  the milliseconds to add, positive or negative
 * @return an {@code Instant} based on this instant with the specified milliseconds added, not null
 * @throws DateTimeException if the result exceeds the maximum or minimum instant
 * @throws ArithmeticException if numeric overflow occurs
 */
public Instant plusMillis(long millisToAdd) {
  return plus(millisToAdd / 1000, (millisToAdd % 1000) * NANOS_PER_MILLI);
}

代码示例来源:origin: org.threeten/threetenbp

/**
 * Returns a copy of this instant with the specified duration in seconds added.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param secondsToAdd  the seconds to add, positive or negative
 * @return an {@code Instant} based on this instant with the specified seconds added, not null
 * @throws DateTimeException if the result exceeds the maximum or minimum instant
 * @throws ArithmeticException if numeric overflow occurs
 */
public Instant plusSeconds(long secondsToAdd) {
  return plus(secondsToAdd, 0);
}

代码示例来源:origin: org.threeten/threetenbp

/**
 * Returns a copy of this instant with the specified duration in milliseconds added.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param millisToAdd  the milliseconds to add, positive or negative
 * @return an {@code Instant} based on this instant with the specified milliseconds added, not null
 * @throws DateTimeException if the result exceeds the maximum or minimum instant
 * @throws ArithmeticException if numeric overflow occurs
 */
public Instant plusMillis(long millisToAdd) {
  return plus(millisToAdd / 1000, (millisToAdd % 1000) * NANOS_PER_MILLI);
}

代码示例来源:origin: ThreeTen/threetenbp

@Override
public Instant instant() {
  return baseClock.instant().plus(offset);
}
@Override

代码示例来源:origin: org.threeten/threetenbp

@Override
public Instant instant() {
  return baseClock.instant().plus(offset);
}
@Override

代码示例来源:origin: com.google.api/gax-httpjson

@Override
public ApiFuture<ResponseT> futureCall(RequestT request, ApiCallContext inputContext) {
 Preconditions.checkNotNull(request);
 HttpJsonCallContext context = HttpJsonCallContext.createDefault().nullToSelf(inputContext);
 @Nullable Instant deadline = context.getDeadline();
 // Try to convert the timeout into a deadline and use it if it occurs before the actual deadline
 if (context.getTimeout() != null) {
  @Nonnull Instant newDeadline = Instant.now().plus(context.getTimeout());
  if (deadline == null || newDeadline.isBefore(deadline)) {
   deadline = newDeadline;
  }
 }
 HttpJsonCallOptions callOptions =
   HttpJsonCallOptions.newBuilder()
     .setDeadline(deadline)
     .setCredentials(context.getCredentials())
     .build();
 return context.getChannel().issueFutureUnaryCall(callOptions, request, descriptor);
}

代码示例来源:origin: googleapis/gax-java

@Override
public ApiFuture<ResponseT> futureCall(RequestT request, ApiCallContext inputContext) {
 Preconditions.checkNotNull(request);
 HttpJsonCallContext context = HttpJsonCallContext.createDefault().nullToSelf(inputContext);
 @Nullable Instant deadline = context.getDeadline();
 // Try to convert the timeout into a deadline and use it if it occurs before the actual deadline
 if (context.getTimeout() != null) {
  @Nonnull Instant newDeadline = Instant.now().plus(context.getTimeout());
  if (deadline == null || newDeadline.isBefore(deadline)) {
   deadline = newDeadline;
  }
 }
 HttpJsonCallOptions callOptions =
   HttpJsonCallOptions.newBuilder()
     .setDeadline(deadline)
     .setCredentials(context.getCredentials())
     .build();
 return context.getChannel().issueFutureUnaryCall(callOptions, request, descriptor);
}

代码示例来源:origin: googleapis/gax-java

@Test
public void testTimeout() {
 HttpJsonChannel mockChannel = Mockito.mock(HttpJsonChannel.class);
 String expectedRequest = "fake";
 HttpJsonDirectCallable<String, String> callable = new HttpJsonDirectCallable<>(API_DESCRIPTOR);
 // Mock the channel that captures the call options
 ArgumentCaptor<HttpJsonCallOptions> capturedCallOptions =
   ArgumentCaptor.forClass(HttpJsonCallOptions.class);
 Mockito.when(
     mockChannel.issueFutureUnaryCall(
       capturedCallOptions.capture(),
       Mockito.anyString(),
       Mockito.any(ApiMethodDescriptor.class)))
   .thenReturn(SettableApiFuture.create());
 // Compose the call context
 Duration timeout = Duration.ofSeconds(10);
 Instant minExpectedDeadline = Instant.now().plus(timeout);
 HttpJsonCallContext callContext =
   HttpJsonCallContext.createDefault().withChannel(mockChannel).withTimeout(timeout);
 callable.futureCall(expectedRequest, callContext);
 Instant maxExpectedDeadline = Instant.now().plus(timeout);
 // Verify that the timeout was converted into a deadline
 assertThat(capturedCallOptions.getValue().getDeadline()).isAtLeast(minExpectedDeadline);
 assertThat(capturedCallOptions.getValue().getDeadline()).isAtMost(maxExpectedDeadline);
}

相关文章