Class UserCodeGenerator

    • Constructor Detail

      • UserCodeGenerator

        public UserCodeGenerator()
        Constructor.
      • UserCodeGenerator

        public UserCodeGenerator​(String characters)
        Constructor.
        Parameters:
        characters - Characters that may appear in generated user codes.
      • UserCodeGenerator

        public UserCodeGenerator​(int length)
        Constructor.
        Parameters:
        length - Length of generated user codes.
      • UserCodeGenerator

        public UserCodeGenerator​(String characters,
                                 int length)
        Constructor.
        Parameters:
        characters - Characters that may appear in generated user codes.
        length - Length of generated user codes.
      • UserCodeGenerator

        public UserCodeGenerator​(String characters,
                                 int length,
                                 Random random)
        Constructor.
        Parameters:
        characters - Characters that may appear in generated user codes.
        length - Length of generated user codes.
        random - A Random instance used for user code generation.
      • UserCodeGenerator

        public UserCodeGenerator​(UserCodeCharset charset)
        Constructor.
        Parameters:
        charset - A character set for user codes. The value returned from charset.getCharacters() is used unless charset is null.
      • UserCodeGenerator

        public UserCodeGenerator​(UserCodeCharset charset,
                                 int length)
        Constructor.
        Parameters:
        charset - A character set for user codes. The value returned from charset.getCharacters() is used unless charset is null.
        length - Length of generated user codes.
      • UserCodeGenerator

        public UserCodeGenerator​(UserCodeCharset charset,
                                 int length,
                                 Random random)
        Constructor.
        Parameters:
        charset - A character set for user codes. The value returned from charset.getCharacters() is used unless charset is null.
        length - Length of generated user codes.
        random - A Random instance used for user code generation.
    • Method Detail

      • getCharacters

        public String getCharacters()
        Get the characters that may appear in generated user codes.
        Returns:
        The characters that may appear in generated user codes.
      • setCharacters

        public UserCodeGenerator setCharacters​(String characters)
        Set characters that may appear in generated user codes.
        Parameters:
        characters - Characters that may appear in generated user codes.
        Returns:
        this object.
      • setCharacters

        public UserCodeGenerator setCharacters​(UserCodeCharset charset)
        Set characters that may appear in generated user codes. The value returned from charset.getCharacters() is used as characters for generated user codes unless charset is null.
        Parameters:
        charset - A character set for user codes.
        Returns:
        this object.
      • getLength

        public int getLength()
        Get the length of generated user codes.
        Returns:
        The length of generated user codes.
      • setLength

        public UserCodeGenerator setLength​(int length)
        Set length of generated user codes.
        Parameters:
        length - Length of generated user codes.
        Returns:
        this object.
      • getRandom

        public Random getRandom()
        Get the Random instance used for user code generation.
        Returns:
        The Random instance user for user code generation.
      • setRandom

        public UserCodeGenerator setRandom​(Random random)
        Set a Random instance used for user code generation.
        Parameters:
        random - A Random instance used for user code generation.
        Returns:
        this object.
      • generate

        public String generate()
        Generate a user code.

        If characters for user codes are not set, the value returned from UserCodeCharset.BASE20.getCharacters() (namely, "BCDFGHJKLMNPQRSTVWXZ") is used.

        If length is not set or its value is 0 or less, proper length is computed based on the characters and used.

        If a Random instance is not set, a new instance of SecureRandom is created and used.

        Returns:
        A newly-generated user code.