Package io.micronaut.core.naming
Class NameUtils
java.lang.Object
io.micronaut.core.naming.NameUtils
Naming convention utilities.
- Since:
- 1.0
- Author:
- Graeme Rocher
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
The camel case version of the string with the first letter in lower case.static String
The camel case version of the string with the first letter in lower case.static String
capitalize
(String name) Converts a property name to class name according to the JavaBean convention.static String
decapitalize
(String name) Decapitalizes a given string according to the rule: If the first or only character is Upper Case, it is made Lower Case UNLESS the second character is also Upper Case, when the String is returned unchanged.static String
decapitalizeWithoutSuffix
(String name, String... suffixes) Converts class name to property name using JavaBean decapitalization.static String
dehyphenate
(String name) Converts hyphenated, lower-case form to camel-case form.static String
environmentName
(String camelCase) Returns the underscore separated version of the given camel case string.static String
Retrieves the extension of a file name.static String
Retrieves the fileName of a file without extension.static String
getPackageName
(String className) Returns the package name for a class represented as string.getPropertyNameForGetter
(@NonNull String getterName, @NonNull String readPrefix) Get the equivalent property name for the given getter and read prefix.getPropertyNameForGetter
(@NonNull String getterName, @NonNull String[] readPrefixes) Get the equivalent property name for the given getter and read prefixes.static String
getPropertyNameForGetter
(String getterName) Get the equivalent property name for the given getter.getPropertyNameForSetter
(@NonNull String setterName, @NonNull String writePrefix) Get the equivalent property name for the given setter and write prefix.getPropertyNameForSetter
(@NonNull String setterName, @NonNull String[] writePrefixes) Get the equivalent property name for the given setter and write prefixes.static String
getPropertyNameForSetter
(String setterName) Get the equivalent property name for the given setter.static String
getSimpleName
(String className) Returns the simple name for a class represented as string.getterNameFor
(@NonNull String propertyName) Get the equivalent getter name for the given property.static String
getterNameFor
(@NonNull String propertyName, boolean isBoolean) Get the equivalent getter name for the given property.getterNameFor
(@NonNull String propertyName, @NonNull Class<?> type) Get the equivalent getter name for the given property.getterNameFor
(@NonNull String propertyName, @NonNull String prefix) Get the equivalent getter name for the given property and a prefix.getterNameFor
(@NonNull String propertyName, @NonNull String[] prefixes) Get the equivalent getter name for the given property and the first prefix.static String
Converts camel case to hyphenated, lowercase form.static String
Converts camel case to hyphenated, lowercase form.static boolean
isEnvironmentName
(String str) Checks whether the string is a valid environment-style property name.static boolean
isGetterName
(String methodName) Is the given method name a valid getter name.static boolean
isHyphenatedLowerCase
(String name) Checks whether the given name is a valid service identifier.static boolean
isReaderName
(@NonNull String methodName, @NonNull String readPrefix) Is the given method name a valid reader name.static boolean
isReaderName
(@NonNull String methodName, @NonNull String[] readPrefixes) Is the given method name a valid reader name.static boolean
isSetterName
(String methodName) Is the given method name a valid setter name.static boolean
Checks whether the string is a valid hyphenated (kebab-case) property name.static boolean
isWriterName
(@NonNull String methodName, @NonNull String writePrefix) Is the given method name a valid writer name for the prefix.static boolean
isWriterName
(@NonNull String methodName, @NonNull String[] writePrefixes) Is the given method name a valid writer name for any of the prefixes.setterNameFor
(@NonNull String propertyName) Get the equivalent setter name for the given property.setterNameFor
(@NonNull String propertyName, @NonNull String prefix) Get the equivalent setter name for the given property and a prefix.setterNameFor
(@NonNull String propertyName, @NonNull String[] prefixes) Get the equivalent setter name for the given property and the first prefix.static String
trimSuffix
(String string, String... suffixes) Trims the given suffixes.static String
underscoreSeparate
(String camelCase) Returns the underscore separated version of the given camel case string.
-
Constructor Details
-
NameUtils
public NameUtils()
-
-
Method Details
-
isHyphenatedLowerCase
Checks whether the given name is a valid service identifier.- Parameters:
name
- The name- Returns:
- True if it is
-
decapitalizeWithoutSuffix
Converts class name to property name using JavaBean decapitalization.- Parameters:
name
- The class namesuffixes
- The suffix to remove- Returns:
- The decapitalized name
-
trimSuffix
Trims the given suffixes.- Parameters:
string
- The string to trimsuffixes
- The suffixes- Returns:
- The trimmed string
-
capitalize
Converts a property name to class name according to the JavaBean convention.- Parameters:
name
- The property name- Returns:
- The class name
-
hyphenate
Converts camel case to hyphenated, lowercase form.- Parameters:
name
- The name- Returns:
- The hyphenated string
-
hyphenate
Converts camel case to hyphenated, lowercase form.- Parameters:
name
- The namelowerCase
- Whether the result should be converted to lower case- Returns:
- The hyphenated string
-
dehyphenate
Converts hyphenated, lower-case form to camel-case form.- Parameters:
name
- The hyphenated string- Returns:
- The camel case form
-
getPackageName
Returns the package name for a class represented as string.- Parameters:
className
- The class name- Returns:
- The package name
-
underscoreSeparate
Returns the underscore separated version of the given camel case string.- Parameters:
camelCase
- The camel case name- Returns:
- The underscore separated version
-
environmentName
Returns the underscore separated version of the given camel case string.- Parameters:
camelCase
- The camel case name- Returns:
- The underscore separated version
-
getSimpleName
Returns the simple name for a class represented as string.- Parameters:
className
- The class name- Returns:
- The simple name of the class
-
isSetterName
Is the given method name a valid setter name.- Parameters:
methodName
- The method name- Returns:
- True if it is a valid setter name
-
isWriterName
public static boolean isWriterName(@NonNull @NonNull String methodName, @NonNull @NonNull String writePrefix) Is the given method name a valid writer name for the prefix.- Parameters:
methodName
- The method namewritePrefix
- The write prefix- Returns:
- True if it is a valid writer name
- Since:
- 3.3.0
-
isWriterName
public static boolean isWriterName(@NonNull @NonNull String methodName, @NonNull @NonNull String[] writePrefixes) Is the given method name a valid writer name for any of the prefixes.- Parameters:
methodName
- The method namewritePrefixes
- The write prefixes- Returns:
- True if it is a valid writer name
- Since:
- 3.3.0
-
getPropertyNameForSetter
Get the equivalent property name for the given setter.- Parameters:
setterName
- The setter- Returns:
- The property name
-
getPropertyNameForSetter
@NonNull public static @NonNull String getPropertyNameForSetter(@NonNull @NonNull String setterName, @NonNull @NonNull String writePrefix) Get the equivalent property name for the given setter and write prefix.- Parameters:
setterName
- The setter namewritePrefix
- The write prefix- Returns:
- The property name
- Since:
- 3.3.0
-
getPropertyNameForSetter
@NonNull public static @NonNull String getPropertyNameForSetter(@NonNull @NonNull String setterName, @NonNull @NonNull String[] writePrefixes) Get the equivalent property name for the given setter and write prefixes.- Parameters:
setterName
- The setter namewritePrefixes
- The write prefixes- Returns:
- The property name
- Since:
- 3.3.0
-
setterNameFor
Get the equivalent setter name for the given property.- Parameters:
propertyName
- The property name- Returns:
- The setter name
-
setterNameFor
@NonNull public static @NonNull String setterNameFor(@NonNull @NonNull String propertyName, @NonNull @NonNull String[] prefixes) Get the equivalent setter name for the given property and the first prefix.- Parameters:
propertyName
- The property nameprefixes
- The prefixes- Returns:
- The setter name for the first prefix
- Since:
- 3.3.0
-
setterNameFor
@NonNull public static @NonNull String setterNameFor(@NonNull @NonNull String propertyName, @NonNull @NonNull String prefix) Get the equivalent setter name for the given property and a prefix.- Parameters:
propertyName
- The property nameprefix
- The prefix- Returns:
- The setter name
- Since:
- 3.3.0
-
isGetterName
Is the given method name a valid getter name.- Parameters:
methodName
- The method name- Returns:
- True if it is a valid getter name
-
isReaderName
public static boolean isReaderName(@NonNull @NonNull String methodName, @NonNull @NonNull String readPrefix) Is the given method name a valid reader name.- Parameters:
methodName
- The method namereadPrefix
- The read prefix- Returns:
- True if it is a valid read name
- Since:
- 3.3.0
-
isReaderName
public static boolean isReaderName(@NonNull @NonNull String methodName, @NonNull @NonNull String[] readPrefixes) Is the given method name a valid reader name.- Parameters:
methodName
- The method namereadPrefixes
- The valid read prefixes- Returns:
- True if it is a valid reader name
- Since:
- 3.3.0
-
getPropertyNameForGetter
Get the equivalent property name for the given getter.- Parameters:
getterName
- The getter- Returns:
- The property name
-
getPropertyNameForGetter
@NonNull public static @NonNull String getPropertyNameForGetter(@NonNull @NonNull String getterName, @NonNull @NonNull String readPrefix) Get the equivalent property name for the given getter and read prefix.- Parameters:
getterName
- The getterreadPrefix
- The read prefix- Returns:
- The property name
- Since:
- 3.3.0
-
getPropertyNameForGetter
@NonNull public static @NonNull String getPropertyNameForGetter(@NonNull @NonNull String getterName, @NonNull @NonNull String[] readPrefixes) Get the equivalent property name for the given getter and read prefixes.- Parameters:
getterName
- The getterreadPrefixes
- The read prefixes- Returns:
- The property name
- Since:
- 3.3.0
-
getterNameFor
Get the equivalent getter name for the given property.- Parameters:
propertyName
- The property name- Returns:
- The getter name
-
getterNameFor
@NonNull public static @NonNull String getterNameFor(@NonNull @NonNull String propertyName, @NonNull @NonNull String[] prefixes) Get the equivalent getter name for the given property and the first prefix.- Parameters:
propertyName
- The property nameprefixes
- The prefixes- Returns:
- The getter name for the first prefix
- Since:
- 3.3.0
-
getterNameFor
@NonNull public static @NonNull String getterNameFor(@NonNull @NonNull String propertyName, @NonNull @NonNull String prefix) Get the equivalent getter name for the given property and a prefix.- Parameters:
propertyName
- The property nameprefix
- The prefix- Returns:
- The getter name for the prefix
- Since:
- 3.3.0
-
getterNameFor
@NonNull public static @NonNull String getterNameFor(@NonNull @NonNull String propertyName, @NonNull @NonNull Class<?> type) Get the equivalent getter name for the given property.- Parameters:
propertyName
- The property nametype
- The type of the property- Returns:
- The getter name
-
getterNameFor
Get the equivalent getter name for the given property.- Parameters:
propertyName
- The property nameisBoolean
- Is the property a boolean- Returns:
- The getter name
-
decapitalize
Decapitalizes a given string according to the rule:- If the first or only character is Upper Case, it is made Lower Case
- UNLESS the second character is also Upper Case, when the String is returned unchanged.
- Parameters:
name
- The String to decapitalize- Returns:
- The decapitalized version of the String
-
extension
Retrieves the extension of a file name. Ex: index.html -> html- Parameters:
filename
- The name of the file- Returns:
- The file extension
-
camelCase
The camel case version of the string with the first letter in lower case.- Parameters:
str
- The string- Returns:
- The new string in camel case
-
camelCase
The camel case version of the string with the first letter in lower case.- Parameters:
str
- The stringlowerCaseFirstLetter
- Whether the first letter is in upper case or lower case- Returns:
- The new string in camel case
-
filename
Retrieves the fileName of a file without extension. Ex: index.html -> index- Parameters:
path
- The path of the file- Returns:
- The file name without extension
-
isValidHyphenatedPropertyName
Checks whether the string is a valid hyphenated (kebab-case) property name.- Parameters:
str
- The string to check- Returns:
- Whether is valid kebab-case or not
-
isEnvironmentName
Checks whether the string is a valid environment-style property name.- Parameters:
str
- The string to check- Returns:
- Whether is valid environment-style property name or not
-