Class StringUtils
- java.lang.Object
-
- org.iqtig.packer.shared.error.crypto.StringUtils
-
public class StringUtils extends Object
Clone from org.apache.commons:commons-lang3:3.11.- Author:
- matthias.drummer
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringdefaultString(String str)Returns either the passed in String, or if the String isnull, an empty String ("").static StringdefaultString(String str, String defaultStr)Returns either the passed in String, or if the String isnull, the value ofdefaultStr.static booleanisBlank(CharSequence cs)Checks if a CharSequence is empty (""), null or whitespace only.static Stringjoin(Iterable<?> iterable, String separator)Joins the elements of the providedIterableinto a single String containing the provided elements.static Stringjoin(Object[] array, String separator)Joins the elements of the provided array into a single String containing the provided list of elements.static Stringjoin(Object[] array, String separator, int startIndex, int endIndex)Joins the elements of the provided array into a single String containing the provided list of elements.static Stringjoin(Iterator<?> iterator, String separator)Joins the elements of the providedIteratorinto a single String containing the provided elements.static intlength(CharSequence cs)Gets a CharSequence length or0if the CharSequence isnull.
-
-
-
Field Detail
-
EMPTY
public static final String EMPTY
The empty String"".- Since:
- 2.0
- See Also:
- Constant Field Values
-
-
Method Detail
-
defaultString
public static String defaultString(String str)
Returns either the passed in String, or if the String is
null, an empty String ("").StringUtils.defaultString(null) = "" StringUtils.defaultString("") = "" StringUtils.defaultString("bat") = "bat"- Parameters:
str- the String to check, may be null- Returns:
- the passed in String, or the empty String if it
was
null - See Also:
String.valueOf(Object)
-
defaultString
public static String defaultString(String str, String defaultStr)
Returns either the passed in String, or if the String is
null, the value ofdefaultStr.StringUtils.defaultString(null, "NULL") = "NULL" StringUtils.defaultString("", "NULL") = "" StringUtils.defaultString("bat", "NULL") = "bat"- Parameters:
str- the String to check, may be nulldefaultStr- the default String to return if the input isnull, may be null- Returns:
- the passed in String, or the default if it was
null - See Also:
String.valueOf(Object)
-
join
public static String join(Iterable<?> iterable, String separator)
Joins the elements of the provided
Iterableinto a single String containing the provided elements.No delimiter is added before or after the list. A
nullseparator is the same as an empty String ("").See the examples here:
join(Object[], String).- Parameters:
iterable- theIterableproviding the values to join together, may be nullseparator- the separator character to use, null treated as ""- Returns:
- the joined String,
nullif null iterator input - Since:
- 2.3
-
join
public static String join(Iterator<?> iterator, String separator)
Joins the elements of the provided
Iteratorinto a single String containing the provided elements.No delimiter is added before or after the list. A
nullseparator is the same as an empty String ("").See the examples here:
join(Object[], String).- Parameters:
iterator- theIteratorof values to join together, may be nullseparator- the separator character to use, null treated as ""- Returns:
- the joined String,
nullif null iterator input
-
join
public static String join(Object[] array, String separator)
Joins the elements of the provided array into a single String containing the provided list of elements.
No delimiter is added before or after the list. A
nullseparator is the same as an empty String (""). Null objects or empty strings within the array are represented by empty strings.StringUtils.join(null, *) = null StringUtils.join([], *) = "" StringUtils.join([null], *) = "" StringUtils.join(["a", "b", "c"], "--") = "a--b--c" StringUtils.join(["a", "b", "c"], null) = "abc" StringUtils.join(["a", "b", "c"], "") = "abc" StringUtils.join([null, "", "a"], ',') = ",,a"
- Parameters:
array- the array of values to join together, may be nullseparator- the separator character to use, null treated as ""- Returns:
- the joined String,
nullif null array input
-
join
public static String join(Object[] array, String separator, int startIndex, int endIndex)
Joins the elements of the provided array into a single String containing the provided list of elements.
No delimiter is added before or after the list. A
nullseparator is the same as an empty String (""). Null objects or empty strings within the array are represented by empty strings.StringUtils.join(null, *, *, *) = null StringUtils.join([], *, *, *) = "" StringUtils.join([null], *, *, *) = "" StringUtils.join(["a", "b", "c"], "--", 0, 3) = "a--b--c" StringUtils.join(["a", "b", "c"], "--", 1, 3) = "b--c" StringUtils.join(["a", "b", "c"], "--", 2, 3) = "c" StringUtils.join(["a", "b", "c"], "--", 2, 2) = "" StringUtils.join(["a", "b", "c"], null, 0, 3) = "abc" StringUtils.join(["a", "b", "c"], "", 0, 3) = "abc" StringUtils.join([null, "", "a"], ',', 0, 3) = ",,a"
- Parameters:
array- the array of values to join together, may be nullseparator- the separator character to use, null treated as ""startIndex- the first index to start joining from.endIndex- the index to stop joining from (exclusive).- Returns:
- the joined String,
nullif null array input; or the empty string ifendIndex - startIndex <= 0. The number of joined entries is given byendIndex - startIndex - Throws:
ArrayIndexOutOfBoundsException- ife
startIndex < 0or
startIndex >= array.length()or
endIndex < 0or
endIndex > array.length()
-
isBlank
public static boolean isBlank(CharSequence cs)
Checks if a CharSequence is empty (""), null or whitespace only.
Whitespace is defined by
Character.isWhitespace(char).StringUtils.isBlank(null) = true StringUtils.isBlank("") = true StringUtils.isBlank(" ") = true StringUtils.isBlank("bob") = false StringUtils.isBlank(" bob ") = false- Parameters:
cs- the CharSequence to check, may be null- Returns:
trueif the CharSequence is null, empty or whitespace only- Since:
- 2.0, 3.0 Changed signature from isBlank(String) to isBlank(CharSequence)
-
length
public static int length(CharSequence cs)
Gets a CharSequence length or0if the CharSequence isnull.- Parameters:
cs- a CharSequence ornull- Returns:
- CharSequence length or
0if the CharSequence isnull. - Since:
- 2.4, 3.0 Changed signature from length(String) to length(CharSequence)
-
-