public class GriffonNameUtils extends Object
Constructor and Description |
---|
GriffonNameUtils() |
Modifier and Type | Method and Description |
---|---|
static String |
capitalize(String str)
Capitalizes a String (makes the first char uppercase) taking care
of blank strings and single character strings.
|
static String |
getClassName(String logicalName,
String trailingName)
Returns the class name for the given logical name and trailing name.
|
static String |
getClassNameForLowerCaseHyphenSeparatedName(String name)
Converts foo-bar into FooBar.
|
static String |
getClassNameRepresentation(String name)
Returns the class name representation of the given name
|
static String |
getGetterName(String propertyName)
Calculate the name for a getter method to retrieve the specified property
|
static String |
getHyphenatedName(Class<?> clazz)
Retrieves the hyphenated name representation of the supplied class.
|
static String |
getHyphenatedName(String name)
Retrieves the hyphenated name representation of the given class name.
|
static String |
getLogicalName(Class<?> clazz,
String trailingName)
Retrieves the logical class name of a Griffon artifact given the Griffon class
and a specified trailing name
|
static String |
getLogicalName(String name,
String trailingName)
Retrieves the logical name of the class without the trailing name
|
static String |
getLogicalPropertyName(String className,
String trailingName) |
static String |
getNaturalName(String name)
Converts a property name into its natural language equivalent eg ('firstName' becomes 'First Name')
|
static String |
getPropertyName(Class<?> clazz)
Shorter version of getPropertyNameRepresentation
|
static String |
getPropertyName(String name)
Shorter version of getPropertyNameRepresentation
|
static String |
getPropertyNameForLowerCaseHyphenSeparatedName(String name)
Converts foo-bar into fooBar
|
static String |
getPropertyNameRepresentation(Class<?> targetClass)
Returns the property name equivalent for the specified class
|
static String |
getPropertyNameRepresentation(String name)
Returns the property name representation of the given name
|
static String |
getSetterName(String propertyName)
Retrieves the name of a setter for the specified property name
|
static String |
getShortName(Class<?> targetClass)
Returns the class name without the package prefix
|
static String |
getShortName(String className)
Returns the class name without the package prefix
|
static boolean |
isBlank(String str)
Determines whether a given string is
null , empty,
or only contains whitespace. |
static boolean |
isKeyword(String str)
Finds out if the given String is a Java/Groovy keyword.
|
static String |
join(Iterable<?> self,
String separator)
Concatenates the
toString() representation of each
item in this Iterable, with the given String as a separator between each item. |
static String |
quote(String str)
Applies single or double quotes to a string if it contains whitespace characters
|
static String |
requireNonBlank(String str)
Checks that the specified String is not
blank . |
static String |
requireNonBlank(String str,
String message)
Checks that the specified String is not
blank and
throws a customized IllegalArgumentException if it is. |
static String |
uncapitalize(String str)
Uncapitalizes a String (makes the first char lowercase) taking care
of blank strings and single character strings.
|
static String |
unquote(String str)
Removes single or double quotes from a String
|
public static boolean isKeyword(String str)
str
- The String to testpublic static String capitalize(String str)
str
- The String to be capitalizedpublic static String uncapitalize(String str)
str
- The String to be uncapitalizedpublic static String getSetterName(String propertyName)
propertyName
- The property namepublic static String getGetterName(String propertyName)
propertyName
- The property namepublic static String getClassName(String logicalName, String trailingName)
logicalName
- The logical nametrailingName
- The trailing namepublic static String getClassNameRepresentation(String name)
name
- The name to convertpublic static String getClassNameForLowerCaseHyphenSeparatedName(String name)
name
- The lower case hyphen separated namepublic static String getLogicalName(Class<?> clazz, String trailingName)
clazz
- The classtrailingName
- The trailing name such as "Controller" or "TagLib"public static String getLogicalName(String name, String trailingName)
name
- The name of the classtrailingName
- The trailing namepublic static String getLogicalPropertyName(String className, String trailingName)
public static String getPropertyName(String name)
name
- The name to convertpublic static String getPropertyName(Class<?> clazz)
clazz
- The clazz to convertpublic static String getPropertyNameRepresentation(Class<?> targetClass)
targetClass
- The class to get the property name forpublic static String getPropertyNameRepresentation(String name)
name
- The name to convertpublic static String getPropertyNameForLowerCaseHyphenSeparatedName(String name)
name
- The lower case hyphen separated namepublic static String getShortName(Class<?> targetClass)
targetClass
- The class to get a short name forpublic static String getShortName(String className)
className
- The class name to get a short name forpublic static String getNaturalName(String name)
name
- The property name to convertpublic static boolean isBlank(String str)
Determines whether a given string is null
, empty,
or only contains whitespace. If it contains anything other than
whitespace then the string is not considered to be blank and the
method returns false
.
We could use Commons Lang for this, but we don't want GriffonNameUtils to have a dependency on any external library to minimise the number of dependencies required to bootstrap Griffon.
str
- The string to test.true
if the string is null
, or
blank.public static String requireNonBlank(String str)
blank
. This
method is designed primarily for doing parameter validation in methods
and constructors, as demonstrated below:
public Foo(String str) { this.str = GriffonNameUtils.requireNonBlank(str); }
str
- the String to check for blankstr
if not blank
IllegalArgumentException
- if str
is blank
public static String requireNonBlank(String str, String message)
blank
and
throws a customized IllegalArgumentException
if it is. This method
is designed primarily for doing parameter validation in methods and
constructors with multiple parameters, as demonstrated below:
public Foo(String str) { this.str = GriffonNameUtils.requireNonBlank(str, "str must not be null"); }
str
- the String to check for blankmessage
- detail message to be used in the event that a IllegalArgumentException
is thrownstr
if not blank
IllegalArgumentException
- if str
is blank
public static String getHyphenatedName(Class<?> clazz)
clazz
- The class to convertpublic static String getHyphenatedName(String name)
name
- The class name to convert.@Nonnull public static String join(@Nonnull Iterable<?> self, @Nullable String separator)
toString()
representation of each
item in this Iterable, with the given String as a separator between each item.self
- an Iterable of objectsseparator
- a String separatorpublic static String quote(String str)
str
- the String to be surrounded by quotes