类 IdGenerator


  • public class IdGenerator
    extends java.lang.Object
    Generates strings to be used as identifiers.

    Use builder() to create an instance.

    • 方法概要

      所有方法 静态方法 实例方法 具体方法 
      修饰符和类型 方法 说明
      static IdGenerator.Builder builder()  
      java.lang.String generateId​(java.lang.String text)
      Generate an ID based on the provided text and previously generated IDs.
      • 从类继承的方法 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 方法详细资料

      • builder

        public static IdGenerator.Builder builder()
        返回:
        a new builder with default arguments
      • generateId

        public java.lang.String generateId​(java.lang.String text)

        Generate an ID based on the provided text and previously generated IDs.

        This method is not thread safe, concurrent calls can end up with non-unique identifiers.

        Note that collision can occur in the case that

        • Method called with 'X'
        • Method called with 'X' again
        • Method called with 'X-1'

        In that case, the three generated IDs will be:

        • X
        • X-1
        • X-1

        Therefore if collisions are unacceptable you should ensure that numbers are stripped from end of text.

        参数:
        text - Text that the identifier should be based on. Will be normalised, then used to generate the identifier.
        返回:
        text if this is the first instance that the text has been passed to the method. Otherwise, text + "-" + X will be returned, where X is the number of times that text has previously been passed in. If text is empty, the default identifier given in the constructor will be used.