Class UniqueNameGenerationHelper.NameGenerationOptions

    • Method Detail

      • copyWithSuffixAndIndex

        @CanIgnoreReturnValue
        public UniqueNameGenerationHelper.NameGenerationOptions copyWithSuffixAndIndex​(String copySuffix,
                                                                                       String separator)
        Sets an interpolator so that the generated names are like MyEntity_Copy_4. In general, given a suffix and separator, the name is generated from the base name and index as <BASE_NAME><SEPARATOR><SUFFIX><SEPARATOR><INDEX> Replaces any interpolator previously set via interpolator().
        Parameters:
        copySuffix - Suffix added to the original name, e.g. Copy.
        separator - Separator between the base name, suffix and index.
        Returns:
        These options for chaining method calls.
      • copyWithIndex

        @CanIgnoreReturnValue
        public UniqueNameGenerationHelper.NameGenerationOptions copyWithIndex​(String separator)
        Sets an interpolator so that the generated names are like MyEntity 4. In general, given a separator, the name is generated from the base name and index as <BASE_NAME><SEPARATOR><INDEX>. Replaces any interpolator previously set via interpolator().
        Parameters:
        separator - Separator between the base name and index.
        Returns:
        These options for chaining method calls.
      • copyWithSpace

        @CanIgnoreReturnValue
        public UniqueNameGenerationHelper.NameGenerationOptions copyWithSpace​(String copyName)
        Sets an interpolator so that the generated names are like MyEntity (Copy 4). Replaces any interpolator previously set via interpolator().
        Parameters:
        copyName - Localized name for 'Copy'.
        Returns:
        These options for chaining method calls.
      • interpolator

        public BiFunction<? super String,​? super Integer,​? extends String> interpolator()
        Gets the interpolator for generating candidate names. The interpolator is a function that receives the name and the current index and creates the derived name with the index, e.g. my_file (copy 2).

        Defaults to (name, index) -> name + "_" + index.

        Returns:
        The interpolator to use.
      • interpolator

        @CanIgnoreReturnValue
        public UniqueNameGenerationHelper.NameGenerationOptions interpolator​(BiFunction<? super String,​? super Integer,​? extends String> interpolator)
        Sets the interpolator for generating candidate names. The interpolator is a function that receives the name and the current index and creates the derived name with the index, e.g. my_file (copy 2).

        Defaults to (name, index) -> name + "_" + index.

        Parameters:
        interpolator - The interpolator to use.
        Returns:
        These options for chaining method calls.
      • maxAttempts

        public int maxAttempts()
        Gets the maximum number of attempts to make for generating a new name before giving up. At most this number of candidate names will be tried.

        Defaults to 256.

        Returns:
        Maximum number of attempts.
      • maxAttempts

        @CanIgnoreReturnValue
        public UniqueNameGenerationHelper.NameGenerationOptions maxAttempts​(int maxAttempts)
        Sets the maximum number of attempts to make for generating a new name before giving up. At most this number of candidate names will be tried.

        Defaults to 256.

        Parameters:
        maxAttempts - Maximum number of attempts.
        Returns:
        These options for chaining method calls.
      • maxLength

        public int maxLength()
        Gets the maximum length that is allowed for the name. The generated name is truncated to fit this length.

        Defaults to no maximum length.

        Returns:
        Maximum length that is allowed for the name.
      • maxLength

        @CanIgnoreReturnValue
        public UniqueNameGenerationHelper.NameGenerationOptions maxLength​(int maxLength)
        Sets the maximum length that is allowed for the name. The generated name is truncated to fit this length.

        Defaults to no maximum length.

        Parameters:
        maxLength - Maximum length that is allowed for the name.
        Returns:
        These options for chaining method calls.
      • replace

        @CanIgnoreReturnValue
        public UniqueNameGenerationHelper.NameGenerationOptions replace​(String disallowedCharactersRegex,
                                                                        char replacementCharacter)
        Sets a sanitizer so that, when generating the new name, replaces all matches for the given regex with the given replacement. Replaces any sanitizer previously set via sanitizer(). For example, you can use this options to replace whitespaces with underscores.
        Parameters:
        disallowedCharactersRegex - Regex for substrings or characters that are not allowed in the name and should be replaced.
        replacementCharacter - Character to replace the disallowed characters.
        Returns:
        These options for chaining method calls.
      • sanitizer

        public Function<? super String,​? extends String> sanitizer()
        Gets the sanitizer that takes a generated name and sanitizes it. For example, the sanitizer could replace characters that are not allowed for a name with a replacement character, e.g. whitespaces with underscores.

        Defaults to the identity operator, i.e. no sanitization.

        Returns:
        The sanitizer to use.
      • sanitizer

        @CanIgnoreReturnValue
        public UniqueNameGenerationHelper.NameGenerationOptions sanitizer​(Function<? super String,​? extends String> sanitizer)
        Sets the sanitizer that takes a generated name and sanitizes it. For example, the sanitizer could replace characters that are not allowed for a name with a replacement character, e.g. whitespaces with underscores.

        Defaults to the identity operator, i.e. no sanitization.

        Parameters:
        sanitizer - The sanitizer to use.
        Returns:
        This for chaining.
      • startIndex

        public int startIndex()
        Gets the initial index used for generating new names. Defaults to 1, so the first generated name ends on Copy_1.
        Returns:
        The initial index used for generating new names.
      • startIndex

        @CanIgnoreReturnValue
        public UniqueNameGenerationHelper.NameGenerationOptions startIndex​(int startIndex)
        Sets the initial index used for generating new names. Defaults to 1, so the first generated name ends on Copy_1.
        Parameters:
        startIndex - The initial index used for generating new names.
        Returns:
        This for chaining.
      • validityCheck

        public Predicate<? super String> validityCheck()
        Gets the validity check that tests whether a given generated name is allowed. For example, the check could test whether an entity with that name exists already. It must return true if the given new name is valid, and false otherwise.
        Returns:
        The predicate that checks whether a given generated name is allowed.
      • validityCheck

        @CanIgnoreReturnValue
        public UniqueNameGenerationHelper.NameGenerationOptions validityCheck​(Predicate<? super String> validityCheck)
        Sets the validity check that tests whether a given generated name is allowed. For example, the check could test whether an entity with that name exists already. It must return true if the given new name is valid, and false otherwise.
        Parameters:
        validityCheck - A predicate that checks whether a given generated name is allowed.
        Returns:
        These options for chaining method calls.