java.lang.Object
org.refcodes.generator.UniqueIdGenerator
- All Implemented Interfaces:
Iterator<String>
,Generator<String>
,IdGenerator
- Direct Known Subclasses:
UniqueIdGeneratorSingleton
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.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Defines the type of BASE-64 encoding to use for generated IDs. -
Constructor Summary
ConstructorDescriptionConstructs aUniqueIdGenerator
with a default TID length of 36.UniqueIdGenerator
(int aIdLength) Constructs aUniqueIdGenerator
with the provided TID length.UniqueIdGenerator
(int aIdLength, UniqueIdGenerator.IdEncoding aIdEncoding) Constructs aUniqueIdGenerator
with the provided TID length.UniqueIdGenerator
(UniqueIdGenerator.IdEncoding aIdEncoding) Constructs aUniqueIdGenerator
with a default TID length of 36. -
Method Summary
Modifier and TypeMethodDescriptionboolean
hasNext()
Tests whether theGenerator
is capable of generating aGenerator.next()
item.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.next()
Generates a next item.void
remove()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Iterator
forEachRemaining
-
Constructor Details
-
UniqueIdGenerator
public UniqueIdGenerator()Constructs aUniqueIdGenerator
with a default TID length of 36. Uses BASE-64 alike encoding (padding chars omitted). -
UniqueIdGenerator
public UniqueIdGenerator(int aIdLength) Constructs aUniqueIdGenerator
with the provided TID length. Uses BASE-64 alike encoding (padding chars omitted).- Parameters:
aIdLength
- The length for the generated IDs.
-
UniqueIdGenerator
Constructs aUniqueIdGenerator
with a default TID length of 36.- Parameters:
aIdEncoding
- TheUniqueIdGenerator.IdEncoding
to use for the IDs being generated (padding chars omitted).
-
UniqueIdGenerator
Constructs aUniqueIdGenerator
with the provided TID length.- Parameters:
aIdLength
- The length for the generated IDs.aIdEncoding
- TheUniqueIdGenerator.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 theGenerator
is capable of generating aGenerator.next()
item. -
next
Generates a next item. -
remove
public void remove()
-