Package org.apache.openjpa.lib.util
Class StringUtil
java.lang.Object
org.apache.openjpa.lib.util.StringUtil
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
capitalize
(String str) Capitalizes a String changing the first letter to title case as perCharacter.toTitleCase(char)
.static boolean
static boolean
endsWithIgnoreCase
(String str, String suffix) static boolean
equalsIgnoreCase
(String str1, String str2) static boolean
isBlank
(CharSequence cs) Checks if a CharSequence is whitespace, empty ("") or null.static boolean
static boolean
Checks if a CharSequence is not empty (""), not null and not whitespace only.static boolean
isNotEmpty
(String val) static String
static <T> T
Parse the givenstatic String
Replace all instances offrom
instr
withto
.static String[]
Splits the given string on the given token.static String
Strips any of a set of characters from the end of a String.static String
Null-safeString.trim()
static String
trimToNull
(String str) static String
uncapitalize
(String str) Uncapitalizes a String changing the first letter to title case as perCharacter.toLowerCase(char)
.
-
Method Details
-
isEmpty
- Returns:
true
if the given string is null or empty.
-
isNotEmpty
-
isBlank
Checks if a CharSequence is whitespace, empty ("") or null.
StringUtils.isBlank(null) = true StringUtils.isBlank("") = true StringUtils.isBlank(" ") = true StringUtils.isBlank("bob") = false StringUtils.isBlank(" bob ") = false
Ported over from Apache commons-lang3- Parameters:
cs
- the CharSequence to check, may be null- Returns:
true
if the CharSequence is null, empty or whitespace
-
isNotBlank
Checks if a CharSequence is not empty (""), not null and not whitespace only.
StringUtils.isNotBlank(null) = false StringUtils.isNotBlank("") = false StringUtils.isNotBlank(" ") = false StringUtils.isNotBlank("bob") = true StringUtils.isNotBlank(" bob ") = true
Ported over from Apache commons-lang3- Parameters:
cs
- the CharSequence to check, may be null- Returns:
true
if the CharSequence is not empty and not null and not whitespace
-
contains
- Parameters:
val
- the string to search incharToSearchFor
- the character to search for- Returns:
true
if the charToSearchFor is contained in the String val
-
equalsIgnoreCase
-
split
Splits the given string on the given token. Follows the semantics of the Java 1.4String.split(String, int)
method, but does not treat the given token as a regular expression. -
replace
Replace all instances offrom
instr
withto
.- Parameters:
str
- the candidate string to replacefrom
- the token to replaceto
- the new token- Returns:
- the string with all the replacements made
-
trim
Null-safeString.trim()
-
trimToNull
- Returns:
- the trimmed string str or
null
if the trimmed string would be empty.
-
join
-
parse
Parse the given- Parameters:
val
- value to parsetype
- the target type of the the parsed value- Returns:
- the converted value
-
capitalize
Capitalizes a String changing the first letter to title case as per
Character.toTitleCase(char)
. No other letters are changed.StringUtil.capitalize(null) = null StringUtil.capitalize("") = "" StringUtil.capitalize("cat") = "Cat" StringUtil.capitalize("cAt") = "CAt"
Ported over from Apache commons-lang3- Parameters:
str
- the String to capitalize, may be null- Returns:
- the capitalized String,
null
if null String input - See Also:
-
uncapitalize
Uncapitalizes a String changing the first letter to title case as per
Character.toLowerCase(char)
. No other letters are changed.StringUtil.uncapitalize(null) = null StringUtil.uncapitalize("") = "" StringUtil.uncapitalize("Cat") = "cat" StringUtil.uncapitalize("CAT") = "cAT"
Ported over from Apache commons-lang3- Parameters:
str
- the String to uncapitalize, may be null- Returns:
- the uncapitalized String,
null
if null String input - See Also:
-
endsWithIgnoreCase
-
stripEnd
Strips any of a set of characters from the end of a String.
A
null
input String returnsnull
. An empty string ("") input returns the empty string.If the stripChars String is
null
, whitespace is stripped as defined byCharacter.isWhitespace(char)
.StringUtils.stripEnd(null, *) = null StringUtils.stripEnd("", *) = "" StringUtils.stripEnd("abc", "") = "abc" StringUtils.stripEnd("abc", null) = "abc" StringUtils.stripEnd(" abc", null) = " abc" StringUtils.stripEnd("abc ", null) = "abc" StringUtils.stripEnd(" abc ", null) = " abc" StringUtils.stripEnd(" abcyx", "xyz") = " abc" StringUtils.stripEnd("120.00", ".0") = "12"
Ported over from Apache commons-lang3- Parameters:
str
- the String to remove characters from, may be nullstripChars
- the set of characters to remove, null treated as whitespace- Returns:
- the stripped String,
null
if null String input
-