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
TheUniqueIdGeneratorImplis an implementation of theGeneratorcapable of generating IDStringinstances unique on the system on which them were generated to IDs generated with the sameUniqueIdGeneratorImplon another system.
-
-
Constructor Summary
Constructors Constructor Description UniqueIdGeneratorImpl()Constructs aUniqueIdGeneratorImplwith a default ID length of 36.UniqueIdGeneratorImpl(int aIdLength)Constructs aUniqueIdGeneratorImplwith the provided ID length.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanhasNext()Tests whether theGeneratoris capable of generating aGenerator.next()item.static voidinitSeed()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.Stringnext()Generates a next item.voidremove()
-
-
-
Constructor Detail
-
UniqueIdGeneratorImpl
public UniqueIdGeneratorImpl()
Constructs aUniqueIdGeneratorImplwith a default ID length of 36.
-
UniqueIdGeneratorImpl
public UniqueIdGeneratorImpl(int aIdLength)
Constructs aUniqueIdGeneratorImplwith 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 theGeneratoris capable of generating aGenerator.next()item.
-
next
public java.lang.String next()
Generates a next item.
-
remove
public void remove()
- Specified by:
removein interfacejava.util.Iterator<java.lang.String>
-
-