Package jadex.commons

Class IdGenerator


  • public class IdGenerator
    extends java.lang.Object
    A configurable Id generator.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static int DEFAULT_ID_SIZE
      The default ID size.
      protected IResultCommand<java.lang.String,​byte[]> encoder  
      protected java.util.Set<java.lang.String> generatedIds
      Set of generated IDs to guarantee collision-free IDs.
      protected int idsize
      The selected id size.
      protected java.util.Random random
      Random 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
      void addUsedId​(java.lang.String id)
      Adds a used ID, only useful for collision-free mode.
      void base16Mode()
      Switches the ID generator to BASE16 mode.
      void base64Mode()
      Switches the ID generator to BASE64 mode.
      java.lang.String generateId()
      Generates an ID.
      static void main​(java.lang.String[] args)  
      void removeUsedId​(java.lang.String id)
      Removes a used ID, only useful in collision-free mode.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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)