Package de.xima.fc.common.text
Class UniqueNameGenerationHelper
- java.lang.Object
-
- de.xima.fc.common.text.UniqueNameGenerationHelper
-
public final class UniqueNameGenerationHelper extends Object
Helper class for generating unique names. Lets you customize the name generation process, e.g. by setting a maximum length for the name, a validity check for the generated names, or a sanitizer for the names.For example, sometimes a new name needs to be generated for an entity, but not all names are allowed. This class helps to generate new unique names with an index and returns the first name it finds that passes the given validity check. Could be used, for example, to create a new name for a copied project, e.g.
My Project_Copy_9
.- Since:
- 8.3.0
- Author:
- XIMA MEDIA GmbH
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
UniqueNameGenerationHelper.NameGenerationOptions
Options for generating unique names.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
generateNewName(String candidateName, UniqueNameGenerationHelper.NameGenerationOptions options)
Sometimes a new name needs to be generated for an entity, but not all names are allowed.
-
-
-
Method Detail
-
generateNewName
public static String generateNewName(String candidateName, UniqueNameGenerationHelper.NameGenerationOptions options) throws LimitExceededException
Sometimes a new name needs to be generated for an entity, but not all names are allowed. This method generates new names with an index and returns the first name it finds that passes the given validity check. May be used, for example, to create a new name for a copied project, e.g.My Project_Copy_9
.When the given candidate name is
valid
, it is returned as is. Otherwise, candidate names aregenerated from the candidate name
, and sanitized via thesanitizer
. The first generated name that passes the validity check is returned. If no such name can be found due to themaximum number of attempts
being reached, the method throws aLimitExceededException
.- Parameters:
candidateName
- Candidate name to use as a base.options
- options for generating the new name- Returns:
- A new name that passes the validity check.
- Throws:
LimitExceededException
- When the maximum number of attempts was reached and no valid name could be found.
-
-