public class NameUtils extends Object
Naming convention utilities.
Constructor and Description |
---|
NameUtils() |
Modifier and Type | Method and Description |
---|---|
static String |
camelCase(String str)
The camel case version of the string with the first letter in lower case.
|
static String |
camelCase(String str,
boolean lowerCaseFirstLetter)
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 |
extension(String filename)
Retrieves the extension of a file name.
|
static String |
filename(String path)
Retrieves the fileName of a file without extension.
|
static String |
getPackageName(String className)
Returns the package name for a class represented as string.
|
static String |
getPropertyNameForGetter(String getterName)
Get the equivalent property name for the given getter.
|
static String |
getPropertyNameForGetter(String getterName,
String readPrefix)
Get the equivalent property name for the given getter and read prefix.
|
static String |
getPropertyNameForGetter(String getterName,
String[] readPrefixes)
Get the equivalent property name for the given getter and read prefixes.
|
static String |
getPropertyNameForSetter(String setterName)
Get the equivalent property name for the given setter.
|
static String |
getPropertyNameForSetter(String setterName,
String writePrefix)
Get the equivalent property name for the given setter and write prefix.
|
static String |
getPropertyNameForSetter(String setterName,
String[] writePrefixes)
Get the equivalent property name for the given setter and write prefixes.
|
static String |
getSimpleName(String className)
Returns the simple name for a class represented as string.
|
static String |
getterNameFor(String propertyName)
Get the equivalent getter name for the given property.
|
static String |
getterNameFor(String propertyName,
boolean isBoolean)
Get the equivalent getter name for the given property.
|
static String |
getterNameFor(String propertyName,
Class<?> type)
Get the equivalent getter name for the given property.
|
static String |
getterNameFor(String propertyName,
String prefix)
Get the equivalent getter name for the given property and a prefix.
|
static String |
getterNameFor(String propertyName,
String[] prefixes)
Get the equivalent getter name for the given property and a the first prefix.
|
static String |
hyphenate(String name)
Converts camel case to hyphenated, lowercase form.
|
static String |
hyphenate(String name,
boolean lowerCase)
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(String methodName,
String readPrefix)
Is the given method name a valid reader name.
|
static boolean |
isReaderName(String methodName,
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 |
isValidHyphenatedPropertyName(String str)
Checks whether the string is a valid hyphenated (kebab-case) property name.
|
static boolean |
isWriterName(String methodName,
String writePrefix)
Is the given method name a valid writer name for the prefix.
|
static boolean |
isWriterName(String methodName,
String[] writePrefixes)
Is the given method name a valid writer name for any of the prefixes.
|
static String |
setterNameFor(String propertyName)
Get the equivalent setter name for the given property.
|
static String |
setterNameFor(String propertyName,
String prefix)
Get the equivalent setter name for the given property and a prefix.
|
static String |
setterNameFor(String propertyName,
String[] prefixes)
Get the equivalent setter name for the given property and a 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.
|
public static boolean isHyphenatedLowerCase(String name)
name
- The namepublic static String decapitalizeWithoutSuffix(String name, String... suffixes)
name
- The class namesuffixes
- The suffix to removepublic static String trimSuffix(String string, String... suffixes)
string
- The string to trimsuffixes
- The suffixespublic static String capitalize(String name)
name
- The property namepublic static String hyphenate(String name)
name
- The namepublic static String hyphenate(String name, boolean lowerCase)
name
- The namelowerCase
- Whether the result should be converted to lower casepublic static String dehyphenate(String name)
name
- The hyphenated stringpublic static String getPackageName(String className)
className
- The class namepublic static String underscoreSeparate(String camelCase)
camelCase
- The camel case namepublic static String environmentName(String camelCase)
camelCase
- The camel case namepublic static String getSimpleName(String className)
className
- The class namepublic static boolean isSetterName(String methodName)
methodName
- The method namepublic static boolean isWriterName(@NonNull String methodName, @NonNull String writePrefix)
methodName
- The method namewritePrefix
- The write prefixpublic static boolean isWriterName(@NonNull String methodName, @NonNull String[] writePrefixes)
methodName
- The method namewritePrefixes
- The write prefixespublic static String getPropertyNameForSetter(String setterName)
setterName
- The setter@NonNull public static String getPropertyNameForSetter(@NonNull String setterName, @NonNull String writePrefix)
setterName
- The setter namewritePrefix
- The write prefix@NonNull public static String getPropertyNameForSetter(@NonNull String setterName, @NonNull String[] writePrefixes)
setterName
- The setter namewritePrefixes
- The write prefixes@NonNull public static String setterNameFor(@NonNull String propertyName)
propertyName
- The property name@NonNull public static String setterNameFor(@NonNull String propertyName, @NonNull String[] prefixes)
propertyName
- The property nameprefixes
- The prefixes@NonNull public static String setterNameFor(@NonNull String propertyName, @NonNull String prefix)
propertyName
- The property nameprefix
- The prefixpublic static boolean isGetterName(String methodName)
methodName
- The method namepublic static boolean isReaderName(@NonNull String methodName, @NonNull String readPrefix)
methodName
- The method namereadPrefix
- The read prefixpublic static boolean isReaderName(@NonNull String methodName, @NonNull String[] readPrefixes)
methodName
- The method namereadPrefixes
- The valid read prefixespublic static String getPropertyNameForGetter(String getterName)
getterName
- The getter@NonNull public static String getPropertyNameForGetter(@NonNull String getterName, @NonNull String readPrefix)
getterName
- The getterreadPrefix
- The read prefix@NonNull public static String getPropertyNameForGetter(@NonNull String getterName, @NonNull String[] readPrefixes)
getterName
- The getterreadPrefixes
- The read prefixes@NonNull public static String getterNameFor(@NonNull String propertyName)
propertyName
- The property name@NonNull public static String getterNameFor(@NonNull String propertyName, @NonNull String[] prefixes)
propertyName
- The property nameprefixes
- The prefixes@NonNull public static String getterNameFor(@NonNull String propertyName, @NonNull String prefix)
propertyName
- The property nameprefix
- The prefix@NonNull public static String getterNameFor(@NonNull String propertyName, @NonNull Class<?> type)
propertyName
- The property nametype
- The type of the propertypublic static String getterNameFor(@NonNull String propertyName, boolean isBoolean)
propertyName
- The property nameisBoolean
- Is the property a booleanpublic static String decapitalize(String name)
name
- The String to decapitalizepublic static String extension(String filename)
filename
- The name of the filepublic static String camelCase(String str)
str
- The stringpublic static String camelCase(String str, boolean lowerCaseFirstLetter)
str
- The stringlowerCaseFirstLetter
- Whether the first letter is in upper case or lower casepublic static String filename(String path)
path
- The path of the filepublic static boolean isValidHyphenatedPropertyName(String str)
str
- The string to checkpublic static boolean isEnvironmentName(String str)
str
- The string to check