- java.lang.Object
-
- org.kordamp.jarviz.util.StringUtils
-
public class StringUtils extends java.lang.Object- Since:
- 0.1.0
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringERROR_METHOD_NULLprivate static java.util.regex.PatternGETTER_PATTERN_1private static java.util.regex.PatternGETTER_PATTERN_2private static java.lang.StringPROPERTY_GET_PREFIXprivate static java.lang.StringPROPERTY_SET_PREFIXprivate static java.util.regex.PatternREGEX_CHARSprivate static java.util.regex.PatternSETTER_PATTERN
-
Constructor Summary
Constructors Constructor Description StringUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static java.lang.StringapplyQuotes(java.lang.String string)static java.lang.Stringcapitalize(java.lang.String str)Capitalizes a String (makes the first char uppercase) taking care of blank strings and single character strings.private static java.lang.Stringescape(char character)static java.lang.StringescapeRegexChars(java.lang.String str)static java.lang.StringgetCapitalizedName(java.lang.String name)Converts foo-bar into Foo Bar.static java.lang.StringgetClassName(java.lang.String logicalName, java.lang.String trailingName)Returns the class name for the given logical name and trailing name.static java.lang.StringgetClassNameForLowerCaseHyphenSeparatedName(java.lang.String name)Converts foo-bar into FooBar.static java.lang.StringgetClassNameRepresentation(java.lang.String name)Returns the class name representation of the given namestatic java.lang.StringgetFilename(java.lang.String path)static java.lang.StringgetFilename(java.lang.String path, java.util.Collection<java.lang.String> extensions)static java.lang.StringgetFilenameExtension(java.lang.String path)static java.lang.StringgetGetterName(java.lang.String propertyName)Calculate the name for a getter method to retrieve the specified propertystatic java.lang.StringgetHyphenatedName(java.lang.Class<?> clazz)Retrieves the hyphenated name representation of the supplied class.static java.lang.StringgetHyphenatedName(java.lang.String name)Retrieves the hyphenated name representation of the given class name.static java.lang.StringgetLogicalName(java.lang.Class<?> clazz, java.lang.String trailingName)Retrieves the logical class name of a Griffon artifact given the Griffon class and a specified trailing namestatic java.lang.StringgetLogicalName(java.lang.String name, java.lang.String trailingName)Retrieves the logical name of the class without the trailing namestatic java.lang.StringgetLogicalPropertyName(java.lang.String className, java.lang.String trailingName)static java.lang.StringgetNaturalName(java.lang.String name)Converts a property name into its natural language equivalent eg ('firstName' becomes 'First Name')private static java.lang.StringgetPadding(java.lang.String padding, int length)static java.lang.StringgetPropertyName(java.lang.Class<?> clazz)Shorter version of getPropertyNameRepresentationstatic java.lang.StringgetPropertyName(java.lang.reflect.Method method)Returns the property name representation of the givenMethodstatic java.lang.StringgetPropertyName(java.lang.String name)Shorter version of getPropertyNameRepresentationstatic java.lang.StringgetPropertyNameForLowerCaseHyphenSeparatedName(java.lang.String name)Converts foo-bar into fooBarstatic java.lang.StringgetPropertyNameRepresentation(java.lang.Class<?> targetClass)Returns the property name equivalent for the specified classstatic java.lang.StringgetPropertyNameRepresentation(java.lang.String name)Returns the property name representation of the given namestatic java.lang.StringgetSetterName(java.lang.String propertyName)Retrieves the name of a setter for the specified property namestatic java.lang.StringgetShortName(java.lang.Class<?> targetClass)Returns the class name without the package prefixstatic java.lang.StringgetShortName(java.lang.String className)Returns the class name without the package prefixstatic booleanisBlank(java.lang.String str)Determines whether a given string isnull, empty, or only contains whitespace.static booleanisFalse(java.lang.Object o)static booleanisNotBlank(java.lang.String str)Determines whether a given string is notnull, empty, or only contains whitespace.static booleanisTrue(java.lang.Object o)static java.lang.StringnormalizeRegexPattern(java.lang.String str)static java.lang.StringpadLeft(java.lang.String str, int numChars)static java.lang.StringpadLeft(java.lang.String str, int numChars, java.lang.String padding)static java.lang.StringpadRight(java.lang.String str, int numChars)static java.lang.StringpadRight(java.lang.String str, int numChars, java.lang.String padding)static java.lang.Stringquote(java.lang.String str)Applies single or double quotes to a string if it contains whitespace charactersstatic java.lang.StringrequireNonBlank(java.lang.String str)Checks that the specified String is notblank.static java.lang.StringrequireNonBlank(java.lang.String str, java.lang.String message)Checks that the specified String is notblankand throws a customizedIllegalArgumentExceptionif it is.static java.lang.ObjectsplitValue(java.lang.String value)static java.lang.StringstripMargin(java.lang.String str)static java.lang.Stringtimes(java.lang.String str, int num)static java.util.regex.PatterntoSafePattern(java.lang.String str)static java.lang.StringtoSafeRegexPattern(java.lang.String str)static java.lang.Stringuncapitalize(java.lang.String str)Uncapitalizes a String (makes the first char lowercase) taking care of blank strings and single character strings.static java.lang.Stringunquote(java.lang.String str)Removes single or double quotes from a String
-
-
-
Field Detail
-
PROPERTY_SET_PREFIX
private static final java.lang.String PROPERTY_SET_PREFIX
- See Also:
- Constant Field Values
-
PROPERTY_GET_PREFIX
private static final java.lang.String PROPERTY_GET_PREFIX
- See Also:
- Constant Field Values
-
GETTER_PATTERN_1
private static final java.util.regex.Pattern GETTER_PATTERN_1
-
GETTER_PATTERN_2
private static final java.util.regex.Pattern GETTER_PATTERN_2
-
SETTER_PATTERN
private static final java.util.regex.Pattern SETTER_PATTERN
-
ERROR_METHOD_NULL
private static final java.lang.String ERROR_METHOD_NULL
- See Also:
- Constant Field Values
-
REGEX_CHARS
private static final java.util.regex.Pattern REGEX_CHARS
-
-
Method Detail
-
capitalize
public static java.lang.String capitalize(java.lang.String str)
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
public static java.lang.String getFilenameExtension(java.lang.String path)
-
getFilename
public static java.lang.String getFilename(java.lang.String path)
-
getFilename
public static java.lang.String getFilename(java.lang.String path, java.util.Collection<java.lang.String> extensions)
-
getSetterName
public static java.lang.String getSetterName(java.lang.String propertyName)
Retrieves the name of a setter for the specified property name- Parameters:
propertyName- The property name- Returns:
- The setter equivalent
-
getGetterName
public static java.lang.String getGetterName(java.lang.String propertyName)
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
public static java.lang.String getClassName(java.lang.String logicalName, java.lang.String trailingName)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
public static java.lang.String getClassNameRepresentation(java.lang.String name)
Returns the class name representation of the given name- Parameters:
name- The name to convert- Returns:
- The property name representation
-
getClassNameForLowerCaseHyphenSeparatedName
public static java.lang.String getClassNameForLowerCaseHyphenSeparatedName(java.lang.String name)
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
public static java.lang.String getCapitalizedName(java.lang.String name)
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
public static java.lang.String getLogicalName(java.lang.Class<?> clazz, java.lang.String trailingName)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
public static java.lang.String getLogicalName(java.lang.String name, java.lang.String trailingName)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
public static java.lang.String getLogicalPropertyName(java.lang.String className, java.lang.String trailingName)
-
getPropertyName
public static java.lang.String getPropertyName(java.lang.String name)
Shorter version of getPropertyNameRepresentation- Parameters:
name- The name to convert- Returns:
- The property name version
-
getPropertyName
public static java.lang.String getPropertyName(java.lang.Class<?> clazz)
Shorter version of getPropertyNameRepresentation- Parameters:
clazz- The clazz to convert- Returns:
- The property name version
-
getPropertyName
public static java.lang.String getPropertyName(java.lang.reflect.Method method)
Returns the property name representation of the givenMethod- Parameters:
method- The method to inspect- Returns:
- The property name representation
- Since:
- 3.0.0
-
getPropertyNameRepresentation
public static java.lang.String getPropertyNameRepresentation(java.lang.Class<?> targetClass)
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
public static java.lang.String getPropertyNameRepresentation(java.lang.String name)
Returns the property name representation of the given name- Parameters:
name- The name to convert- Returns:
- The property name representation
-
getPropertyNameForLowerCaseHyphenSeparatedName
public static java.lang.String getPropertyNameForLowerCaseHyphenSeparatedName(java.lang.String name)
Converts foo-bar into fooBar- Parameters:
name- The lower case hyphen separated name- Returns:
- The property name equivalent
-
getShortName
public static java.lang.String getShortName(java.lang.Class<?> targetClass)
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
public static java.lang.String getShortName(java.lang.String className)
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
public static java.lang.String getNaturalName(java.lang.String name)
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
public static boolean isBlank(java.lang.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 returnsfalse.- Parameters:
str- The string to test.- Returns:
trueif the string isnull, or blank.
-
isNotBlank
public static boolean isNotBlank(java.lang.String str)
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
public static java.lang.String requireNonBlank(java.lang.String str)
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:
java.lang.IllegalArgumentException- ifstrisblank
-
requireNonBlank
public static java.lang.String requireNonBlank(java.lang.String str, java.lang.String message)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:
java.lang.IllegalArgumentException- ifstrisblank
-
getHyphenatedName
public static java.lang.String getHyphenatedName(java.lang.Class<?> clazz)
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
public static java.lang.String getHyphenatedName(java.lang.String name)
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
public static java.lang.String uncapitalize(java.lang.String str)
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
public static java.lang.Object splitValue(java.lang.String value)
-
escape
private static java.lang.String escape(char character)
-
padLeft
public static java.lang.String padLeft(java.lang.String str, int numChars)
-
padLeft
public static java.lang.String padLeft(java.lang.String str, int numChars, java.lang.String padding)
-
padRight
public static java.lang.String padRight(java.lang.String str, int numChars)
-
padRight
public static java.lang.String padRight(java.lang.String str, int numChars, java.lang.String padding)
-
getPadding
private static java.lang.String getPadding(java.lang.String padding, int length)
-
times
public static java.lang.String times(java.lang.String str, int num)
-
stripMargin
public static java.lang.String stripMargin(java.lang.String str)
-
escapeRegexChars
public static java.lang.String escapeRegexChars(java.lang.String str)
-
toSafeRegexPattern
public static java.lang.String toSafeRegexPattern(java.lang.String str)
-
normalizeRegexPattern
public static java.lang.String normalizeRegexPattern(java.lang.String str)
-
toSafePattern
public static java.util.regex.Pattern toSafePattern(java.lang.String str)
-
isTrue
public static boolean isTrue(java.lang.Object o)
-
isFalse
public static boolean isFalse(java.lang.Object o)
-
quote
public static java.lang.String quote(java.lang.String str)
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
public static java.lang.String unquote(java.lang.String str)
Removes single or double quotes from a String- Parameters:
str- the String from which quotes will be removed- Returns:
- the unquoted String
-
applyQuotes
private static java.lang.String applyQuotes(java.lang.String string)
-
-