Package jadex.commons
Class IdGenerator
- java.lang.Object
- 
- jadex.commons.IdGenerator
 
- 
 public class IdGenerator extends java.lang.ObjectA configurable Id generator.
- 
- 
Field SummaryFields 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 SummaryConstructors 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 SummaryAll 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_SIZEprotected static final int DEFAULT_ID_SIZE The default ID size.- See Also:
- Constant Field Values
 
 - 
randomprotected java.util.Random random Random number generator.
 - 
idsizeprotected int idsize The selected id size.
 - 
encoderprotected IResultCommand<java.lang.String,byte[]> encoder 
 - 
generatedIdsprotected java.util.Set<java.lang.String> generatedIds Set of generated IDs to guarantee collision-free IDs.
 
- 
 - 
Constructor Detail- 
IdGeneratorpublic IdGenerator() Creates a new ID generator.
 - 
IdGeneratorpublic 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.
 
 - 
IdGeneratorpublic 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.
 
 - 
IdGeneratorpublic IdGenerator(int idsize, java.util.Random random)Creates a new ID generator.
 - 
IdGeneratorpublic 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- 
generateIdpublic java.lang.String generateId() Generates an ID.- Returns:
- The ID.
 
 - 
addUsedIdpublic void addUsedId(java.lang.String id) Adds a used ID, only useful for collision-free mode.- Parameters:
- id- The id.
 
 - 
removeUsedIdpublic void removeUsedId(java.lang.String id) Removes a used ID, only useful in collision-free mode.- Parameters:
- id- The ID.
 
 - 
base64Modepublic void base64Mode() Switches the ID generator to BASE64 mode.
 - 
base16Modepublic void base16Mode() Switches the ID generator to BASE16 mode.
 - 
mainpublic static void main(java.lang.String[] args) 
 
- 
 
-