Package com.github.f4b6a3.uuid.creator
Class AbstractNameBasedUuidCreator
- java.lang.Object
-
- com.github.f4b6a3.uuid.creator.AbstractUuidCreator
-
- com.github.f4b6a3.uuid.creator.AbstractNameBasedUuidCreator
-
- Direct Known Subclasses:
NameBasedMd5UuidCreator
,NameBasedSha1UuidCreator
public abstract class AbstractNameBasedUuidCreator extends AbstractUuidCreator
Factory that creates name-based UUIDs.Name spaces predefined by RFC-4122 (Appendix C): - NAMESPACE_DNS: Name string is a fully-qualified domain name; - NAMESPACE_URL: Name string is a URL; - NAMESPACE_ISO_OID: Name string is an ISO OID; - NAMESPACE_X500_DN: Name string is an X.500 DN (in DER or a text format).
Sources: RFC-4122 - 4.3. Algorithm for Creating a Name-Based UUID https://tools.ietf.org/html/rfc4122#section-4.3 RFC-4122 - Appendix C - Some Name Space IDs https://tools.ietf.org/html/rfc4122#appendix-C
-
-
Field Summary
Fields Modifier and Type Field Description protected String
algorithm
protected static String
ALGORITHM_MD5
protected static String
ALGORITHM_SHA1
protected byte[]
namespace
-
Fields inherited from class com.github.f4b6a3.uuid.creator.AbstractUuidCreator
version, versionBits
-
-
Constructor Summary
Constructors Constructor Description AbstractNameBasedUuidCreator(UuidVersion version, String algorithm)
This constructor receives the name of a message digest.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description UUID
create(byte[] name)
Returns a name-based UUID.UUID
create(UuidNamespace namespace, byte[] name)
Returns a name-based UUID.UUID
create(UuidNamespace namespace, String name)
Returns a name-based UUID.UUID
create(String name)
Returns a name-based UUID.UUID
create(String namespace, byte[] name)
Returns a name-based UUID.UUID
create(String namespace, String name)
Returns a name-based UUID.UUID
create(UUID namespace, byte[] name)
Returns a name-based UUID. ### RFC-4122 - 4.3.UUID
create(UUID namespace, String name)
Returns a name-based UUID.<T extends AbstractNameBasedUuidCreator>
TwithNamespace(UuidNamespace namespace)
Sets a fixed name space to be used by default.<T extends AbstractNameBasedUuidCreator>
TwithNamespace(String namespace)
Sets a fixed name space to be used by default.<T extends AbstractNameBasedUuidCreator>
TwithNamespace(UUID namespace)
Sets a fixed name space to be used by default.-
Methods inherited from class com.github.f4b6a3.uuid.creator.AbstractUuidCreator
getUuid, getUuid, getVersion
-
-
-
-
Field Detail
-
namespace
protected byte[] namespace
-
algorithm
protected final String algorithm
-
ALGORITHM_MD5
protected static final String ALGORITHM_MD5
- See Also:
- Constant Field Values
-
ALGORITHM_SHA1
protected static final String ALGORITHM_SHA1
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AbstractNameBasedUuidCreator
public AbstractNameBasedUuidCreator(UuidVersion version, String algorithm)
This constructor receives the name of a message digest.- Parameters:
version
- the version numberalgorithm
- a message digest algorithm
-
-
Method Detail
-
create
public UUID create(byte[] name)
Returns a name-based UUID. The (optional) namespace to be used is set bywithNamespace(UUID)
- Parameters:
name
- a byte array of the name- Returns:
- a name-based UUID
-
create
public UUID create(String name)
Returns a name-based UUID. The (optional) namespace to be used is set bywithNamespace(UUID)
The name string is encoded into a sequence of bytes using the UTF-8 charset. If you want another charset, usecreate(byte[])
instead.- Parameters:
name
- a name string- Returns:
- a name-based UUID
-
create
public UUID create(UUID namespace, byte[] name)
Returns a name-based UUID. ### RFC-4122 - 4.3. Algorithm for Creating a Name-Based UUID (1) Allocate a UUID to use as a "name space ID" for all UUIDs generated from names in that name space; see Appendix C for some pre-defined values. (2) Choose either MD5 [4] or SHA-1 [8] as the hash algorithm; If backward compatibility is not an issue, SHA-1 is preferred. (3) Convert the name to a canonical sequence of octets (as defined by the standards or conventions of its name space); put the name space ID in network byte order. (4) Compute the hash of the name space ID concatenated with the name. (5) Set octets zero through 3 of the time_low field to octets zero through 3 of the hash. (6) Set octets zero and one of the time_mid field to octets 4 and 5 of the hash. (7) Set octets zero and one of the time_hi_and_version field to octets 6 and 7 of the hash. (8) Set the four most significant bits (bits 12 through 15) of the time_hi_and_version field to the appropriate 4-bit version number from Section 4.1.3. (9) Set the clock_seq_hi_and_reserved field to octet 8 of the hash. (10) Set the two most significant bits (bits 6 and 7) of the clock_seq_hi_and_reserved to zero and one, respectively. (11) Set the clock_seq_low field to octet 9 of the hash. (12) Set octets zero through five of the node field to octets 10 through 15 of the hash. (13) Convert the resulting UUID to local byte order.- Parameters:
namespace
- a name space UUID (optional)name
- a byte array of the name- Returns:
- a name-based UUID
-
create
public UUID create(UUID namespace, String name)
Returns a name-based UUID. The name string is encoded into a sequence of bytes using the UTF-8 charset. If you want another charset, usecreate(UUID, byte[])
instead.- Parameters:
namespace
- a name space UUID (optional)name
- a name string- Returns:
- a name-based UUID
-
create
public UUID create(String namespace, byte[] name)
Returns a name-based UUID.- Parameters:
namespace
- a name space UUID in string format (optional)name
- a byte array of the name- Returns:
- a name-based UUID
- Throws:
InvalidUuidException
- if the namespace is invalid
-
create
public UUID create(String namespace, String name)
Returns a name-based UUID. The name string is encoded into a sequence of bytes using the UTF-8 charset. If you want another charset, usecreate(String, byte[])
instead.- Parameters:
namespace
- a name space UUID in string format (optional)name
- a name string- Returns:
- a name-based UUID
- Throws:
InvalidUuidException
- if the namespace is invalid
-
create
public UUID create(UuidNamespace namespace, byte[] name)
Returns a name-based UUID.- Parameters:
namespace
- a name space enumeration (optional)name
- a byte array of the name- Returns:
- a name-based UUID
-
create
public UUID create(UuidNamespace namespace, String name)
Returns a name-based UUID. The name string is encoded into a sequence of bytes using the UTF-8 charset. If you want another charset, usecreate(UuidNamespace, byte[])
instead.- Parameters:
namespace
- a name space enumeration (optional)name
- a name string- Returns:
- a name-based UUID
-
withNamespace
public <T extends AbstractNameBasedUuidCreator> T withNamespace(UUID namespace)
Sets a fixed name space to be used by default. The namespace provided will be used by the methodcreate(String)
- Type Parameters:
T
- the type parameter- Parameters:
namespace
- a namespace UUID- Returns:
AbstractNameBasedUuidCreator
-
withNamespace
public <T extends AbstractNameBasedUuidCreator> T withNamespace(String namespace)
Sets a fixed name space to be used by default. The namespace provided will be used by the methodcreate(String)
- Type Parameters:
T
- the type parameter- Parameters:
namespace
- a namespace UUID in string format- Returns:
AbstractNameBasedUuidCreator
- Throws:
InvalidUuidException
- if the namespace is invalid
-
withNamespace
public <T extends AbstractNameBasedUuidCreator> T withNamespace(UuidNamespace namespace)
Sets a fixed name space to be used by default. The namespace provided will be used by the methodcreate(String)
- Type Parameters:
T
- the type parameter- Parameters:
namespace
- a namespace enumeration- Returns:
AbstractNameBasedUuidCreator
-
-