Module com.github.f4b6a3.uuid
Interface TimeFunction
-
- All Superinterfaces:
LongSupplier
- All Known Implementing Classes:
DefaultTimeFunction,WindowsTimeFunction
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface public interface TimeFunction extends LongSupplier
Function that must return a number of 100-nanoseconds since 1970-01-01 (Unix epoch).Example:
// A function that returns `Instant.now()` as a number of 100ns TimeFunction f = () -> TimeFunction.toUnixTimestamp(Instant.now());In JDK 8,
Instant.now()has millisecond precision, in spite ofInstanthas nanoseconds resolution. In JDK 9+,Instant.now()has microsecond precision.
-
-
Method Summary
Static Methods Modifier and Type Method Description static longtoExpectedRange(long timestamp)Clears the leading bits so that the resulting number is in the range 0 to 2^60-1.static longtoUnixTimestamp(Instant instant)Converts an instant to a number of 100-nanoseconds since 1970-01-01 (Unix epoch).-
Methods inherited from interface java.util.function.LongSupplier
getAsLong
-
-
-
-
Method Detail
-
toUnixTimestamp
static long toUnixTimestamp(Instant instant)
Converts an instant to a number of 100-nanoseconds since 1970-01-01 (Unix epoch).- Parameters:
instant- an instant- Returns:
- a number of 100-nanoseconds since 1970-01-01 (Unix epoch)
-
toExpectedRange
static long toExpectedRange(long timestamp)
Clears the leading bits so that the resulting number is in the range 0 to 2^60-1.The result is equivalent to
n % 2^60.- Parameters:
timestamp- a number of 100-nanoseconds since 1970-01-01 (Unix epoch)- Returns:
- a number in the range 0 to 2^60-1.
-
-