Class IdAllocator


  • public final class IdAllocator
    extends java.lang.Object
    Used to "uniquify" names within a given context. A base name is passed in, and the return value is the base name, or the base name extended with a suffix to make it unique. This class is not threadsafe.
    • Constructor Summary

      Constructors 
      Constructor Description
      IdAllocator()
      Creates a new allocator with no namespace.
      IdAllocator​(java.lang.String namespace)
      Creates a new allocator with the provided namespace.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String allocateId​(java.lang.String name)
      Allocates the id.
      void clear()
      Clears the allocator, resetting it to freshly allocated state.
      IdAllocator clone()
      Creates a clone of this IdAllocator instance, copying the allocator's namespace and key map.
      java.util.List<java.lang.String> getAllocatedIds()
      Returns a list of all allocated ids, sorted alphabetically.
      boolean isAllocated​(java.lang.String name)
      Checks to see if a given name has been allocated.
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • IdAllocator

        public IdAllocator()
        Creates a new allocator with no namespace.
      • IdAllocator

        public IdAllocator​(java.lang.String namespace)
        Creates a new allocator with the provided namespace.
    • Method Detail

      • getAllocatedIds

        public java.util.List<java.lang.String> getAllocatedIds()
        Returns a list of all allocated ids, sorted alphabetically.
      • clone

        public IdAllocator clone()
        Creates a clone of this IdAllocator instance, copying the allocator's namespace and key map.
        Overrides:
        clone in class java.lang.Object
      • allocateId

        public java.lang.String allocateId​(java.lang.String name)
        Allocates the id. Repeated calls for the same name will return "name", "name_0", "name_1", etc.
      • isAllocated

        public boolean isAllocated​(java.lang.String name)
        Checks to see if a given name has been allocated.
      • clear

        public void clear()
        Clears the allocator, resetting it to freshly allocated state.