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 String
defaultString(String str)
Returns either the passed in String, or if the String isnull
, an empty String ("").static String
defaultString(String str, String defaultStr)
Returns either the passed in String, or if the String isnull
, the value ofdefaultStr
.static boolean
isBlank(CharSequence cs)
Checks if a CharSequence is empty (""), null or whitespace only.static String
join(Iterable<?> iterable, String separator)
Joins the elements of the providedIterable
into a single String containing the provided elements.static String
join(Object[] array, String separator)
Joins the elements of the provided array into a single String containing the provided list of elements.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.static String
join(Iterator<?> iterator, String separator)
Joins the elements of the providedIterator
into a single String containing the provided elements.static int
length(CharSequence cs)
Gets a CharSequence length or0
if 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
Iterable
into a single String containing the provided elements.No delimiter is added before or after the list. A
null
separator is the same as an empty String ("").See the examples here:
join(Object[], String)
.- Parameters:
iterable
- theIterable
providing the values to join together, may be nullseparator
- the separator character to use, null treated as ""- Returns:
- the joined String,
null
if null iterator input - Since:
- 2.3
-
join
public static String join(Iterator<?> iterator, String separator)
Joins the elements of the provided
Iterator
into a single String containing the provided elements.No delimiter is added before or after the list. A
null
separator is the same as an empty String ("").See the examples here:
join(Object[], String)
.- Parameters:
iterator
- theIterator
of values to join together, may be nullseparator
- the separator character to use, null treated as ""- Returns:
- the joined String,
null
if 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
null
separator 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,
null
if 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
null
separator 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,
null
if null array input; or the empty string ifendIndex - startIndex <= 0
. The number of joined entries is given byendIndex - startIndex
- Throws:
ArrayIndexOutOfBoundsException
- ife
startIndex < 0
or
startIndex >= array.length()
or
endIndex < 0
or
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:
true
if 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 or0
if the CharSequence isnull
.- Parameters:
cs
- a CharSequence ornull
- Returns:
- CharSequence length or
0
if the CharSequence isnull
. - Since:
- 2.4, 3.0 Changed signature from length(String) to length(CharSequence)
-
-