Package de.xima.fc.copy
Class UniqueNameGenerationHelper.NameGenerationOptions
java.lang.Object
de.xima.fc.copy.UniqueNameGenerationHelper.NameGenerationOptions
- Enclosing class:
- UniqueNameGenerationHelper
POJO for customizing the options
-
Method Summary
Modifier and TypeMethodDescriptioncopySuffix
(String copySuffix) Setup the interpolator so that the generated names are likeMyEntity_Copy_4
copyWithSpace
(String copyName) Setup the interpolator so that the generated names are likeMyEntity (Copy 4)
create()
int
int
int
interpolator
(BiFunction<String, Integer, String> interpolator) maxAttempts
(int maxAttempts) maxLength
(int maxLength) When generating the new name, replaces all matches for the given regex with the given replacement.sanitizer
(UnaryOperator<String> sanitizer) startIndex
(int startIndex) validityCheck
(Predicate<String> validityCheck)
-
Method Details
-
getMaxLength
public int getMaxLength() -
getStartIndex
public int getStartIndex() -
getValidityCheck
-
getSanitizer
-
getInterpolator
-
getMaxAttempts
public int getMaxAttempts() -
maxLength
- Parameters:
maxLength
- Maximum length that is allowed for the name. The generated name is truncated to fit this length.- Returns:
- This for chaining.
-
maxAttempts
- Parameters:
maxAttempts
- Maximum number of generated names that are tried (againstgetValidityCheck()
).- Returns:
- This for chaining.
-
startIndex
- Parameters:
startIndex
- The initial index used for generating new names. Defaults to1
, so the first generated name ends onCopy_1
.- Returns:
- This for chaining.
-
validityCheck
public UniqueNameGenerationHelper.NameGenerationOptions validityCheck(Predicate<String> validityCheck) - Parameters:
validityCheck
- A predicate that checks whether a given generated name is allowed, eg. whether a project with that name exists already. It must returntrue
if the given new name is valid,false
otherwise.- Returns:
- This for chaining.
-
sanitizer
- Parameters:
sanitizer
- An operator that takes a generated name and sanitizes it, eg. replaces characters that are not allowed for that name, such as whitespaces with underscores.- Returns:
- This for chaining.
-
interpolator
public UniqueNameGenerationHelper.NameGenerationOptions interpolator(BiFunction<String, Integer, String> interpolator) - Parameters:
interpolator
- Function that receives the name and the current index and creates the derived name with the index, egmyfile (copy 2)
.
-
copySuffix
Setup the interpolator so that the generated names are likeMyEntity_Copy_4
- Parameters:
copySuffix
- Suffix added to the original name, eg.Copy
.- Returns:
- This for chaining.
-
copyWithSpace
Setup the interpolator so that the generated names are likeMyEntity (Copy 4)
- Parameters:
copyName
- Localized name for 'Copy'.- Returns:
- This for chaining.
-
replace
public UniqueNameGenerationHelper.NameGenerationOptions replace(String disallowedCharactersRegex, char replacementCharacter) When generating the new name, replaces all matches for the given regex with the given replacement. Useful eg. for replacing whitespaces with underscores.- Parameters:
disallowedCharactersRegex
- Characters that are not allowed in the name and should be replaced.replacementCharacter
- Character that replaces the disallowed characters.- Returns:
- This for chaining.
-
create
-