java.lang.Object
org.kordamp.jarviz.util.StringUtils
- Since:
- 0.1.0
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static StringapplyQuotes(String string) static Stringcapitalize(String str) Capitalizes a String (makes the first char uppercase) taking care of blank strings and single character strings.private static Stringescape(char character) static StringescapeRegexChars(String str) static StringgetCapitalizedName(String name) Converts foo-bar into Foo Bar.static StringgetClassName(String logicalName, String trailingName) Returns the class name for the given logical name and trailing name.static StringConverts foo-bar into FooBar.static StringReturns the class name representation of the given namestatic StringgetFilename(String path) static StringgetFilename(String path, Collection<String> extensions) static StringgetFilenameExtension(String path) static StringgetGetterName(String propertyName) Calculate the name for a getter method to retrieve the specified propertystatic StringgetHyphenatedName(Class<?> clazz) Retrieves the hyphenated name representation of the supplied class.static StringgetHyphenatedName(String name) Retrieves the hyphenated name representation of the given class name.static StringgetLogicalName(Class<?> clazz, String trailingName) Retrieves the logical class name of a Griffon artifact given the Griffon class and a specified trailing namestatic StringgetLogicalName(String name, String trailingName) Retrieves the logical name of the class without the trailing namestatic StringgetLogicalPropertyName(String className, String trailingName) static StringgetNaturalName(String name) Converts a property name into its natural language equivalent eg ('firstName' becomes 'First Name')private static StringgetPadding(String padding, int length) static StringgetPropertyName(Class<?> clazz) Shorter version of getPropertyNameRepresentationstatic StringgetPropertyName(Method method) Returns the property name representation of the givenMethodstatic StringgetPropertyName(String name) Shorter version of getPropertyNameRepresentationstatic StringConverts foo-bar into fooBarstatic StringgetPropertyNameRepresentation(Class<?> targetClass) Returns the property name equivalent for the specified classstatic StringReturns the property name representation of the given namestatic StringgetSetterName(String propertyName) Retrieves the name of a setter for the specified property namestatic StringgetShortName(Class<?> targetClass) Returns the class name without the package prefixstatic StringgetShortName(String className) Returns the class name without the package prefixstatic booleanDetermines whether a given string isnull, empty, or only contains whitespace.static booleanstatic booleanisNotBlank(String str) Determines whether a given string is notnull, empty, or only contains whitespace.static booleanstatic Stringstatic Stringstatic Stringstatic Stringstatic Stringstatic StringApplies single or double quotes to a string if it contains whitespace charactersstatic StringrequireNonBlank(String str) Checks that the specified String is notblank.static StringrequireNonBlank(String str, String message) Checks that the specified String is notblankand throws a customizedIllegalArgumentExceptionif it is.static ObjectsplitValue(String value) static StringstripMargin(String str) static Stringstatic PatterntoSafePattern(String str) static StringtoSafeRegexPattern(String str) static Stringuncapitalize(String str) Uncapitalizes a String (makes the first char lowercase) taking care of blank strings and single character strings.static StringRemoves single or double quotes from a String
-
Field Details
-
PROPERTY_SET_PREFIX
- See Also:
-
PROPERTY_GET_PREFIX
- See Also:
-
GETTER_PATTERN_1
-
GETTER_PATTERN_2
-
SETTER_PATTERN
-
ERROR_METHOD_NULL
- See Also:
-
REGEX_CHARS
-
-
Constructor Details
-
StringUtils
public StringUtils()
-
-
Method Details
-
capitalize
Capitalizes a String (makes the first char uppercase) taking care of blank strings and single character strings.- Parameters:
str- The String to be capitalized- Returns:
- Capitalized version of the target string if it is not blank
-
getFilenameExtension
-
getFilename
-
getFilename
-
getSetterName
Retrieves the name of a setter for the specified property name- Parameters:
propertyName- The property name- Returns:
- The setter equivalent
-
getGetterName
Calculate the name for a getter method to retrieve the specified property- Parameters:
propertyName- The property name- Returns:
- The name for the getter method for this property, if it were to exist, i.e. getConstraints
-
getClassName
Returns the class name for the given logical name and trailing name. For example "person" and "Controller" would evaluate to "PersonController"- Parameters:
logicalName- The logical nametrailingName- The trailing name- Returns:
- The class name
-
getClassNameRepresentation
Returns the class name representation of the given name- Parameters:
name- The name to convert- Returns:
- The property name representation
-
getClassNameForLowerCaseHyphenSeparatedName
Converts foo-bar into FooBar. Empty and null strings are returned as-is.- Parameters:
name- The lower case hyphen separated name- Returns:
- The class name equivalent.
-
getCapitalizedName
Converts foo-bar into Foo Bar. Empty and null strings are returned as-is.- Parameters:
name- The lower case hyphen separated name- Returns:
- The capitalized name equivalent.
-
getLogicalName
Retrieves the logical class name of a Griffon artifact given the Griffon class and a specified trailing name- Parameters:
clazz- The classtrailingName- The trailing name such as "Controller" or "TagLib"- Returns:
- The logical class name
-
getLogicalName
Retrieves the logical name of the class without the trailing name- Parameters:
name- The name of the classtrailingName- The trailing name- Returns:
- The logical name
-
getLogicalPropertyName
-
getPropertyName
Shorter version of getPropertyNameRepresentation- Parameters:
name- The name to convert- Returns:
- The property name version
-
getPropertyName
Shorter version of getPropertyNameRepresentation- Parameters:
clazz- The clazz to convert- Returns:
- The property name version
-
getPropertyName
Returns the property name representation of the givenMethod- Parameters:
method- The method to inspect- Returns:
- The property name representation
- Since:
- 3.0.0
-
getPropertyNameRepresentation
Returns the property name equivalent for the specified class- Parameters:
targetClass- The class to get the property name for- Returns:
- A property name representation of the class name (eg. MyClass becomes myClass)
-
getPropertyNameRepresentation
Returns the property name representation of the given name- Parameters:
name- The name to convert- Returns:
- The property name representation
-
getPropertyNameForLowerCaseHyphenSeparatedName
Converts foo-bar into fooBar- Parameters:
name- The lower case hyphen separated name- Returns:
- The property name equivalent
-
getShortName
Returns the class name without the package prefix- Parameters:
targetClass- The class to get a short name for- Returns:
- The short name of the class
-
getShortName
Returns the class name without the package prefix- Parameters:
className- The class name to get a short name for- Returns:
- The short name of the class
-
getNaturalName
Converts a property name into its natural language equivalent eg ('firstName' becomes 'First Name')- Parameters:
name- The property name to convert- Returns:
- The converted property name
-
isBlank
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 returnsfalse.- Parameters:
str- The string to test.- Returns:
trueif the string isnull, or blank.
-
isNotBlank
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 returnstrue.- Parameters:
str- The string to test.- Returns:
trueif the string is notnull, nor blank.
-
requireNonBlank
Checks that the specified String is notblank. This method is designed primarily for doing parameter validation in methods and constructors, as demonstrated below:Foo(String str) {* this.str = GriffonNameUtils.requireNonBlank(str) }*- Parameters:
str- the String to check for blank- Returns:
strif notblank- Throws:
IllegalArgumentException- ifstrisblank
-
requireNonBlank
Checks that the specified String is notblankand throws a customizedIllegalArgumentExceptionif 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") }*- Parameters:
str- the String to check for blankmessage- detail message to be used in the event that aIllegalArgumentExceptionis thrown- Returns:
strif notblank- Throws:
IllegalArgumentException- ifstrisblank
-
getHyphenatedName
Retrieves the hyphenated name representation of the supplied class. For example MyFunkyGriffonThingy would be my-funky-griffon-thingy.- Parameters:
clazz- The class to convert- Returns:
- The hyphenated name representation
-
getHyphenatedName
Retrieves the hyphenated name representation of the given class name. For example MyFunkyGriffonThingy would be my-funky-griffon-thingy.- Parameters:
name- The class name to convert.- Returns:
- The hyphenated name representation.
-
uncapitalize
Uncapitalizes a String (makes the first char lowercase) taking care of blank strings and single character strings.- Parameters:
str- The String to be uncapitalized- Returns:
- Uncapitalized version of the target string if it is not blank
-
splitValue
-
escape
-
padLeft
-
padLeft
-
padRight
-
padRight
-
getPadding
-
times
-
stripMargin
-
escapeRegexChars
-
toSafeRegexPattern
-
normalizeRegexPattern
-
toSafePattern
-
isTrue
-
isFalse
-
quote
Applies single or double quotes to a string if it contains whitespace characters- Parameters:
str- the String to be surrounded by quotes- Returns:
- a copy of the original String, surrounded by quotes
-
unquote
Removes single or double quotes from a String- Parameters:
str- the String from which quotes will be removed- Returns:
- the unquoted String
-
applyQuotes
-