Package de.xima.fc.copy
Class UniqueNameGenerationHelper.NameGenerationOptions
- java.lang.Object
-
- de.xima.fc.copy.UniqueNameGenerationHelper.NameGenerationOptions
-
- Enclosing class:
- UniqueNameGenerationHelper
public static class UniqueNameGenerationHelper.NameGenerationOptions extends Object
POJO for customizing the options
-
-
Method Summary
-
-
-
Method Detail
-
getMaxLength
public int getMaxLength()
-
getStartIndex
public int getStartIndex()
-
getSanitizer
public UnaryOperator<String> getSanitizer()
-
getInterpolator
public BiFunction<String,Integer,String> getInterpolator()
-
getMaxAttempts
public int getMaxAttempts()
-
maxLength
public UniqueNameGenerationHelper.NameGenerationOptions maxLength(int 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
public UniqueNameGenerationHelper.NameGenerationOptions maxAttempts(int maxAttempts)
- Parameters:
maxAttempts
- Maximum number of generated names that are tried (againstgetValidityCheck()
).- Returns:
- This for chaining.
-
startIndex
public UniqueNameGenerationHelper.NameGenerationOptions startIndex(int 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
public UniqueNameGenerationHelper.NameGenerationOptions sanitizer(UnaryOperator<String> 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
public UniqueNameGenerationHelper.NameGenerationOptions copySuffix(String copySuffix)
Setup the interpolator so that the generated names are likeMyEntity_Copy_4
- Parameters:
copySuffix
- Suffix added to the original name, eg. .- Returns:
- This for chaining.
-
copyWithSpace
public UniqueNameGenerationHelper.NameGenerationOptions copyWithSpace(String copyName)
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
public static UniqueNameGenerationHelper.NameGenerationOptions create()
-
-