Java Code Examples for java.time.Duration#multipliedBy()

The following examples show how to use java.time.Duration#multipliedBy() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TCKDuration.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="MultipliedBy")
public void multipliedBy(long seconds, int nanos, int multiplicand, long expectedSeconds, int expectedNanos) {
    Duration t = Duration.ofSeconds(seconds, nanos);
    t = t.multipliedBy(multiplicand);
    assertEquals(t.getSeconds(), expectedSeconds);
    assertEquals(t.getNano(), expectedNanos);
}
 
Example 2
Source File: TCKDuration.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Test()
@UseDataProvider("provider_multipliedBy")
public void multipliedBy(long seconds, int nanos, int multiplicand, long expectedSeconds, int expectedNanos) {
    Duration t = Duration.ofSeconds(seconds, nanos);
    t = t.multipliedBy(multiplicand);
    assertEquals(t.getSeconds(), expectedSeconds);
    assertEquals(t.getNano(), expectedNanos);
}
 
Example 3
Source File: TCKDuration.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="MultipliedBy")
public void multipliedBy(long seconds, int nanos, int multiplicand, long expectedSeconds, int expectedNanos) {
    Duration t = Duration.ofSeconds(seconds, nanos);
    t = t.multipliedBy(multiplicand);
    assertEquals(t.getSeconds(), expectedSeconds);
    assertEquals(t.getNano(), expectedNanos);
}
 
Example 4
Source File: DelaySupplier.java    From vespa with Apache License 2.0 5 votes vote down vote up
@Override
public Duration getDelay(int executionCount) {
    Duration nextDelay = startDelay;
    for (int i = 1; i < executionCount; ++i) {
        nextDelay = nextDelay.multipliedBy(2);
    }
    return maxDelay.compareTo(nextDelay) > 0 ? nextDelay : maxDelay;
}
 
Example 5
Source File: TCKDuration.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="MultipliedBy")
public void multipliedBy(long seconds, int nanos, int multiplicand, long expectedSeconds, int expectedNanos) {
    Duration t = Duration.ofSeconds(seconds, nanos);
    t = t.multipliedBy(multiplicand);
    assertEquals(t.getSeconds(), expectedSeconds);
    assertEquals(t.getNano(), expectedNanos);
}
 
Example 6
Source File: VoiceGatewayRetrySpec.java    From Discord4J with GNU Lesser General Public License v3.0 5 votes vote down vote up
static Duration computeBackoff(long iteration, Duration minBackoff, Duration maxBackoff) {
    Duration nextBackoff;
    try {
        nextBackoff = minBackoff.multipliedBy((long) Math.pow(2, iteration));
        if (nextBackoff.compareTo(maxBackoff) > 0) {
            nextBackoff = maxBackoff;
        }
    } catch (ArithmeticException overflow) {
        nextBackoff = maxBackoff;
    }
    return nextBackoff;
}
 
Example 7
Source File: ExponentialBackoff.java    From smallrye-mutiny with Apache License 2.0 5 votes vote down vote up
private static Duration getNextAttemptDelay(Duration firstBackoff, Duration maxBackoff, int iteration) {
    Duration nextBackoff;
    try {
        nextBackoff = firstBackoff.multipliedBy((long) Math.pow(2, iteration));
        if (nextBackoff.compareTo(maxBackoff) > 0) {
            nextBackoff = maxBackoff;
        }
    } catch (ArithmeticException overflow) {
        nextBackoff = maxBackoff;
    }
    return nextBackoff;
}
 
Example 8
Source File: TCKDuration.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="MultipliedBy")
public void multipliedBy(long seconds, int nanos, int multiplicand, long expectedSeconds, int expectedNanos) {
    Duration t = Duration.ofSeconds(seconds, nanos);
    t = t.multipliedBy(multiplicand);
    assertEquals(t.getSeconds(), expectedSeconds);
    assertEquals(t.getNano(), expectedNanos);
}
 
Example 9
Source File: BackOffActor.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
private void backOff(final BackOffWithAnswer<?> backOffWithAnswer) {
    final Duration backOffTimeout = this.retryTimeoutStrategy.getNextTimeout();
    final Duration resetBackOffTimeout = backOffTimeout.multipliedBy(2L);

    log.debug("Going to back off for <{}> until sending answer: <{}>", backOffTimeout, backOffWithAnswer.getAnswer());

    this.getTimers().startSingleTimer(InternalTimers.BACK_OFF, new BackOffWithSender<>(getSender(), backOffWithAnswer), backOffTimeout);
    this.getTimers().startSingleTimer(InternalTimers.RESET_BACK_OFF, RESET_BACK_OFF, resetBackOffTimeout);
}
 
Example 10
Source File: Waiter.java    From teku with Apache License 2.0 4 votes vote down vote up
private static Duration nextPollInterval(final Duration duration) {
  final Duration nextInterval = duration.multipliedBy(2);
  return nextInterval.compareTo(MAX_POLL_INTERVAL) <= 0 ? nextInterval : MAX_POLL_INTERVAL;
}
 
Example 11
Source File: TCKDuration.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=ArithmeticException.class)
public void multipliedBy_tooBig() {
    Duration test = Duration.ofSeconds(1, 1);
    test.multipliedBy(Long.MAX_VALUE);
}
 
Example 12
Source File: TCKDuration.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=ArithmeticException.class)
public void multipliedBy_tooBig() {
    Duration test = Duration.ofSeconds(1, 1);
    test.multipliedBy(Long.MAX_VALUE);
}
 
Example 13
Source File: TCKDuration.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=ArithmeticException.class)
public void multipliedBy_tooBig() {
    Duration test = Duration.ofSeconds(1, 1);
    test.multipliedBy(Long.MAX_VALUE);
}
 
Example 14
Source File: TCKDuration.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=ArithmeticException.class)
public void multipliedBy_tooBig_negative() {
    Duration test = Duration.ofSeconds(1, 1);
    test.multipliedBy(Long.MIN_VALUE);
}
 
Example 15
Source File: TCKDuration.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=ArithmeticException.class)
public void multipliedBy_tooBig_negative() {
    Duration test = Duration.ofSeconds(1, 1);
    test.multipliedBy(Long.MIN_VALUE);
}
 
Example 16
Source File: TCKDuration.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=ArithmeticException.class)
public void multipliedBy_tooBig() {
    Duration test = Duration.ofSeconds(1, 1);
    test.multipliedBy(Long.MAX_VALUE);
}
 
Example 17
Source File: TCKDuration.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=ArithmeticException.class)
public void multipliedBy_tooBig_negative() {
    Duration test = Duration.ofSeconds(1, 1);
    test.multipliedBy(Long.MIN_VALUE);
}
 
Example 18
Source File: TCKDuration.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=ArithmeticException.class)
public void multipliedBy_tooBig_negative() {
    Duration test = Duration.ofSeconds(1, 1);
    test.multipliedBy(Long.MIN_VALUE);
}
 
Example 19
Source File: TCKDuration.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=ArithmeticException.class)
public void multipliedBy_tooBig() {
    Duration test = Duration.ofSeconds(1, 1);
    test.multipliedBy(Long.MAX_VALUE);
}
 
Example 20
Source File: DateTimeExtensions.java    From groovy with Apache License 2.0 2 votes vote down vote up
/**
 * Supports the multiplication operator; equivalent to calling the {@link Duration#multipliedBy(long)} method.
 *
 * @param self   a Duration
 * @param scalar the value to multiply by
 * @return a Duration
 * @since 2.5.0
 */
public static Duration multiply(final Duration self, long scalar) {
    return self.multipliedBy(scalar);
}