Package com._1c.g5.v8.dt.common
Class UniqueNameGenerator
java.lang.Object
com._1c.g5.v8.dt.common.UniqueNameGenerator
Unique name generator. Generates unique names by adding digits to a given prefix.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected String
formatNumber
(String numberFormat, int number) Format the generated number to string using the given format.generate
(String namePrefix, Collection<String> existingNames) Generate a unique name, based on the given name prefix and a collection of existing names.generate
(String namePrefix, Collection<String> existingNames, String numberFormat, Pattern duplicatePattern) Generate unique name, based on the given name prefix and a collection of the existing names.
-
Constructor Details
-
UniqueNameGenerator
public UniqueNameGenerator()
-
-
Method Details
-
generate
Generate a unique name, based on the given name prefix and a collection of existing names. Default duplicate pattern will be used:.+digit+
.Name will be generated as following example: if names
Name1
andName2
already exist, nameName3
will be generated.- Parameters:
namePrefix
- the name prefix to generate name with, cannot benull
existingNames
- the collection of existing names to check uniqueness for, cannot benull
- Returns:
- a unique name, based on the given name prefix and collection of the existing names, never
null
-
generate
public String generate(String namePrefix, Collection<String> existingNames, String numberFormat, Pattern duplicatePattern) Generate unique name, based on the given name prefix and a collection of the existing names.Custom duplicate-check pattern will be used. Number format can be used to format generated number, before appending it to the generated name.
- Parameters:
namePrefix
- the name prefix to generate name with, cannot benull
existingNames
- the collection of the existing names to check uniqueness for, cannot benull
numberFormat
- the number format to format generated number, before appending it to the generated name;String#format
style format is expected with one and only one%s
; can benull
if number formatting is not neededduplicatePattern
- the duplicate-check pattern, cannot benull
, must have regexp group with a digit inside it- Returns:
- a unique name, based on the given name prefix and collection of the existing names, never
null
-
formatNumber
Format the generated number to string using the given format.- Parameters:
numberFormat
- the number format to format generated number, before appending it to the generated name;String#format
style format is expected with one and only one%s
; can benull
if number formatting is not needednumber
- the number to format- Returns:
- formatted number, never
null
-