Package jadex.commons
Class IdGenerator
- java.lang.Object
 - 
- jadex.commons.IdGenerator
 
 
- 
public class IdGenerator extends java.lang.ObjectA configurable Id generator. 
- 
- 
Field Summary
Fields Modifier and Type Field Description protected static intDEFAULT_ID_SIZEThe default ID size.protected IResultCommand<java.lang.String,byte[]>encoderprotected java.util.Set<java.lang.String>generatedIdsSet of generated IDs to guarantee collision-free IDs.protected intidsizeThe selected id size.protected java.util.RandomrandomRandom number generator. 
- 
Constructor Summary
Constructors Constructor Description IdGenerator()Creates a new ID generator.IdGenerator(boolean collisionfree)Creates a new ID generator.IdGenerator(int idsize)Creates a new ID generator.IdGenerator(int idsize, boolean collisionfree, java.util.Random random)Creates a new ID generator.IdGenerator(int idsize, java.util.Random random)Creates a new ID generator. 
- 
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddUsedId(java.lang.String id)Adds a used ID, only useful for collision-free mode.voidbase16Mode()Switches the ID generator to BASE16 mode.voidbase64Mode()Switches the ID generator to BASE64 mode.java.lang.StringgenerateId()Generates an ID.static voidmain(java.lang.String[] args)voidremoveUsedId(java.lang.String id)Removes a used ID, only useful in collision-free mode. 
 - 
 
- 
- 
Field Detail
- 
DEFAULT_ID_SIZE
protected static final int DEFAULT_ID_SIZE
The default ID size.- See Also:
 - Constant Field Values
 
 
- 
random
protected java.util.Random random
Random number generator. 
- 
idsize
protected int idsize
The selected id size. 
- 
encoder
protected IResultCommand<java.lang.String,byte[]> encoder
 
- 
generatedIds
protected java.util.Set<java.lang.String> generatedIds
Set of generated IDs to guarantee collision-free IDs. 
 - 
 
- 
Constructor Detail
- 
IdGenerator
public IdGenerator()
Creates a new ID generator. 
- 
IdGenerator
public IdGenerator(int idsize)
Creates a new ID generator.- Parameters:
 idsize- Size of ID entropy in bytes, actual ID is slightly larger due to Base64 encoding.
 
- 
IdGenerator
public IdGenerator(boolean collisionfree)
Creates a new ID generator.- Parameters:
 collisionfree- If true, this will guarantee collision-free IDs. However, requires maintaining a set of used IDs, increasing memory consumption. This option is unnecessary for most use cases due to the extremely low probability of collisions at reasonable ID sizes.
 
- 
IdGenerator
public IdGenerator(int idsize, java.util.Random random)Creates a new ID generator. 
- 
IdGenerator
public IdGenerator(int idsize, boolean collisionfree, java.util.Random random)Creates a new ID generator.- Parameters:
 idsize- Size of ID entropy in bytes, actual ID is slightly larger due to Base64 encoding.collisionfree- If true, this will guarantee collision-free IDs. However, requires maintaining a set of used IDs, increasing memory consumption. This option is unnecessary for most use cases due to the extremely low probability of collisions at reasonable ID sizes.
 
 - 
 
- 
Method Detail
- 
generateId
public java.lang.String generateId()
Generates an ID.- Returns:
 - The ID.
 
 
- 
addUsedId
public void addUsedId(java.lang.String id)
Adds a used ID, only useful for collision-free mode.- Parameters:
 id- The id.
 
- 
removeUsedId
public void removeUsedId(java.lang.String id)
Removes a used ID, only useful in collision-free mode.- Parameters:
 id- The ID.
 
- 
base64Mode
public void base64Mode()
Switches the ID generator to BASE64 mode. 
- 
base16Mode
public void base16Mode()
Switches the ID generator to BASE16 mode. 
- 
main
public static void main(java.lang.String[] args)
 
 - 
 
 -