Java Duration Calculate getTTLSeconds(Duration duration)

Here you can find the source of getTTLSeconds(Duration duration)

Description

get TTL Seconds

License

Apache License

Declaration

public static final int getTTLSeconds(Duration duration) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import com.google.common.base.Preconditions;
import java.time.Duration;
import java.time.temporal.TemporalUnit;

public class Main {
    public static final int getTTLSeconds(Duration duration) {
        Preconditions.checkArgument(duration != null && !duration.isZero(), "Must provide non-zero TTL");
        long ttlSeconds = Math.max(1, duration.getSeconds());
        assert ttlSeconds > 0;
        Preconditions.checkArgument(ttlSeconds <= Integer.MAX_VALUE, "tll value is too large [%s] - value overflow",
                duration);/*from w  w  w. j a  v a 2 s.  c o m*/
        return (int) ttlSeconds;
    }

    public static final int getTTLSeconds(long time, TemporalUnit unit) {
        return getTTLSeconds(Duration.of(time, unit));
    }
}

Related

  1. futureWithTimeout(Duration timeout, ScheduledExecutorService executorService)
  2. getDurationAsISO8601(Duration duration)
  3. getDurationByTimeValues(final long hours, final long minutes, final long seconds)
  4. getExpirationMillis(long now, Duration duration)
  5. getOrThrow(final ListenableFuture Future, final Duration timeout)
  6. isDuration(String value)
  7. isFinite(Duration duration)
  8. isInfPositive(Duration duration)
  9. max(Duration a, Duration b)