public class UUIDGen
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static byte[] |
decompose(java.util.UUID uuid)
decomposes a uuid into raw bytes.
|
static long |
getAdjustedTimestamp(java.util.UUID uuid)
Returns a milliseconds-since-epoch value for a type-1 UUID.
|
static java.util.UUID |
getRandomTimeUUIDFromMicros(long whenInMicros)
Similar to
getTimeUUIDFromMicros , but randomize (using SecureRandom) the clock and sequence. |
static java.util.UUID |
getTimeUUID()
Creates a type 1 UUID (time-based UUID).
|
static java.util.UUID |
getTimeUUID(long when)
Creates a type 1 UUID (time-based UUID) with the timestamp of @param when, in milliseconds.
|
static java.util.UUID |
getTimeUUID(long when,
long nanos) |
static java.util.UUID |
getTimeUUID(long when,
long nanos,
long clockSeqAndNode) |
static byte[] |
getTimeUUIDBytes()
Returns a 16 byte representation of a type 1 UUID (a time-based UUID),
based on the current system time.
|
static byte[] |
getTimeUUIDBytes(long timeMillis,
int nanos)
Converts a 100-nanoseconds precision timestamp into the 16 byte representation
of a type 1 UUID (a time-based UUID).
|
static java.util.UUID |
getTimeUUIDFromMicros(long whenInMicros)
Returns a version 1 UUID using the provided timestamp and the local clock and sequence.
|
static java.util.UUID |
getUUID(java.nio.ByteBuffer raw)
creates a type 1 uuid from raw bytes.
|
static java.util.UUID |
maxTimeUUID(long timestamp)
Returns the biggest possible type 1 UUID having the provided timestamp.
|
static long |
microsTimestamp(java.util.UUID uuid) |
static java.util.UUID |
minTimeUUID(long timestamp)
Returns the smaller possible type 1 UUID having the provided timestamp.
|
static long |
unixTimestamp(java.util.UUID uuid) |
static int |
unixTimestampInSec(java.util.UUID uuid) |
public static java.util.UUID getTimeUUID()
public static java.util.UUID getTimeUUID(long when)
public static java.util.UUID getTimeUUIDFromMicros(long whenInMicros)
Note that this method is generally only safe to use if you can guarantee that the provided parameter is unique across calls (otherwise the returned UUID won't be unique accross calls).
whenInMicros
- a unix time in microseconds.id
such that microsTimestamp(id) == whenInMicros
. Please not that
multiple calls to this method with the same value of whenInMicros
will return the same
UUID.public static java.util.UUID getRandomTimeUUIDFromMicros(long whenInMicros)
getTimeUUIDFromMicros
, but randomize (using SecureRandom) the clock and sequence.
If you can guarantee that the whenInMicros
argument is unique (for this JVM instance) for
every call, then you should prefer getTimeUUIDFromMicros
which is faster. If you can't
guarantee this however, this method will ensure the returned UUID are still unique (accross calls)
through randomization.
whenInMicros
- a unix time in microseconds.id
such that microsTimestamp(id) == whenInMicros
. The UUID returned
by different calls will be unique even if whenInMicros
is not.public static java.util.UUID getTimeUUID(long when, long nanos)
public static java.util.UUID getTimeUUID(long when, long nanos, long clockSeqAndNode)
public static java.util.UUID getUUID(java.nio.ByteBuffer raw)
public static byte[] decompose(java.util.UUID uuid)
public static byte[] getTimeUUIDBytes()
public static java.util.UUID minTimeUUID(long timestamp)
public static java.util.UUID maxTimeUUID(long timestamp)
public static long unixTimestamp(java.util.UUID uuid)
uuid
- public static int unixTimestampInSec(java.util.UUID uuid)
uuid
- public static long microsTimestamp(java.util.UUID uuid)
uuid
- public static byte[] getTimeUUIDBytes(long timeMillis, int nanos)
Warning: This method is not guaranteed to return unique UUIDs; Multiple invocations using identical timestamps will result in identical UUIDs.
public static long getAdjustedTimestamp(java.util.UUID uuid)
uuid
- a type-1 (time-based) UUIDjava.lang.IllegalArgumentException
- if the UUID is not version 1Copyright © 2017 The Apache Software Foundation