Package com.github.f4b6a3.uuid.util
Class UuidUtil
- java.lang.Object
-
- com.github.f4b6a3.uuid.util.UuidUtil
-
public final class UuidUtil extends Object
Utility that provides methods for checking UUID version, for extracting information from UUIDs, and etc.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static UUIDapplyVersion(UUID uuid, int version)Applies UUID version bits into the UUIDstatic intextractClockSequence(UUID uuid)Get the clock sequence from a time-based, time-ordered or DCE Security UUID.static InstantextractInstant(UUID uuid)Get the instant from a time-based, time-ordered or DCE Security UUID.static byteextractLocalDomain(UUID uuid)Get the local domain number from a DCE Security UUID.static intextractLocalIdentifier(UUID uuid)Get the local identifier number from a DCE Security UUID.static longextractNodeIdentifier(UUID uuid)Get the node identifier from a time-based, time-ordered or DCE Security UUID.static longextractTimestamp(UUID uuid)Get the timestamp from a time-based, time-ordered or DCE Security UUID.static longextractUnixMilliseconds(UUID uuid)Get the Unix epoch milliseconds from a time-based, time-ordered or DCE Security UUID.static UuidVariantgetVariant(UUID uuid)Get the UUID version.static UuidVersiongetVersion(UUID uuid)Get the UUID version.static booleanisDceSecurity(UUID uuid)Checks whether the UUID version 2.static booleanisNameBasedMd5(UUID uuid)Checks whether the UUID version 3.static booleanisNameBasedSha1(UUID uuid)Checks whether the UUID version 5.static booleanisNil(UUID uuid)Checks whether the UUID is equal to the Nil UUID.static booleanisRandomBased(UUID uuid)Checks whether the UUID version 4.static booleanisReservedFuture(UUID uuid)Checks whether the UUID variant is reserved future.static booleanisReservedMicrosoft(UUID uuid)Checks whether the UUID variant is reserved Microsoft.static booleanisReservedNcs(UUID uuid)Checks whether the UUID variant is reserved NCS.static booleanisRfc4122(UUID uuid)Checks whether the UUID variant is the one defined by the RFC-4122.static booleanisTimeBased(UUID uuid)Checks whether the UUID version 1.static booleanisTimeOrdered(UUID uuid)Checks whether the UUID version 6.protected static char[]removeHyphens(char[] input)
-
-
-
Method Detail
-
getVersion
public static UuidVersion getVersion(UUID uuid)
Get the UUID version. See:UuidVersion- Parameters:
uuid- a UUID- Returns:
- a
UuidVersion
-
getVariant
public static UuidVariant getVariant(UUID uuid)
Get the UUID version. See:UuidVariant- Parameters:
uuid- a UUID- Returns:
- a
UuidVariant
-
applyVersion
public static UUID applyVersion(UUID uuid, int version)
Applies UUID version bits into the UUID- Parameters:
uuid- a UUIDversion- a version- Returns:
- a UUID
-
isNil
public static boolean isNil(UUID uuid)
Checks whether the UUID is equal to the Nil UUID. The nil UUID is special UUID that has all 128 bits set to zero.- Parameters:
uuid- a UUID- Returns:
- boolean true if it is an RFC4122 variant
-
isRfc4122
public static boolean isRfc4122(UUID uuid)
Checks whether the UUID variant is the one defined by the RFC-4122.- Parameters:
uuid- a UUID- Returns:
- boolean true if it is an RFC4122 variant
-
isReservedNcs
public static boolean isReservedNcs(UUID uuid)
Checks whether the UUID variant is reserved NCS.- Parameters:
uuid- a UUID- Returns:
- boolean true if it is an reserved NCS variant
-
isReservedMicrosoft
public static boolean isReservedMicrosoft(UUID uuid)
Checks whether the UUID variant is reserved Microsoft.- Parameters:
uuid- a UUID- Returns:
- boolean true if it is an reserved Microsoft variant
-
isReservedFuture
public static boolean isReservedFuture(UUID uuid)
Checks whether the UUID variant is reserved future.- Parameters:
uuid- a UUID- Returns:
- boolean true if it is an reserved future variant
-
isRandomBased
public static boolean isRandomBased(UUID uuid)
Checks whether the UUID version 4.- Parameters:
uuid- a UUID- Returns:
- boolean true if it is a random UUID
-
isNameBasedMd5
public static boolean isNameBasedMd5(UUID uuid)
Checks whether the UUID version 3.- Parameters:
uuid- a UUID- Returns:
- boolean true if it is a name-based UUID
-
isNameBasedSha1
public static boolean isNameBasedSha1(UUID uuid)
Checks whether the UUID version 5.- Parameters:
uuid- a UUID- Returns:
- boolean true if it is a name-based UUID
-
isTimeBased
public static boolean isTimeBased(UUID uuid)
Checks whether the UUID version 1.- Parameters:
uuid- a UUID- Returns:
- boolean true if it is a time-based UUID
-
isTimeOrdered
public static boolean isTimeOrdered(UUID uuid)
Checks whether the UUID version 6.- Parameters:
uuid- a UUID- Returns:
- boolean true if it is a time-ordered UUID
-
isDceSecurity
public static boolean isDceSecurity(UUID uuid)
Checks whether the UUID version 2.- Parameters:
uuid- a UUID- Returns:
- boolean true if it is a DCE Security UUID
-
extractNodeIdentifier
public static long extractNodeIdentifier(UUID uuid)
Get the node identifier from a time-based, time-ordered or DCE Security UUID.- Parameters:
uuid- a UUID- Returns:
- long the node identifier
- Throws:
IllegalUuidException- if the input is not a time-based, time-ordered or DCE Security UUID.
-
extractClockSequence
public static int extractClockSequence(UUID uuid)
Get the clock sequence from a time-based, time-ordered or DCE Security UUID.- Parameters:
uuid- a UUID- Returns:
- int the clock sequence
- Throws:
IllegalUuidException- if the input is not a time-based, time-ordered or DCE Security UUID.
-
extractInstant
public static Instant extractInstant(UUID uuid)
Get the instant from a time-based, time-ordered or DCE Security UUID.- Parameters:
uuid- a UUID- Returns:
Instant- Throws:
IllegalUuidException- if the input is not a time-based, time-ordered or DCE Security UUID.
-
extractUnixMilliseconds
public static long extractUnixMilliseconds(UUID uuid)
Get the Unix epoch milliseconds from a time-based, time-ordered or DCE Security UUID. The value returned by this method is the number of milliseconds since 1970-01-01 (Unix epoch).- Parameters:
uuid- a UUID- Returns:
- Unix milliseconds
- Throws:
IllegalUuidException- if the input is not a time-based, time-ordered or DCE Security UUID.
-
extractTimestamp
public static long extractTimestamp(UUID uuid)
Get the timestamp from a time-based, time-ordered or DCE Security UUID. The value returned by this method is the number of 100-nanos since 1582-10-15 (Gregorian epoch).- Parameters:
uuid- a UUID- Returns:
- long the timestamp
- Throws:
IllegalUuidException- if the input is not a time-based, time-ordered or DCE Security UUID.
-
extractLocalDomain
public static byte extractLocalDomain(UUID uuid)
Get the local domain number from a DCE Security UUID.- Parameters:
uuid- a UUID- Returns:
- the local domain
- Throws:
IllegalUuidException- if the input is not a DCE Security UUID.
-
extractLocalIdentifier
public static int extractLocalIdentifier(UUID uuid)
Get the local identifier number from a DCE Security UUID.- Parameters:
uuid- a UUID- Returns:
- the local identifier
- Throws:
IllegalUuidException- if the input is not a DCE Security UUID.
-
removeHyphens
protected static char[] removeHyphens(char[] input)
-
-