Class CharSequenceUtils
- java.lang.Object
-
- io.microsphere.util.CharSequenceUtils
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
containsWhitespace(java.lang.CharSequence str)
Checks whether the givenCharSequence
contains any whitespace characters.static boolean
isEmpty(java.lang.CharSequence value)
Checks if the providedCharSequence
is empty.static boolean
isNotEmpty(java.lang.CharSequence value)
Checks if the providedCharSequence
is not empty.static int
length(java.lang.CharSequence value)
Returns the length of the providedCharSequence
.static java.lang.CharSequence
trimAllWhitespace(java.lang.CharSequence str)
Trims all whitespace characters from the givenCharSequence
.
-
-
-
Method Detail
-
length
public static int length(@Nullable java.lang.CharSequence value)
Returns the length of the providedCharSequence
.If the provided value is
null
, this method returns0
. Otherwise, it returns the result of calling theCharSequence.length()
method.Example Usage
length(null)
returns0
length("")
returns0
length("hello")
} returns5
- Parameters:
value
- theCharSequence
to get the length from- Returns:
- the length of the provided value, or
0
if it isnull
-
isEmpty
public static boolean isEmpty(@Nullable java.lang.CharSequence value)
Checks if the providedCharSequence
is empty.A
CharSequence
is considered empty if its length is0
. This method returnstrue
if the provided value isnull
or has a length of0
.Example Usage
isEmpty(null)
returnstrue
isEmpty("")
returnstrue
isEmpty("hello")
} returnsfalse
- Parameters:
value
- theCharSequence
to check- Returns:
true
if the providedCharSequence
is empty or null, otherwisefalse
-
isNotEmpty
public static boolean isNotEmpty(@Nullable java.lang.CharSequence value)
Checks if the providedCharSequence
is not empty.A
CharSequence
is considered not empty if its length is greater than0
. This method returnstrue
if the provided value is notnull
and has a length greater than0
.Example Usage
isNotEmpty(null)
returnsfalse
isNotEmpty("")
returnsfalse
isNotEmpty("hello")
} returnstrue
- Parameters:
value
- theCharSequence
to check- Returns:
true
if the providedCharSequence
is not empty, otherwisefalse
-
containsWhitespace
public static boolean containsWhitespace(@Nullable java.lang.CharSequence str)
Checks whether the givenCharSequence
contains any whitespace characters.A whitespace character is defined as any character that returns
true
when passed toCharacter.isWhitespace(char)
.Example Usage
containsWhitespace(null)
returnsfalse
containsWhitespace("")
returnsfalse
containsWhitespace("hello world")
returnstrue
containsWhitespace("hello\tworld")
returnstrue
containsWhitespace("helloworld")
returnsfalse
- Parameters:
str
- theCharSequence
to check (may benull
)- Returns:
true
if the provided sequence is not empty and contains at least one whitespace character; otherwise,false
-
trimAllWhitespace
public static java.lang.CharSequence trimAllWhitespace(java.lang.CharSequence str)
Trims all whitespace characters from the givenCharSequence
.This method removes all whitespace characters (as defined by
Character.isWhitespace(char)
) from the beginning, end, and middle of the input sequence. If the input isnull
or empty, it will be returned as-is.Example Usage
trimAllWhitespace(null)
returnsnull
trimAllWhitespace("")
returns""
trimAllWhitespace(" hello world ")
returns"helloworld"
trimAllWhitespace(" \t\n h e l l o \r\n\f")
returns"hello"
- Parameters:
str
- theCharSequence
to trim (may benull
)- Returns:
- a new
CharSequence
with all whitespace characters removed, or the original if none exist
-
-