Class UniqueIdGenerator

java.lang.Object
org.refcodes.generator.UniqueIdGenerator
All Implemented Interfaces:
Iterator<String>, Generator<String>, IdGenerator
Direct Known Subclasses:
UniqueIdGeneratorSingleton

public class UniqueIdGenerator extends Object implements IdGenerator
The UniqueIdGenerator is an implementation of the Generator capable of generating TID String instances unique on the system on which them were generated to IDs generated with the same UniqueIdGenerator on another system.
  • Constructor Details

    • UniqueIdGenerator

      public UniqueIdGenerator()
      Constructs a UniqueIdGenerator with a default TID length of 36. Uses BASE-64 alike encoding (padding chars omitted).
    • UniqueIdGenerator

      public UniqueIdGenerator(int aIdLength)
      Constructs a UniqueIdGenerator with the provided TID length. Uses BASE-64 alike encoding (padding chars omitted).
      Parameters:
      aIdLength - The length for the generated IDs.
    • UniqueIdGenerator

      public UniqueIdGenerator(UniqueIdGenerator.IdEncoding aIdEncoding)
      Constructs a UniqueIdGenerator with a default TID length of 36.
      Parameters:
      aIdEncoding - The UniqueIdGenerator.IdEncoding to use for the IDs being generated (padding chars omitted).
    • UniqueIdGenerator

      public UniqueIdGenerator(int aIdLength, UniqueIdGenerator.IdEncoding aIdEncoding)
      Constructs a UniqueIdGenerator with the provided TID length.
      Parameters:
      aIdLength - The length for the generated IDs.
      aIdEncoding - The UniqueIdGenerator.IdEncoding to use for the IDs being generated (padding chars omitted).
  • Method Details

    • initSeed

      public static void initSeed()
      This method initializes the TID generator, it is invoked upon loading the utility class by the class loader (static block), though it may be called manually in case of TID collisions. Then a new random number as starting point for a specific part of the TID and the IP address are newly set.
    • hasNext

      public boolean hasNext()
      Tests whether the Generator is capable of generating a Generator.next() item.
      Specified by:
      hasNext in interface Generator<String>
      Specified by:
      hasNext in interface Iterator<String>
      Returns:
      true, if successful
    • next

      public String next()
      Generates a next item.
      Specified by:
      next in interface Generator<String>
      Specified by:
      next in interface Iterator<String>
      Returns:
      The next item generated
    • remove

      public void remove()
      Specified by:
      remove in interface Iterator<String>