Package jadex.common
Class IdGenerator
java.lang.Object
jadex.common.IdGenerator
A configurable Id generator.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final int
The default ID size.protected IResultCommand
<String, byte[]> Set of generated IDs to guarantee collision-free IDs.protected int
The selected id size.protected Random
Random number generator. -
Constructor Summary
ConstructorsConstructorDescriptionCreates 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, Random random) Creates a new ID generator.IdGenerator
(int idsize, Random random) Creates a new ID generator. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a used ID, only useful for collision-free mode.void
Switches the ID generator to BASE16 mode.void
Switches the ID generator to BASE64 mode.Generates an ID.static void
void
removeUsedId
(String id) Removes a used ID, only useful in collision-free mode.
-
Field Details
-
DEFAULT_ID_SIZE
protected static final int DEFAULT_ID_SIZEThe default ID size.- See Also:
-
random
Random number generator. -
idsize
protected int idsizeThe selected id size. -
encoder
-
generatedIds
Set of generated IDs to guarantee collision-free IDs.
-
-
Constructor Details
-
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
Creates a new ID generator. -
IdGenerator
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 Details
-
generateId
Generates an ID.- Returns:
- The ID.
-
addUsedId
Adds a used ID, only useful for collision-free mode.- Parameters:
id
- The id.
-
removeUsedId
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
-