Class Generators

java.lang.Object
com.fasterxml.uuid.Generators

public class Generators extends Object
Root factory class for constructing UUID generators.
Since:
3.0
Author:
tatu
  • Field Details

    • _sharedTimer

      protected static UUIDTimer _sharedTimer
      If no explicit timer (and synchronizer it implicitly uses) is specified, we will create and use a single lazily-constructed timer, which uses in-JVM synchronization but no external file-based syncing.
    • _preferredIfAddr

      protected static EthernetAddress _preferredIfAddr
      The hardware address of the egress network interface.
  • Constructor Details

    • Generators

      public Generators()
  • Method Details

    • randomBasedGenerator

      public static RandomBasedGenerator randomBasedGenerator()
      Factory method for constructing UUID generator that uses default (shared) random number generator for constructing UUIDs according to standard version 4.
    • randomBasedGenerator

      public static RandomBasedGenerator randomBasedGenerator(Random rnd)
      Factory method for constructing UUID generator that uses specified random number generator for constructing UUIDs according to standard version 4.
    • nameBasedGenerator

      public static NameBasedGenerator nameBasedGenerator()
      Factory method for constructing UUID generator that uses specified random number generator for constructing UUIDs according to standard version 5, but without using a namespace. Digester to use will be SHA-1 as recommended by UUID spec.
    • nameBasedGenerator

      public static NameBasedGenerator nameBasedGenerator(UUID namespace)
      Factory method for constructing UUID generator that uses specified random number generator for constructing UUIDs according to standard version 5, with specified namespace (or without one if null is specified). Digester to use will be SHA-1 as recommened by UUID spec.
      Parameters:
      namespace - UUID that represents namespace to use; see NameBasedGenerator for 'standard' namespaces specified by UUID specs
    • nameBasedGenerator

      public static NameBasedGenerator nameBasedGenerator(UUID namespace, MessageDigest digester)
      Factory method for constructing UUID generator that uses specified random number generator for constructing UUIDs according to standard version 3 or 5, with specified namespace (or without one if null is specified), using specified digester. If digester is passed as null, a SHA-1 digester will be constructed.
      Parameters:
      namespace - UUID that represents namespace to use; see NameBasedGenerator for 'standard' namespaces specified by UUID specs
      digester - Digester to use; should be a MD5 or SHA-1 digester.
    • timeBasedEpochGenerator

      public static TimeBasedEpochGenerator timeBasedEpochGenerator()
      Factory method for constructing UUID generator that generates UUID using version 7 (Unix Epoch time+random based).

      NOTE: calls within same millisecond produce very similar values; this may be unsafe in some environments.

      No additional external synchronization is used.

    • timeBasedEpochGenerator

      public static TimeBasedEpochGenerator timeBasedEpochGenerator(Random random)
      Factory method for constructing UUID generator that generates UUID using version 7 (Unix Epoch time+random based), using specified Random number generator.

      NOTE: calls within same millisecond produce very similar values; this may be unsafe in some environments.

      No additional external synchronization is used.

    • timeBasedEpochGenerator

      public static TimeBasedEpochGenerator timeBasedEpochGenerator(Random random, UUIDClock clock)
      Factory method for constructing UUID generator that generates UUID using version 7 (Unix Epoch time+random based), using specified Random number generator. Timestamp to use is accessed using specified UUIDClock.

      NOTE: calls within same millisecond produce very similar values; this may be unsafe in some environments.

      No additional external synchronization is used.

      Since:
      4.3
    • timeBasedEpochRandomGenerator

      public static TimeBasedEpochRandomGenerator timeBasedEpochRandomGenerator()
      Factory method for constructing UUID generator that generates UUID using version 7 (Unix Epoch time+random based).

      Calls within same millisecond use additional per-call randomness to try to create more distinct values, compared to timeBasedEpochGenerator(Random)

      No additional external synchronization is used.

      Since:
      5.1
    • timeBasedEpochRandomGenerator

      public static TimeBasedEpochRandomGenerator timeBasedEpochRandomGenerator(Random random)
      Factory method for constructing UUID generator that generates UUID using version 7 (Unix Epoch time+random based), using specified Random number generator.

      Calls within same millisecond use additional per-call randomness to try to create more distinct values, compared to timeBasedEpochGenerator(Random)

      No additional external synchronization is used.

      Since:
      5.0
    • timeBasedEpochRandomGenerator

      public static TimeBasedEpochRandomGenerator timeBasedEpochRandomGenerator(Random random, UUIDClock clock)
      Factory method for constructing UUID generator that generates UUID using version 7 (Unix Epoch time+random based), using specified Random number generator. Timestamp to use is accessed using specified UUIDClock

      Calls within same millisecond use additional per-call randomness to try to create more distinct values, compared to timeBasedEpochGenerator(Random)

      No additional external synchronization is used.

      Since:
      5.0
    • defaultTimeBasedGenerator

      public static TimeBasedGenerator defaultTimeBasedGenerator()
      Factory method for constructing UUID generator that generates UUID using version 1 (time+location based). This method will use the ethernet address of the interface that routes to the default gateway, or if that cannot be found, then the address of an indeterminately selected non-loopback interface. For most simple and common networking configurations this will be the most appropriate address to use. The default interface is determined by the calling EthernetAddress.fromPreferredInterface() method. Note that this will only identify the preferred interface once: if you have a complex network setup where your outbound routes/interfaces may change dynamically. If you want your UUIDs to accurately reflect a deterministic selection of network interface, you should instead use a generator implementation that uses an explicitly specified address, such as timeBasedGenerator(EthernetAddress).
      Since:
      4.2
    • timeBasedGenerator

      public static TimeBasedGenerator timeBasedGenerator()
      Factory method for constructing UUID generator that generates UUID using version 1 (time+location based). Since no Ethernet address is passed, a bogus broadcast address will be constructed for purpose of UUID generation; usually it is better to instead access one of host's NIC addresses using EthernetAddress.fromInterface() which will use one of available MAC (Ethernet) addresses available.
    • timeBasedGenerator

      public static TimeBasedGenerator timeBasedGenerator(EthernetAddress ethernetAddress)
      Factory method for constructing UUID generator that generates UUID using version 1 (time+location based), using specified Ethernet address as the location part of UUID. No additional external synchronization is used.
    • timeBasedGenerator

      public static TimeBasedGenerator timeBasedGenerator(EthernetAddress ethernetAddress, TimestampSynchronizer sync)
      Factory method for constructing UUID generator that generates UUID using version 1 (time+location based), using specified Ethernet address as the location part of UUID, and specified synchronizer (which may add additional restrictions to guarantee system-wide uniqueness).
      Parameters:
      ethernetAddress - (optional) MAC address to use; if null, a transient random address is generated.
      See Also:
    • timeBasedGenerator

      public static TimeBasedGenerator timeBasedGenerator(EthernetAddress ethernetAddress, UUIDTimer timer)
      Factory method for constructing UUID generator that generates UUID using version 1 (time+location based), using specified Ethernet address as the location part of UUID, and specified UUIDTimer instance (which includes embedded synchronizer that defines synchronization behavior).
    • timeBasedReorderedGenerator

      public static TimeBasedReorderedGenerator timeBasedReorderedGenerator()
      Factory method for constructing UUID generator that generates UUID using version 6 (time+location based, reordered for DB locality). Since no Ethernet address is passed, a bogus broadcast address will be constructed for purpose of UUID generation; usually it is better to instead access one of host's NIC addresses using EthernetAddress.fromInterface() which will use one of available MAC (Ethernet) addresses available.
    • timeBasedReorderedGenerator

      public static TimeBasedReorderedGenerator timeBasedReorderedGenerator(EthernetAddress ethernetAddress)
      Factory method for constructing UUID generator that generates UUID using version 6 (time+location based, reordered for DB locality), using specified Ethernet address as the location part of UUID. No additional external synchronization is used.
    • timeBasedReorderedGenerator

      public static TimeBasedReorderedGenerator timeBasedReorderedGenerator(EthernetAddress ethernetAddress, UUIDTimer timer)
      Factory method for constructing UUID generator that generates UUID using version 6 (time+location based, reordered for DB locality), using specified Ethernet address as the location part of UUID, and specified UUIDTimer instance (which includes embedded synchronizer that defines synchronization behavior).