Class CharSequenceUtils
- java.lang.Object
-
- io.microsphere.util.CharSequenceUtils
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleancontainsWhitespace(java.lang.CharSequence str)Checks whether the givenCharSequencecontains any whitespace characters.static booleanisEmpty(java.lang.CharSequence value)Checks if the providedCharSequenceis empty.static booleanisNotEmpty(java.lang.CharSequence value)Checks if the providedCharSequenceis not empty.static intlength(java.lang.CharSequence value)Returns the length of the providedCharSequence.static java.lang.CharSequencetrimAllWhitespace(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)returns0length("")returns0length("hello")} returns5
- Parameters:
value- theCharSequenceto get the length from- Returns:
- the length of the provided value, or
0if it isnull
-
isEmpty
public static boolean isEmpty(@Nullable java.lang.CharSequence value)
Checks if the providedCharSequenceis empty.A
CharSequenceis considered empty if its length is0. This method returnstrueif the provided value isnullor has a length of0.Example Usage
isEmpty(null)returnstrueisEmpty("")returnstrueisEmpty("hello")} returnsfalse
- Parameters:
value- theCharSequenceto check- Returns:
trueif the providedCharSequenceis empty or null, otherwisefalse
-
isNotEmpty
public static boolean isNotEmpty(@Nullable java.lang.CharSequence value)
Checks if the providedCharSequenceis not empty.A
CharSequenceis considered not empty if its length is greater than0. This method returnstrueif the provided value is notnulland has a length greater than0.Example Usage
isNotEmpty(null)returnsfalseisNotEmpty("")returnsfalseisNotEmpty("hello")} returnstrue
- Parameters:
value- theCharSequenceto check- Returns:
trueif the providedCharSequenceis not empty, otherwisefalse
-
containsWhitespace
public static boolean containsWhitespace(@Nullable java.lang.CharSequence str)
Checks whether the givenCharSequencecontains any whitespace characters.A whitespace character is defined as any character that returns
truewhen passed toCharacter.isWhitespace(char).Example Usage
containsWhitespace(null)returnsfalsecontainsWhitespace("")returnsfalsecontainsWhitespace("hello world")returnstruecontainsWhitespace("hello\tworld")returnstruecontainsWhitespace("helloworld")returnsfalse
- Parameters:
str- theCharSequenceto check (may benull)- Returns:
trueif 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 isnullor empty, it will be returned as-is.Example Usage
trimAllWhitespace(null)returnsnulltrimAllWhitespace("")returns""trimAllWhitespace(" hello world ")returns"helloworld"trimAllWhitespace(" \t\n h e l l o \r\n\f")returns"hello"
- Parameters:
str- theCharSequenceto trim (may benull)- Returns:
- a new
CharSequencewith all whitespace characters removed, or the original if none exist
-
-