Package org.refcodes.generator
Class UniqueIdGeneratorImpl
- java.lang.Object
-
- org.refcodes.generator.UniqueIdGeneratorImpl
-
- All Implemented Interfaces:
java.util.Iterator<java.lang.String>
,Generator<java.lang.String>
,IdGenerator
- Direct Known Subclasses:
UniqueIdGeneratorSingleton
public class UniqueIdGeneratorImpl extends java.lang.Object implements IdGenerator
TheUniqueIdGeneratorImpl
is an implementation of theGenerator
capable of generating IDString
instances unique on the system on which them were generated to IDs generated with the sameUniqueIdGeneratorImpl
on another system.
-
-
Constructor Summary
Constructors Constructor Description UniqueIdGeneratorImpl()
Constructs aUniqueIdGeneratorImpl
with a default ID length of 36.UniqueIdGeneratorImpl(int aIdLength)
Constructs aUniqueIdGeneratorImpl
with the provided ID length.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
hasNext()
Tests whether theGenerator
is capable of generating aGenerator.next()
item.static void
initSeed()
This method initializes the ID generator, it is invoked upon loading the utility class by the class loader (static block), though it may be called manually in case of ID collisions.java.lang.String
next()
Generates a next item.void
remove()
-
-
-
Constructor Detail
-
UniqueIdGeneratorImpl
public UniqueIdGeneratorImpl()
Constructs aUniqueIdGeneratorImpl
with a default ID length of 36.
-
UniqueIdGeneratorImpl
public UniqueIdGeneratorImpl(int aIdLength)
Constructs aUniqueIdGeneratorImpl
with the provided ID length.- Parameters:
aIdLength
- The length for the generated IDs.
-
-
Method Detail
-
initSeed
public static void initSeed()
This method initializes the ID generator, it is invoked upon loading the utility class by the class loader (static block), though it may be called manually in case of ID collisions. Then a new random number as starting point for a specific part of the ID and the IP address are newly set.
-
hasNext
public boolean hasNext()
Tests whether theGenerator
is capable of generating aGenerator.next()
item.
-
next
public java.lang.String next()
Generates a next item.
-
remove
public void remove()
- Specified by:
remove
in interfacejava.util.Iterator<java.lang.String>
-
-