@CompileStatic class StringUtils extends Object
Constructor and description |
---|
StringUtils
() |
Type Params | Return Type | Name 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 |
getFilenameExtension(String path) |
|
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(String name) Shorter version of getPropertyNameRepresentation |
|
static String |
getPropertyName(Class<?> clazz) Shorter version of getPropertyNameRepresentation |
|
static String |
getPropertyName(Method method) Returns the property name representation of the given Method |
|
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) |
|
static boolean |
isNotBlank(String str) |
|
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 |
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. |
Capitalizes a String (makes the first char uppercase) taking care of blank strings and single character strings.
str
- The String to be capitalizedReturns the class name for the given logical name and trailing name. For example "person" and "Controller" would evaluate to "PersonController"
logicalName
- The logical nametrailingName
- The trailing nameConverts foo-bar into FooBar. Empty and null strings are returned as-is.
name
- The lower case hyphen separated nameReturns the class name representation of the given name
name
- The name to convertCalculate the name for a getter method to retrieve the specified property
propertyName
- The property nameRetrieves the hyphenated name representation of the supplied class. For example MyFunkyGriffonThingy would be my-funky-griffon-thingy.
clazz
- The class to convertRetrieves the hyphenated name representation of the given class name. For example MyFunkyGriffonThingy would be my-funky-griffon-thingy.
name
- The class name to convert.Retrieves the logical class name of a Griffon artifact given the Griffon class and a specified trailing name
clazz
- The classtrailingName
- The trailing name such as "Controller" or "TagLib"Retrieves the logical name of the class without the trailing name
name
- The name of the classtrailingName
- The trailing nameConverts a property name into its natural language equivalent eg ('firstName' becomes 'First Name')
name
- The property name to convertShorter version of getPropertyNameRepresentation
name
- The name to convertShorter version of getPropertyNameRepresentation
clazz
- The clazz to convert Returns the property name representation of the given Method
method
- The method to inspectConverts foo-bar into fooBar
name
- The lower case hyphen separated nameReturns the property name equivalent for the specified class
targetClass
- The class to get the property name forReturns the property name representation of the given name
name
- The name to convertRetrieves the name of a setter for the specified property name
propertyName
- The property nameReturns the class name without the package prefix
targetClass
- The class to get a short name forReturns the class name without the package prefix
className
- The class name to get a short name for
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
.
str
- The string to test. true
if the string is null
, or
blank.
Determines whether a given string is not 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 true
.
str
- The string to test. true
if the string is not null
, nor
blank. Concatenates the 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 separator Checks that the specified String is not blank
. This
method is designed primarily for doing parameter validation in methods
and constructors, as demonstrated below:
Foo(String str) {* this.str = GriffonNameUtils.requireNonBlank(str) }*
str
is blank
str
- the String to check for blankstr
if not blank
Checks that the specified String is not 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:
Foo(String str) {* this.str = GriffonNameUtils.requireNonBlank(str, "str must not be null") }*
str
is blank
str
- the String to check for blankmessage
- detail message to be used in the event that a IllegalArgumentException
is thrownstr
if not blank