Class 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
    • Constructor Detail

      • AbstractNameBasedUuidCreator

        public AbstractNameBasedUuidCreator​(UuidVersion version,
                                            String algorithm)
        This constructor receives the name of a message digest.
        Parameters:
        version - the version number
        algorithm - 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 by withNamespace(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 by withNamespace(UUID) The name string is encoded into a sequence of bytes using the UTF-8 charset. If you want another charset, use create(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, use create(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, use create(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, use create(UuidNamespace, byte[]) instead.
        Parameters:
        namespace - a name space enumeration (optional)
        name - a name string
        Returns:
        a name-based UUID