Class NameUtils
java.lang.Object
io.micronaut.core.naming.NameUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringThe camel case version of the string with the first letter in lower case.static StringThe camel case version of the string with the first letter in lower case.static Stringcapitalize(String name) Converts a property name to class name according to the JavaBean convention.static @Nullable Stringdecapitalize(@Nullable 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 StringdecapitalizeWithoutSuffix(String name, String... suffixes) Converts class name to property name using JavaBean decapitalization.static Stringdehyphenate(String name) Converts hyphenated, lower-case form to camel-case form.static StringenvironmentName(String camelCase) Returns the underscore separated version of the given camel case string.static StringRetrieves the extension of a file name.static StringRetrieves the fileName of a file without extension.static StringgetPackageName(String className) Returns the package name for a class represented as string.static StringgetPropertyNameForGetter(String getterName) Get the equivalent property name for the given getter.static StringgetPropertyNameForGetter(String getterName, String readPrefix) Get the equivalent property name for the given getter and read prefix.static StringgetPropertyNameForGetter(String getterName, String[] readPrefixes) Get the equivalent property name for the given getter and read prefixes.static StringgetPropertyNameForSetter(String setterName) Get the equivalent property name for the given setter.static StringgetPropertyNameForSetter(String setterName, String writePrefix) Get the equivalent property name for the given setter and write prefix.static StringgetPropertyNameForSetter(String setterName, String[] writePrefixes) Get the equivalent property name for the given setter and write prefixes.static StringgetShortenedName(String typeName) Returns the shortened fully-qualified name for a class represented as a string.static StringgetSimpleName(String className) Returns the simple name for a class represented as string.static StringgetterNameFor(String propertyName) Get the equivalent getter name for the given property.static StringgetterNameFor(String propertyName, boolean isBoolean) Get the equivalent getter name for the given property.static StringgetterNameFor(String propertyName, Class<?> type) Get the equivalent getter name for the given property.static StringgetterNameFor(String propertyName, String prefix) Get the equivalent getter name for the given property and a prefix.static StringgetterNameFor(String propertyName, String[] prefixes) Get the equivalent getter name for the given property and the first prefix.static StringConverts camel case to hyphenated, lowercase form.static StringConverts camel case to hyphenated, lowercase form.static booleanisEnvironmentName(String str) Checks whether the string is a valid environment-style property name.static booleanisGetterName(String methodName) Is the given method name a valid getter name.static booleanisHyphenatedLowerCase(@Nullable String name) Checks whether the given name is a valid service identifier.static booleanisReaderName(String methodName, String readPrefix) Is the given method name a valid reader name.static booleanisReaderName(String methodName, String[] readPrefixes) Is the given method name a valid reader name.static booleanisSetterName(String methodName) Is the given method name a valid setter name.static booleanChecks whether the string is a valid hyphenated (kebab-case) property name.static booleanisWriterName(String methodName, String writePrefix) Is the given method name a valid writer name for the prefix.static booleanisWriterName(String methodName, String[] writePrefixes) Is the given method name a valid writer name for any of the prefixes.static StringsetterNameFor(String propertyName) Get the equivalent setter name for the given property.static StringsetterNameFor(String propertyName, String prefix) Get the equivalent setter name for the given property and a prefix.static StringsetterNameFor(String propertyName, String[] prefixes) Get the equivalent setter name for the given property and the first prefix.static StringtrimSuffix(String string, String... suffixes) Trims the given suffixes.static StringunderscoreSeparate(String camelCase) Returns the underscore separated version of the given camel case string.static StringunderscoreSeparate(String camelCase, boolean lowercase) Returns the underscore separated version of the given camel case string, optionally with lowercase result.
-
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
-
trimSuffix
-
capitalize
-
hyphenate
-
hyphenate
-
dehyphenate
-
getPackageName
-
underscoreSeparate
-
underscoreSeparate
Returns the underscore separated version of the given camel case string, optionally with lowercase result.- Parameters:
camelCase- The camel case namelowercase- true to lowercase the result- Returns:
- The underscore separated version
-
environmentName
-
getSimpleName
-
getShortenedName
Returns the shortened fully-qualified name for a class represented as a string. Shortened name would have package names and owner objects reduced to a single letter. For example,com.example.Owner$Innerwould becomec.e.O$Inner. IDEs would still be able to recognize these types, but they would take less space visually.- Parameters:
typeName- The fully-qualified type name- Returns:
- The shortened type name
- Since:
- 4.8.x
-
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
-
isWriterName
-
getPropertyNameForSetter
-
getPropertyNameForSetter
-
getPropertyNameForSetter
-
setterNameFor
-
setterNameFor
-
setterNameFor
-
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
-
isReaderName
-
getPropertyNameForGetter
-
getPropertyNameForGetter
-
getPropertyNameForGetter
-
getterNameFor
-
getterNameFor
-
getterNameFor
-
getterNameFor
-
getterNameFor
-
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
-
camelCase
-
camelCase
-
filename
-
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
-