Class StringUtils
- java.lang.Object
-
- ch.systemsx.cisd.common.shared.basic.string.StringUtils
-
public final class StringUtils extends java.lang.Object
Some utilities forString
.Can be used from GWT code.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
EMPTY_STRING
static java.lang.String[]
EMPTY_STRING_ARRAY
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
abbreviate(java.lang.String value, int maxLength)
static java.lang.String
capitalize(java.lang.String word)
static java.lang.String
defaultIfBlank(java.lang.String str, java.lang.String defaultStr)
Returns defaultStr, if str is blank, or otherwise it returns str itself.static java.lang.String
emptyIfNull(java.lang.String stringOrNull)
Returns an empty string if given stringOrNull isnull
, otherwise it returns stringOrNull itself.static java.lang.String
escape(java.lang.String text, char... escapedChars)
Escapes escapedChars characters in specified text.static boolean
isBlank(java.lang.Object value)
Whether given value is blank or not.static boolean
isBlank(java.lang.String value)
Whether given value is blank or not.static boolean
isNotBlank(java.lang.String value)
Whether given value is not blank.static java.lang.String
join(java.lang.Object[] array, java.lang.String separator)
Joins the elements of the provided array into a singleString
containing the provided list of elements.static java.lang.String
joinList(java.util.List<java.lang.String> list)
Joins the elements using comma as a separator.static java.lang.String
joinList(java.util.List<java.lang.String> list, java.lang.String separator)
Joins the elements using comma as a separator.static boolean
matches(java.lang.String regExp, java.lang.String value)
Returnstrue
if given regExp could be found in given value.static boolean
matches(java.lang.String regExp, java.lang.String value, java.lang.String modifiers)
Returnstrue
if given regExp could be found in given value.static java.lang.String
nullIfBlank(java.lang.String value)
Returnsnull
if given value is blank.static java.util.List<java.lang.String>
tokenize(java.lang.String str)
Returns the tokens found in str, where tokens are separated by white spaces.static java.lang.String
toStringEmptyIfNull(java.lang.Object objectOrNull)
Returns an empty string if given objectOrNull isnull
, otherwise it returns result ofObject.toString()
on the object.static java.lang.String
toStringOrNull(java.lang.Object objectOrNull)
Returns null if given objectOrNull isnull
, otherwise it returns result ofObject.toString()
on the object.static java.lang.String
trimToNull(java.lang.String value)
Trims given value tonull
.
-
-
-
Field Detail
-
EMPTY_STRING
public static final java.lang.String EMPTY_STRING
- See Also:
- Constant Field Values
-
EMPTY_STRING_ARRAY
public static final java.lang.String[] EMPTY_STRING_ARRAY
-
-
Method Detail
-
isBlank
public static final boolean isBlank(java.lang.String value)
Whether given value is blank or not.
-
isBlank
public static final boolean isBlank(java.lang.Object value)
Whether given value is blank or not.
-
isNotBlank
public static final boolean isNotBlank(java.lang.String value)
Whether given value is not blank.
-
joinList
public static final java.lang.String joinList(java.util.List<java.lang.String> list)
Joins the elements using comma as a separator.
Example: "a", "b", "c" -> "a, b, c"
-
joinList
public static final java.lang.String joinList(java.util.List<java.lang.String> list, java.lang.String separator)
Joins the elements using comma as a separator.
Example: "a", "b", "c" -> "a, b, c"
-
join
public static final java.lang.String join(java.lang.Object[] array, java.lang.String separator)
Joins the elements of the provided array into a singleString
containing the provided list of elements.
-
capitalize
public static final java.lang.String capitalize(java.lang.String word)
-
abbreviate
public static final java.lang.String abbreviate(java.lang.String value, int maxLength)
-
trimToNull
public static final java.lang.String trimToNull(java.lang.String value)
Trims given value tonull
.- Returns:
null
if given value is blank.
-
nullIfBlank
public static final java.lang.String nullIfBlank(java.lang.String value)
Returnsnull
if given value is blank.
-
emptyIfNull
public static final java.lang.String emptyIfNull(java.lang.String stringOrNull)
Returns an empty string if given stringOrNull isnull
, otherwise it returns stringOrNull itself.
-
toStringEmptyIfNull
public static final java.lang.String toStringEmptyIfNull(java.lang.Object objectOrNull)
Returns an empty string if given objectOrNull isnull
, otherwise it returns result ofObject.toString()
on the object.
-
toStringOrNull
public static final java.lang.String toStringOrNull(java.lang.Object objectOrNull)
Returns null if given objectOrNull isnull
, otherwise it returns result ofObject.toString()
on the object.
-
defaultIfBlank
public static final java.lang.String defaultIfBlank(java.lang.String str, java.lang.String defaultStr)
Returns defaultStr, if str is blank, or otherwise it returns str itself.
-
escape
public static final java.lang.String escape(java.lang.String text, char... escapedChars)
Escapes escapedChars characters in specified text.
-
tokenize
public static final java.util.List<java.lang.String> tokenize(java.lang.String str)
Returns the tokens found in str, where tokens are separated by white spaces.
-
matches
public static final boolean matches(java.lang.String regExp, java.lang.String value, java.lang.String modifiers)
Returnstrue
if given regExp could be found in given value.Allowed modifiers are:
- i - Perform case-insensitive matching
- g - Perform a global match (find all matches rather than stopping after the first match)
- m - Perform multiline matching
-
matches
public static final boolean matches(java.lang.String regExp, java.lang.String value)
Returnstrue
if given regExp could be found in given value.
-
-