Package org.opencms.util
Class CmsUUID
java.lang.Object
org.opencms.util.CmsUUID
- All Implemented Interfaces:
Externalizable
,Serializable
,Cloneable
,Comparable<CmsUUID>
Generates a UUID using spatial and temporal uniqueness.
Spatial uniqueness is derived from ethernet address (MAC, 802.1); temporal from system clock.
For more information about the algorithm used, please see draft-leach-uuids-guids-01.txt.
Because Java is unable to read the MAC address of the machine
(without using JNI), the MAC address has to be provided first
by using the static init(String)
method.
This class is just a facade wrapper for the "real" UUID implementation.
- Since:
- 6.0.0
- See Also:
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Check that the given id is not the null id.clone()
Creates a clone of this CmsUUID.int
boolean
static CmsUUID
getConstantUUID
(String name) Returns a constant (name based) UUID, based on the given name in the OpenCms name space.static String
Returns a String representing a dummy (random based) ethernet address.static CmsUUID
Returns a null UUID, use this null UUID to check if a UUID has been initialized or not.static CmsUUID
Returns a constant (name based) UUID for OpenCms, based on "www.opencms.org" in the dns name space.Returns the String representation of this UUID, same astoString()
.int
hashCode()
Optimized hashCode implementation for UUID's.static void
Initialize the UUID generator with the ethernet address of the server machine.boolean
Returns true if this UUID is equal to the null UUID.static boolean
isValidUUID
(String uuid) Returnstrue
if the given UUID is valid.void
byte[]
Returns the UUID as a 16-byte byte array.toString()
static CmsUUID
Returns the given String transformed to a UUID in case the String is a valid UUID.void
-
Field Details
-
UUID_REGEX
A regular expression for matching UUIDs.- See Also:
-
-
Constructor Details
-
CmsUUID
public CmsUUID()Creates a new UUID.Please note that the static init() method has to be called first to initialize the internet address of the machine.
-
CmsUUID
Create a UUID based on a binary data array.- Parameters:
data
- a binary data array representing a UUID
-
CmsUUID
Create a UUID based on a String.- Parameters:
uuid
- a String representing a UUID- Throws:
NumberFormatException
- in case uuid is not a valid UUID
-
-
Method Details
-
checkId
Check that the given id is not the null id.- Parameters:
id
- the id to checkcanBeNull
- only if flag is set,null
is accepted- See Also:
-
getConstantUUID
Returns a constant (name based) UUID, based on the given name in the OpenCms name space.- Parameters:
name
- the name to derive the uuid from- Returns:
- name based UUID of the given name
-
getDummyEthernetAddress
Returns a String representing a dummy (random based) ethernet address.- Returns:
- a String representing a dummy (random based) ethernet address
-
getNullUUID
Returns a null UUID, use this null UUID to check if a UUID has been initialized or not.- Returns:
- a null UUID
-
getOpenCmsUUID
Returns a constant (name based) UUID for OpenCms, based on "www.opencms.org" in the dns name space.- Returns:
- name based UUID of OpenCms
-
init
Initialize the UUID generator with the ethernet address of the server machine.The ethernetAddress parameter must represent a 'standard' ethernet MAC address string (e.g. '00:C0:F0:3D:5B:7C').
- Parameters:
ethernetAddress
- the ethernet address of the server machine- Throws:
CmsInitException
- in case the ethernetAddress String is not a valid ethernet address
-
isValidUUID
Returnstrue
if the given UUID is valid.- Parameters:
uuid
- the UUID to check- Returns:
true
if the given UUID is valid
-
valueOf
Returns the given String transformed to a UUID in case the String is a valid UUID.- Parameters:
uuid
- the String to transform to a UUID- Returns:
- the given String transformed to a UUID in case the String is a valid UUID
- Throws:
NumberFormatException
- in case the String is no valid UUID
-
clone
Creates a clone of this CmsUUID. -
compareTo
- Specified by:
compareTo
in interfaceComparable<CmsUUID>
- See Also:
-
equals
-
getStringValue
Returns the String representation of this UUID, same astoString()
.This method is useful if bean like access to the UUID String is required.
- Returns:
- the String representation of this UUID
-
hashCode
Optimized hashCode implementation for UUID's. -
isNullUUID
Returns true if this UUID is equal to the null UUID.- Returns:
- true if this UUID is equal to the null UUID
-
readExternal
- Specified by:
readExternal
in interfaceExternalizable
- See Also:
-
toByteArray
Returns the UUID as a 16-byte byte array.- Returns:
- 16-byte byte array that contains the UUID's bytes in the network byte order
-
toString
-
writeExternal
- Specified by:
writeExternal
in interfaceExternalizable
- Throws:
IOException
- See Also:
-