com.evanmclean.evlib.lang
Class Str

java.lang.Object
  extended by com.evanmclean.evlib.lang.Str

public final class Str
extends Object

Misc string operations.

For the purposes of this class, a whitespace character is any character equal or below ' ' (ASCII 32, which is the space character, and all below are control characters) or any character for which Character.isWhitespace(char) returns true. This does not include non-breaking space characters in the Unicode set.

The standard String.trim() method only strips characters equal or below ' ' (ASCII 32), so I think these methods are more complete.

Author:
Evan McLean McLean Computer Services (see the overview for copyright and licensing.)

Nested Class Summary
static interface Str.ToString<T>
          Can be passed into a join call perform specialised object to string conversions.
 
Field Summary
static String EMPTY
          A final, unmodifiable, zero length string, in case you need one.
 
Method Summary
static boolean endsWithIgnoreCase(String str, String suffix)
          Tests if the string ends with the specified suffix, ignoring case.
static boolean equals(String lhs, String rhs)
          Compares two strings, handling nulls.
static boolean equalsIgnoreCase(String lhs, String rhs)
          Compares two strings in a case insensitive manner, handling nulls.
static boolean equalsOneOf(String lhs, String... rhs)
          Calls lhs.equals() for each of the other strings until one of them returns true.
static boolean equalsOneOfIgnoreCase(String lhs, String... rhs)
          Calls lhs.equalsIgnoreCase() for each of the other strings until one of them returns true.
static String getStackTrace(Throwable ex)
           Takes what would normally be output from Throwable.printStackTrace() and returns it as a string.
static
<T extends CharSequence>
T
ifBlank(T str, T alt)
           Return the first parameter if it is not null, zero length, and contains at least one non-whitespace character, otherwise return the second parameter.
static
<T extends CharSequence>
T
ifEmpty(T str, T alt)
          Return the first parameter if it is not null or a zero length string, otherwise return the second parameter.
static String ifNull(String str)
          Return the parameter if it is not null, otherwise return an empty string.
static
<T extends CharSequence>
T
ifNull(T str, T alt)
          Return the first parameter if it is not null, otherwise return the second parameter.
static boolean isBlank(CharSequence str)
           Returns true if the parameter is null, zero length, or only contains whitespace.
static boolean isEmpty(CharSequence str)
          Returns true if the parameter is null or a zero length string.
static boolean isNotBlank(CharSequence str)
           Returns true if the parameter is not null, not zero length, and contains at least one non-whitespace character.
static boolean isNotEmpty(CharSequence str)
          Returns true if the parameter is not null and not a zero length string.
static
<T> String
join(char sep, Iterable<T> it)
           Joins the elements in the provided iterable into a string.
static
<T> String
join(char sep, Iterator<T> it)
           Joins the elements in the provided iterator into a string.
static
<T> String
join(char sep, Str.ToString<T> tos, Iterable<T> it)
           Joins the elements in the provided iterable into a string.
static
<T> String
join(char sep, Str.ToString<T> tos, Iterator<T> it)
           Joins the elements in the provided iterator into a string.
static
<T> String
join(char sep, Str.ToString<T> tos, T... arr)
           Joins the elements in the provided array into a string.
static
<T> String
join(char sep, Str.ToString<T> tos, T[] arr, int start_index)
           Joins the elements in the provided array into a string.
static
<T> String
join(char sep, Str.ToString<T> tos, T[] arr, int start_index, int end_index)
           Joins the elements in the provided array into a string.
static
<T> String
join(char sep, T... arr)
           Joins the elements in the provided array into a string.
static
<T> String
join(char sep, T[] arr, int start_index)
           Joins the elements in the provided array into a string.
static
<T> String
join(char sep, T[] arr, int start_index, int end_index)
           Joins the elements in the provided array into a string.
static
<T> StringBuilder
join(StringBuilder buff, char sep, Iterable<T> it)
           Appends the elements in the provided iterable onto a string builder.
static
<T> StringBuilder
join(StringBuilder buff, char sep, Iterator<T> it)
           Appends the elements in the provided iterator onto a string builder.
static
<T> StringBuilder
join(StringBuilder buff, char sep, Str.ToString<T> tos, Iterable<T> it)
           Appends the elements in the provided iterable onto a string builder.
static
<T> StringBuilder
join(StringBuilder buff, char sep, Str.ToString<T> tos, Iterator<T> it)
           Appends the elements in the provided iterator onto a string builder.
static
<T> StringBuilder
join(StringBuilder buff, char sep, Str.ToString<T> tos, T... arr)
           Appends the elements in the provided array onto a string builder.
static
<T> StringBuilder
join(StringBuilder buff, char sep, Str.ToString<T> tos, T[] arr, int start_index)
           Appends the elements in the provided array onto a string builder.
static
<T> StringBuilder
join(StringBuilder buff, char sep, Str.ToString<T> tos, T[] arr, int start_index, int end_index)
           Appends the elements in the provided array onto a string builder.
static
<T> StringBuilder
join(StringBuilder buff, char sep, T... arr)
           Appends the elements in the provided array onto a string builder.
static
<T> StringBuilder
join(StringBuilder buff, char sep, T[] arr, int start_index)
           Appends the elements in the provided array onto a string builder.
static
<T> StringBuilder
join(StringBuilder buff, char sep, T[] arr, int start_index, int end_index)
           Appends the elements in the provided array onto a string builder.
static
<T> StringBuilder
join(StringBuilder buff, String sep, Iterable<T> it)
           Appends the elements in the provided iterable onto a string builder.
static
<T> StringBuilder
join(StringBuilder buff, String sep, Iterator<T> it)
           Appends the elements in the provided iterator onto a string builder.
static
<T> StringBuilder
join(StringBuilder buff, String sep, Str.ToString<T> tos, Iterable<T> it)
           Appends the elements in the provided iterable onto a string builder.
static
<T> StringBuilder
join(StringBuilder buff, String sep, Str.ToString<T> tos, Iterator<T> it)
           Appends the elements in the provided iterator onto a string builder.
static
<T> StringBuilder
join(StringBuilder buff, String sep, Str.ToString<T> tos, T... arr)
           Appends the elements in the provided array onto a string builder.
static
<T> StringBuilder
join(StringBuilder buff, String sep, Str.ToString<T> tos, T[] arr, int start_index)
           Appends the elements in the provided array onto a string builder.
static
<T> StringBuilder
join(StringBuilder buff, String sep, Str.ToString<T> tos, T[] arr, int start_index, int end_index)
           Appends the elements in the provided array onto a string builder.
static
<T> StringBuilder
join(StringBuilder buff, String sep, T... arr)
           Appends the elements in the provided array onto a string builder.
static
<T> StringBuilder
join(StringBuilder buff, String sep, T[] arr, int start_index)
           Appends the elements in the provided array onto a string builder.
static
<T> StringBuilder
join(StringBuilder buff, String sep, T[] arr, int start_index, int end_index)
           Appends the elements in the provided array onto a string builder.
static
<T> String
join(String sep, Iterable<T> it)
           Joins the elements in the provided iterable into a string.
static
<T> String
join(String sep, Iterator<T> it)
           Joins the elements in the provided iterator into a string.
static
<T> String
join(String sep, Str.ToString<T> tos, Iterable<T> it)
           Joins the elements in the provided iterable into a string.
static
<T> String
join(String sep, Str.ToString<T> tos, Iterator<T> it)
           Joins the elements in the provided iterator into a string.
static
<T> String
join(String sep, Str.ToString<T> tos, T... arr)
           Joins the elements in the provided array into a string.
static
<T> String
join(String sep, Str.ToString<T> tos, T[] arr, int start_index)
           Joins the elements in the provided array into a string.
static
<T> String
join(String sep, Str.ToString<T> tos, T[] arr, int start_index, int end_index)
           Joins the elements in the provided array into a string.
static
<T> String
join(String sep, T... arr)
           Joins the elements in the provided array into a string.
static
<T> String
join(String sep, T[] arr, int start_index)
           Joins the elements in the provided array into a string.
static
<T> String
join(String sep, T[] arr, int start_index, int end_index)
           Joins the elements in the provided array into a string.
static int length(CharSequence str)
          Return the length of the string, or zero if passed a null.
static StringBuilder ltrim(StringBuilder buff)
           Trims the string builder contents of any leading whitespace.
static String ltrimToEmpty(String str)
           Trims the string of any leading whitespace, but also returns a zero length string if the parameter was null.
static String ltrimToNull(String str)
           Trims the string of any leading whitespace, returning null if the result is a zero length string, or the parameter was null to begin with.
static boolean notEquals(String lhs, String rhs)
          Compares two strings, handling nulls.
static boolean notEqualsIgnoreCase(String lhs, String rhs)
          Compares two strings in a case insensitive manner, handling nulls.
static String replace(String orig, int start, int end, String replace)
          Replace a range of text within a string with a new string.
static StringBuilder rtrim(StringBuilder buff)
           Trims the string builder contents of any trailing whitespace.
static String rtrimToEmpty(String str)
           Trims the string of any trailing whitespace, but also returns a zero length string if the parameter was null.
static String rtrimToNull(String str)
           Trims the string of any trailing whitespace, returning null if the result is a zero length string, or the parameter was null to begin with.
static String[] split(Pattern regex, CharSequence str)
           Splits a string on a regular expression.
static String[] split(Pattern regex, CharSequence str, boolean trim, boolean remove_blank_lines)
           Splits a string on a regular expression, providing various cleanups such as trimming and elimination of blank lines.
static String[] split(Pattern regex, CharSequence str, int limit)
           Splits a string on a regular expression.
static String[] split(Pattern regex, CharSequence str, int limit, boolean trim, boolean remove_blank_lines)
           Splits a string on a regular expression, providing various cleanups such as trimming and elimination of blank lines.
static String[] splitLines(CharSequence str)
           Splits a string on a newlines.
static String[] splitLines(CharSequence str, boolean trim, boolean remove_blank_lines)
           Splits a string on a newlines, providing various cleanups such as trimming and elimination of blank lines.
static String[] splitLines(CharSequence str, int limit)
           Splits a string on a newlines.
static String[] splitLines(CharSequence str, int limit, boolean trim, boolean remove_blank_lines)
           Splits a string on a newlines, providing various cleanups such as trimming and elimination of blank lines.
static String[] splitStackTrace(Throwable ex)
           Takes what would normally be output from Throwable.printStackTrace() and breaks it into an array of Strings (one per line).
static boolean startsWithIgnoreCase(String str, String prefix)
          Tests if the string starts with the specified prefix, ignoring case.
static boolean startsWithIgnoreCase(String str, String prefix, int toffset)
          Tests if the string starts with the specified prefix, ignoring case.
static StringBuilder trim(StringBuilder buff)
           Trims the string builder contents of any leading and trailing whitespace.
static String trimToEmpty(String str)
           Trims the string of any leading and trailing whitespace, but also returns a zero length string if the parameter was null.
static String trimToNull(String str)
           Trims the string of any leading and trailing whitespace, returning null if the result is a zero length string, or the parameter was null to begin with.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY

public static final String EMPTY
A final, unmodifiable, zero length string, in case you need one. Saves you allocating others.

See Also:
Constant Field Values
Method Detail

endsWithIgnoreCase

public static boolean endsWithIgnoreCase(String str,
                                         String suffix)
Tests if the string ends with the specified suffix, ignoring case. This is really just a thin wrapper around String.regionMatches(boolean, int, String, int, int) that calculates the right offsets.

Parameters:
str - The string to check.
suffix - The suffix.
Returns:
Returns true if str ends with suffix, ignoring case. Note that the result will be true if suffix is an empty string or is equal to str as determined by the equalsIgnoreCase(Object) method.

equals

public static boolean equals(String lhs,
                             String rhs)
Compares two strings, handling nulls.
 Str.equals(null, null) = true
 Str.equals(null, "") = false
 Str.equals("", "") = true
 Str.equals("", " ") = false
 Str.equals("abc", "abc") = true
 Str.equals("abc", "ABC") = false
 Str.equals("abc", "def") = false
 

Parameters:
lhs -
rhs -
Returns:
True if both parameters are null, or lhs.equals(rhs) returns true.

equalsIgnoreCase

public static boolean equalsIgnoreCase(String lhs,
                                       String rhs)
Compares two strings in a case insensitive manner, handling nulls.
 Str.equals(null, null) = true
 Str.equals(null, "") = false
 Str.equals("", "") = true
 Str.equals("", " ") = false
 Str.equals("abc", "abc") = true
 Str.equals("abc", "ABC") = true
 Str.equals("abc", "def") = false
 

Parameters:
lhs -
rhs -
Returns:
True if both parameters are null, or lhs.equalsIgnoreCase(rhs) returns true.

equalsOneOf

public static boolean equalsOneOf(String lhs,
                                  String... rhs)
Calls lhs.equals() for each of the other strings until one of them returns true.

Parameters:
lhs - The string to compare.
rhs - One or more string to compare against for equality.
Returns:
True if lhs.equals(rhs) returns true for one of the rhs objects specified. Returns true if lhs is null and one of the rhs objects is also null.

equalsOneOfIgnoreCase

public static boolean equalsOneOfIgnoreCase(String lhs,
                                            String... rhs)
Calls lhs.equalsIgnoreCase() for each of the other strings until one of them returns true.

Parameters:
lhs - The string to compare.
rhs - One or more string to compare against for equality.
Returns:
True if lhs.equalsIgnoreCase(rhs) returns true for one of the rhs objects specified. Returns true if lhs is null and one of the rhs objects is also null.

getStackTrace

public static String getStackTrace(Throwable ex)

Takes what would normally be output from Throwable.printStackTrace() and returns it as a string.

Parameters:
ex - The exception to process.
Returns:
The output as a string.

ifBlank

public static <T extends CharSequence> T ifBlank(T str,
                                                 T alt)

Return the first parameter if it is not null, zero length, and contains at least one non-whitespace character, otherwise return the second parameter.

See note above for our definition of whitespace.

Type Parameters:
T - Anything that implements CharSequence (such as Str.ToStrings).
Parameters:
str -
alt -
Returns:
Return str parameter if it is not null, zero length, and contains at least one non-whitespace character, otherwise return alt.

ifEmpty

public static <T extends CharSequence> T ifEmpty(T str,
                                                 T alt)
Return the first parameter if it is not null or a zero length string, otherwise return the second parameter.

Type Parameters:
T - Anything that implements CharSequence (such as Str.ToStrings).
Parameters:
str -
alt -
Returns:
Return str if it is not null or a zero length string, otherwise return alt.

ifNull

public static String ifNull(String str)
Return the parameter if it is not null, otherwise return an empty string.

Parameters:
str -
Returns:
Return str if it is not null, otherwise return an empty string.

ifNull

public static <T extends CharSequence> T ifNull(T str,
                                                T alt)
Return the first parameter if it is not null, otherwise return the second parameter.

Type Parameters:
T - Anything that implements CharSequence (such as Str.ToStrings).
Parameters:
str -
alt -
Returns:
Return str if it is not null, otherwise return alt.

isBlank

public static boolean isBlank(CharSequence str)

Returns true if the parameter is null, zero length, or only contains whitespace.

See note above for our definition of whitespace.

Parameters:
str -
Returns:
Returns true if the parameter is null, zero length, or only contains whitespace.

isEmpty

public static boolean isEmpty(CharSequence str)
Returns true if the parameter is null or a zero length string.

Parameters:
str -
Returns:
Returns true if the parameter is null or a zero length string.

isNotBlank

public static boolean isNotBlank(CharSequence str)

Returns true if the parameter is not null, not zero length, and contains at least one non-whitespace character.

See note above for our definition of whitespace.

Parameters:
str -
Returns:
Returns true if the parameter is not null , not zero length, and contains at least one non-whitespace character.

isNotEmpty

public static boolean isNotEmpty(CharSequence str)
Returns true if the parameter is not null and not a zero length string.

Parameters:
str -
Returns:
Returns true if the parameter is not null and not a zero length string.

join

public static <T> String join(char sep,
                              Iterable<T> it)

Joins the elements in the provided iterable into a string. Null objects and empty strings are skipped.

Object.toString() is called on each element.

Type Parameters:
T - <T>.toString() called.
Parameters:
sep - What to insert between each element.
it - The elements to join together.
Returns:
The string of joined elements.

join

public static <T> String join(char sep,
                              Iterator<T> it)

Joins the elements in the provided iterator into a string. Null objects and empty strings are skipped.

Object.toString() is called on each element.

Type Parameters:
T - <T>.toString() called.
Parameters:
sep - What to insert between each element.
it - The elements to join together.
Returns:
The string of joined elements.

join

public static <T> String join(char sep,
                              T... arr)

Joins the elements in the provided array into a string. Null objects and empty strings are skipped.

Object.toString() is called on each element.

Type Parameters:
T - <T>.toString() called.
Parameters:
sep - What to insert between each element.
arr - The array of elements to join together.
Returns:
The string of joined elements.

join

public static <T> String join(char sep,
                              T[] arr,
                              int start_index)

Joins the elements in the provided array into a string. Null objects and empty strings are skipped.

Object.toString() is called on each element.

Type Parameters:
T - <T>.toString() called.
Parameters:
sep - What to insert between each element.
arr - The array of elements to join together.
start_index - The index of the first element to start joining from, to the end of the array.
Returns:
The string of joined elements.

join

public static <T> String join(char sep,
                              T[] arr,
                              int start_index,
                              int end_index)

Joins the elements in the provided array into a string. Null objects and empty strings are skipped.

Object.toString() is called on each element.

Type Parameters:
T - <T>.toString() called.
Parameters:
sep - What to insert between each element.
arr - The array of elements to join together.
start_index - The index of the first element to start joining from.
end_index - The index (exclusive) to stop joining at.
Returns:
The string of joined elements.

join

public static <T> String join(char sep,
                              Str.ToString<T> tos,
                              Iterable<T> it)

Joins the elements in the provided iterable into a string. Null objects and empty strings are skipped.

Str.ToString.toString(Object) is called on each element.

Type Parameters:
T -
Parameters:
sep - What to insert between each element.
tos - Convert each object to the desired string format.
it - The elements to join together.
Returns:
The string of joined elements.

join

public static <T> String join(char sep,
                              Str.ToString<T> tos,
                              Iterator<T> it)

Joins the elements in the provided iterator into a string. Null objects and empty strings are skipped.

Str.ToString.toString(Object) is called on each element.

Type Parameters:
T -
Parameters:
sep - What to insert between each element.
tos - Convert each object to the desired string format.
it - The elements to join together.
Returns:
The string of joined elements.

join

public static <T> String join(char sep,
                              Str.ToString<T> tos,
                              T... arr)

Joins the elements in the provided array into a string. Null objects and empty strings are skipped.

Str.ToString.toString(Object) is called on each element.

Type Parameters:
T -
Parameters:
sep - What to insert between each element.
tos - Convert each object to the desired string format.
arr - The array of elements to join together.
Returns:
The string of joined elements.

join

public static <T> String join(char sep,
                              Str.ToString<T> tos,
                              T[] arr,
                              int start_index)

Joins the elements in the provided array into a string. Null objects and empty strings are skipped.

Str.ToString.toString(Object) is called on each element.

Type Parameters:
T -
Parameters:
sep - What to insert between each element.
tos - Convert each object to the desired string format.
arr - The array of elements to join together.
start_index - The index of the first element to start joining from, to the end of the array.
Returns:
The string of joined elements.

join

public static <T> String join(char sep,
                              Str.ToString<T> tos,
                              T[] arr,
                              int start_index,
                              int end_index)

Joins the elements in the provided array into a string. Null objects and empty strings are skipped.

Str.ToString.toString(Object) is called on each element.

Type Parameters:
T -
Parameters:
sep - What to insert between each element.
tos - Convert each object to the desired string format.
arr - The array of elements to join together.
start_index - The index of the first element to start joining from.
end_index - The index (exclusive) to stop joining at.
Returns:
The string of joined elements.

join

public static <T> String join(String sep,
                              Iterable<T> it)

Joins the elements in the provided iterable into a string. Null objects and empty strings are skipped.

Object.toString() is called on each element.

Type Parameters:
T - <T>.toString() called.
Parameters:
sep - What to insert between each element.
it - The elements to join together.
Returns:
The string of joined elements.

join

public static <T> String join(String sep,
                              Iterator<T> it)

Joins the elements in the provided iterator into a string. Null objects and empty strings are skipped.

Object.toString() is called on each element.

Type Parameters:
T - <T>.toString() called.
Parameters:
sep - What to insert between each element.
it - The elements to join together.
Returns:
The string of joined elements.

join

public static <T> String join(String sep,
                              T... arr)

Joins the elements in the provided array into a string. Null objects and empty strings are skipped.

Object.toString() is called on each element.

Type Parameters:
T - <T>.toString() called.
Parameters:
sep - What to insert between each element.
arr - The array of elements to join together.
Returns:
The string of joined elements.

join

public static <T> String join(String sep,
                              T[] arr,
                              int start_index)

Joins the elements in the provided array into a string. Null objects and empty strings are skipped.

Object.toString() is called on each element.

Type Parameters:
T - <T>.toString() called.
Parameters:
sep - What to insert between each element.
arr - The array of elements to join together.
start_index - The index of the first element to start joining from, to the end of the array.
Returns:
The string of joined elements.

join

public static <T> String join(String sep,
                              T[] arr,
                              int start_index,
                              int end_index)

Joins the elements in the provided array into a string. Null objects and empty strings are skipped.

Object.toString() is called on each element.

Type Parameters:
T - <T>.toString() called.
Parameters:
sep - What to insert between each element.
arr - The array of elements to join together.
start_index - The index of the first element to start joining from.
end_index - The index (exclusive) to stop joining at.
Returns:
The string of joined elements.

join

public static <T> String join(String sep,
                              Str.ToString<T> tos,
                              Iterable<T> it)

Joins the elements in the provided iterable into a string. Null objects and empty strings are skipped.

Str.ToString.toString(Object) is called on each element.

Type Parameters:
T -
Parameters:
sep - What to insert between each element.
tos - Convert each object to the desired string format.
it - The elements to join together.
Returns:
The string of joined elements.

join

public static <T> String join(String sep,
                              Str.ToString<T> tos,
                              Iterator<T> it)

Joins the elements in the provided iterator into a string. Null objects and empty strings are skipped.

Str.ToString.toString(Object) is called on each element.

Type Parameters:
T -
Parameters:
sep - What to insert between each element.
tos - Convert each object to the desired string format.
it - The elements to join together.
Returns:
The string of joined elements.

join

public static <T> String join(String sep,
                              Str.ToString<T> tos,
                              T... arr)

Joins the elements in the provided array into a string. Null objects and empty strings are skipped.

Str.ToString.toString(Object) is called on each element.

Type Parameters:
T -
Parameters:
sep - What to insert between each element.
tos - Convert each object to the desired string format.
arr - The array of elements to join together.
Returns:
The string of joined elements.

join

public static <T> String join(String sep,
                              Str.ToString<T> tos,
                              T[] arr,
                              int start_index)

Joins the elements in the provided array into a string. Null objects and empty strings are skipped.

Str.ToString.toString(Object) is called on each element.

Type Parameters:
T -
Parameters:
sep - What to insert between each element.
tos - Convert each object to the desired string format.
arr - The array of elements to join together.
start_index - The index of the first element to start joining from, to the end of the array.
Returns:
The string of joined elements.

join

public static <T> String join(String sep,
                              Str.ToString<T> tos,
                              T[] arr,
                              int start_index,
                              int end_index)

Joins the elements in the provided array into a string. Null objects and empty strings are skipped.

Str.ToString.toString(Object) is called on each element.

Type Parameters:
T -
Parameters:
sep - What to insert between each element.
tos - Convert each object to the desired string format.
arr - The array of elements to join together.
start_index - The index of the first element to start joining from.
end_index - The index (exclusive) to stop joining at.
Returns:
The string of joined elements.

join

public static <T> StringBuilder join(StringBuilder buff,
                                     char sep,
                                     Iterable<T> it)

Appends the elements in the provided iterable onto a string builder. Null objects and empty strings are skipped.

Object.toString() is called on each element.

Type Parameters:
T - <T>.toString() called.
Parameters:
buff - The string builder to append to.
sep - What to insert between each element.
it - The elements to join together.
Returns:
The buff parameter.

join

public static <T> StringBuilder join(StringBuilder buff,
                                     char sep,
                                     Iterator<T> it)

Appends the elements in the provided iterator onto a string builder. Null objects and empty strings are skipped.

Object.toString() is called on each element.

Type Parameters:
T - <T>.toString() called.
Parameters:
buff - The string builder to append to.
sep - What to insert between each element.
it - The elements to join together.
Returns:
The buff parameter.

join

public static <T> StringBuilder join(StringBuilder buff,
                                     char sep,
                                     T... arr)

Appends the elements in the provided array onto a string builder. Null objects and empty strings are skipped.

Object.toString() is called on each element.

Type Parameters:
T - <T>.toString() called.
Parameters:
buff - The string builder to append to.
sep - What to insert between each element.
arr - The array of elements to join together.
Returns:
The buff parameter.

join

public static <T> StringBuilder join(StringBuilder buff,
                                     char sep,
                                     T[] arr,
                                     int start_index)

Appends the elements in the provided array onto a string builder. Null objects and empty strings are skipped.

Object.toString() is called on each element.

Type Parameters:
T - <T>.toString() called.
Parameters:
buff - The string builder to append to.
sep - What to insert between each element.
arr - The array of elements to join together.
start_index - The index of the first element to start joining from, to the end of the array.
Returns:
The buff parameter.

join

public static <T> StringBuilder join(StringBuilder buff,
                                     char sep,
                                     T[] arr,
                                     int start_index,
                                     int end_index)

Appends the elements in the provided array onto a string builder. Null objects and empty strings are skipped.

Object.toString() is called on each element.

Type Parameters:
T - <T>.toString() called.
Parameters:
buff - The string builder to append to.
sep - What to insert between each element.
arr - The array of elements to join together.
start_index - The index of the first element to start joining from.
end_index - The index (exclusive) to stop joining at.
Returns:
The buff parameter.

join

public static <T> StringBuilder join(StringBuilder buff,
                                     char sep,
                                     Str.ToString<T> tos,
                                     Iterable<T> it)

Appends the elements in the provided iterable onto a string builder. Null objects and empty strings are skipped.

Str.ToString.toString(Object) is called on each element.

Type Parameters:
T -
Parameters:
buff - The string builder to append to.
sep - What to insert between each element.
tos - Convert each object to the desired string format.
it - The elements to join together.
Returns:
The buff parameter.

join

public static <T> StringBuilder join(StringBuilder buff,
                                     char sep,
                                     Str.ToString<T> tos,
                                     Iterator<T> it)

Appends the elements in the provided iterator onto a string builder. Null objects and empty strings are skipped.

Str.ToString.toString(Object) is called on each element.

Type Parameters:
T -
Parameters:
buff - The string builder to append to.
sep - What to insert between each element.
tos - Convert each object to the desired string format.
it - The elements to join together.
Returns:
The buff parameter.

join

public static <T> StringBuilder join(StringBuilder buff,
                                     char sep,
                                     Str.ToString<T> tos,
                                     T... arr)

Appends the elements in the provided array onto a string builder. Null objects and empty strings are skipped.

Str.ToString.toString(Object) is called on each element.

Type Parameters:
T -
Parameters:
buff - The string builder to append to.
sep - What to insert between each element.
tos - Convert each object to the desired string format.
arr - The array of elements to join together.
Returns:
The buff parameter.

join

public static <T> StringBuilder join(StringBuilder buff,
                                     char sep,
                                     Str.ToString<T> tos,
                                     T[] arr,
                                     int start_index)

Appends the elements in the provided array onto a string builder. Null objects and empty strings are skipped.

Str.ToString.toString(Object) is called on each element.

Type Parameters:
T -
Parameters:
buff - The string builder to append to.
sep - What to insert between each element.
tos - Convert each object to the desired string format.
arr - The array of elements to join together.
start_index - The index of the first element to start joining from, to the end of the array.
Returns:
The buff parameter.

join

public static <T> StringBuilder join(StringBuilder buff,
                                     char sep,
                                     Str.ToString<T> tos,
                                     T[] arr,
                                     int start_index,
                                     int end_index)

Appends the elements in the provided array onto a string builder. Null objects and empty strings are skipped.

Str.ToString.toString(Object) is called on each element.

Type Parameters:
T -
Parameters:
buff - The string builder to append to.
sep - What to insert between each element.
tos - Convert each object to the desired string format.
arr - The array of elements to join together.
start_index - The index of the first element to start joining from.
end_index - The index (exclusive) to stop joining at.
Returns:
The buff parameter.

join

public static <T> StringBuilder join(StringBuilder buff,
                                     String sep,
                                     Iterable<T> it)

Appends the elements in the provided iterable onto a string builder. Null objects and empty strings are skipped.

Object.toString() is called on each element.

Type Parameters:
T - <T>.toString() called.
Parameters:
buff - The string builder to append to.
sep - What to insert between each element.
it - The elements to join together.
Returns:
The buff parameter.

join

public static <T> StringBuilder join(StringBuilder buff,
                                     String sep,
                                     Iterator<T> it)

Appends the elements in the provided iterator onto a string builder. Null objects and empty strings are skipped.

Object.toString() is called on each element.

Type Parameters:
T - <T>.toString() called.
Parameters:
buff - The string builder to append to.
sep - What to insert between each element.
it - The elements to join together.
Returns:
The buff parameter.

join

public static <T> StringBuilder join(StringBuilder buff,
                                     String sep,
                                     T... arr)

Appends the elements in the provided array onto a string builder. Null objects and empty strings are skipped.

Object.toString() is called on each element.

Type Parameters:
T - <T>.toString() called.
Parameters:
buff - The string builder to append to.
sep - What to insert between each element.
arr - The array of elements to join together.
Returns:
The buff parameter.

join

public static <T> StringBuilder join(StringBuilder buff,
                                     String sep,
                                     T[] arr,
                                     int start_index)

Appends the elements in the provided array onto a string builder. Null objects and empty strings are skipped.

Object.toString() is called on each element.

Type Parameters:
T - <T>.toString() called.
Parameters:
buff - The string builder to append to.
sep - What to insert between each element.
arr - The array of elements to join together.
start_index - The index of the first element to start joining from, to the end of the array.
Returns:
The buff parameter.

join

public static <T> StringBuilder join(StringBuilder buff,
                                     String sep,
                                     T[] arr,
                                     int start_index,
                                     int end_index)

Appends the elements in the provided array onto a string builder. Null objects and empty strings are skipped.

Object.toString() is called on each element.

Type Parameters:
T - <T>.toString() called.
Parameters:
buff - The string builder to append to.
sep - What to insert between each element.
arr - The array of elements to join together.
start_index - The index of the first element to start joining from.
end_index - The index (exclusive) to stop joining at.
Returns:
The buff parameter.

join

public static <T> StringBuilder join(StringBuilder buff,
                                     String sep,
                                     Str.ToString<T> tos,
                                     Iterable<T> it)

Appends the elements in the provided iterable onto a string builder. Null objects and empty strings are skipped.

Str.ToString.toString(Object) is called on each element.

Type Parameters:
T -
Parameters:
buff - The string builder to append to.
sep - What to insert between each element.
tos - Convert each object to the desired string format.
it - The elements to join together.
Returns:
The buff parameter.

join

public static <T> StringBuilder join(StringBuilder buff,
                                     String sep,
                                     Str.ToString<T> tos,
                                     Iterator<T> it)

Appends the elements in the provided iterator onto a string builder. Null objects and empty strings are skipped.

Str.ToString.toString(Object) is called on each element.

Type Parameters:
T -
Parameters:
buff - The string builder to append to.
sep - What to insert between each element.
tos - Convert each object to the desired string format.
it - The elements to join together.
Returns:
The buff parameter.

join

public static <T> StringBuilder join(StringBuilder buff,
                                     String sep,
                                     Str.ToString<T> tos,
                                     T... arr)

Appends the elements in the provided array onto a string builder. Null objects and empty strings are skipped.

Str.ToString.toString(Object) is called on each element.

Type Parameters:
T -
Parameters:
buff - The string builder to append to.
sep - What to insert between each element.
tos - Convert each object to the desired string format.
arr - The array of elements to join together.
Returns:
The buff parameter.

join

public static <T> StringBuilder join(StringBuilder buff,
                                     String sep,
                                     Str.ToString<T> tos,
                                     T[] arr,
                                     int start_index)

Appends the elements in the provided array onto a string builder. Null objects and empty strings are skipped.

Str.ToString.toString(Object) is called on each element.

Type Parameters:
T -
Parameters:
buff - The string builder to append to.
sep - What to insert between each element.
tos - Convert each object to the desired string format.
arr - The array of elements to join together.
start_index - The index of the first element to start joining from, to the end of the array.
Returns:
The buff parameter.

join

public static <T> StringBuilder join(StringBuilder buff,
                                     String sep,
                                     Str.ToString<T> tos,
                                     T[] arr,
                                     int start_index,
                                     int end_index)

Appends the elements in the provided array onto a string builder. Null objects and empty strings are skipped.

Str.ToString.toString(Object) is called on each element.

Type Parameters:
T -
Parameters:
buff - The string builder to append to.
sep - What to insert between each element.
tos - Convert each object to the desired string format.
arr - The array of elements to join together.
start_index - The index of the first element to start joining from.
end_index - The index (exclusive) to stop joining at.
Returns:
The buff parameter.

length

public static int length(CharSequence str)
Return the length of the string, or zero if passed a null.

Parameters:
str -
Returns:
Return the length of the string, or zero if passed a null.

ltrim

public static StringBuilder ltrim(StringBuilder buff)

Trims the string builder contents of any leading whitespace.

See note above for our definition of whitespace.

Parameters:
buff -
Returns:
Returns buff.

ltrimToEmpty

public static String ltrimToEmpty(String str)

Trims the string of any leading whitespace, but also returns a zero length string if the parameter was null. Does not allocate a new string if it does not need to.

See note above for our definition of whitespace.

Parameters:
str -
Returns:
Return the trimmed string. If str was null then return a zero length string.

ltrimToNull

public static String ltrimToNull(String str)

Trims the string of any leading whitespace, returning null if the result is a zero length string, or the parameter was null to begin with. Does not allocate a new string if it does not need to.

See note above for our definition of whitespace.

Parameters:
str -
Returns:
Return the trimmed string, or null if str was null or the result is a zero length string.

notEquals

public static boolean notEquals(String lhs,
                                String rhs)
Compares two strings, handling nulls.
 Str.equals(null, null) = false
 Str.equals(null, "") = true
 Str.equals("", "") = false
 Str.equals("", " ") = true
 Str.equals("abc", "abc") = false
 Str.equals("abc", "ABC") = true
 Str.equals("abc", "def") = true
 

Parameters:
lhs -
rhs -
Returns:
True if both parameters are null, or lhs.equals(rhs) returns true.

notEqualsIgnoreCase

public static boolean notEqualsIgnoreCase(String lhs,
                                          String rhs)
Compares two strings in a case insensitive manner, handling nulls.
 Str.equals(null, null) = false
 Str.equals(null, "") = true
 Str.equals("", "") = false
 Str.equals("", " ") = true
 Str.equals("abc", "abc") = false
 Str.equals("abc", "ABC") = false
 Str.equals("abc", "def") = true
 

Parameters:
lhs -
rhs -
Returns:
True if both parameters are null, or lhs.equalsIgnoreCase(rhs) returns true.

replace

public static String replace(String orig,
                             int start,
                             int end,
                             String replace)
Replace a range of text within a string with a new string.

Parameters:
orig - The original string to perform the replacement on.
start - The start of the range (inclusive).
end - The end of the range (exclusive).
replace - The string to put in place of the specified range.
Returns:
The string with the replaced range.

rtrim

public static StringBuilder rtrim(StringBuilder buff)

Trims the string builder contents of any trailing whitespace.

See note above for our definition of whitespace.

Parameters:
buff -
Returns:
Returns buff.

rtrimToEmpty

public static String rtrimToEmpty(String str)

Trims the string of any trailing whitespace, but also returns a zero length string if the parameter was null. Does not allocate a new string if it does not need to.

See note above for our definition of whitespace.

Parameters:
str -
Returns:
Return the trimmed string. If str was null then return a zero length string.

rtrimToNull

public static String rtrimToNull(String str)

Trims the string of any trailing whitespace, returning null if the result is a zero length string, or the parameter was null to begin with. Does not allocate a new string if it does not need to.

See note above for our definition of whitespace.

Parameters:
str -
Returns:
Return the trimmed string, or null if str was null or the result is a zero length string.

split

public static String[] split(Pattern regex,
                             CharSequence str)

Splits a string on a regular expression.

This works as if you called split(Pattern, CharSequence, int) with a limit of zero.

Parameters:
regex - The regular expression to split the strong on.
str - The string to split.
Returns:
The array of strings computed by splitting the input around matches of the given regular expression.

split

public static String[] split(Pattern regex,
                             CharSequence str,
                             boolean trim,
                             boolean remove_blank_lines)

Splits a string on a regular expression, providing various cleanups such as trimming and elimination of blank lines.

This works as if you called split(Pattern, CharSequence, int, boolean, boolean) with a limit of zero.

Parameters:
regex - The regular expression to split the strong on.
str - The string to split.
trim - If true, trims each string in the array of leading and trailing whitespace.
remove_blank_lines - If true, removes any strings out of the array that only contain whitespace, shortening the length of the array.
Returns:
The array of strings computed by splitting the input around matches of the given regular expression.

split

public static String[] split(Pattern regex,
                             CharSequence str,
                             int limit)

Splits a string on a regular expression.

The limit parameter controls the number of times the pattern is applied and therefore affects the length of the resulting array. If the limit n is greater than zero then the pattern will be applied at most n - 1 times, the array's length will be no greater than n, and the array's last entry will contain all input beyond the last matched delimiter. If n is non-positive then the pattern will be applied as many times as possible and the array can have any length. If n is zero then the pattern will be applied as many times as possible, the array can have any length, and trailing empty strings will be discarded.

Parameters:
regex - The regular expression to split the strong on.
str - The string to split.
limit - The result threshold, as described above.
Returns:
The array of strings computed by splitting the input around matches of the given regular expression.

split

public static String[] split(Pattern regex,
                             CharSequence str,
                             int limit,
                             boolean trim,
                             boolean remove_blank_lines)

Splits a string on a regular expression, providing various cleanups such as trimming and elimination of blank lines.

The limit parameter controls the number of times the pattern is applied and therefore affects the length of the resulting array. If the limit n is greater than zero then the pattern will be applied at most n - 1 times, the array's length will be no greater than n, and the array's last entry will contain all input beyond the last matched delimiter. If n is non-positive then the pattern will be applied as many times as possible and the array can have any length. If n is zero then the pattern will be applied as many times as possible, the array can have any length, and trailing empty strings will be discarded.

Parameters:
regex - The regular expression to split the strong on.
str - The string to split.
limit - The result threshold, as described above.
trim - If true, trims each string in the array of leading and trailing whitespace.
remove_blank_lines - If true, removes any strings out of the array that only contain whitespace, shortening the length of the array.
Returns:
The array of strings computed by splitting the input around matches of the given regular expression.

splitLines

public static String[] splitLines(CharSequence str)

Splits a string on a newlines.

A newline is represented by one of "\n", " \r", or "\r\n".

This works as if you called splitLines(CharSequence, int) with a limit of zero.

Parameters:
str - The string to split.
Returns:
The array of strings computed by splitting the input around newlines.

splitLines

public static String[] splitLines(CharSequence str,
                                  boolean trim,
                                  boolean remove_blank_lines)

Splits a string on a newlines, providing various cleanups such as trimming and elimination of blank lines.

A newline is represented by one of "\n", " \r", or "\r\n".

This works as if you called splitLines(CharSequence, int, boolean, boolean) with a limit of zero.

Parameters:
str - The string to split.
trim - If true, trims each string in the array of leading and trailing whitespace.
remove_blank_lines - If true, removes any strings out of the array that only contain whitespace, shortening the length of the array.
Returns:
The array of strings computed by splitting the input around newlines.

splitLines

public static String[] splitLines(CharSequence str,
                                  int limit)

Splits a string on a newlines.

A newline is represented by one of "\n", " \r", or "\r\n".

The limit parameter controls the number of times the pattern is applied and therefore affects the length of the resulting array. If the limit n is greater than zero then the pattern will be applied at most n - 1 times, the array's length will be no greater than n, and the array's last entry will contain all input beyond the last matched delimiter. If n is non-positive then the pattern will be applied as many times as possible and the array can have any length. If n is zero then the pattern will be applied as many times as possible, the array can have any length, and trailing empty strings will be discarded.

Parameters:
str - The string to split.
limit - The result threshold, as described above.
Returns:
The array of strings computed by splitting the input around newlines.

splitLines

public static String[] splitLines(CharSequence str,
                                  int limit,
                                  boolean trim,
                                  boolean remove_blank_lines)

Splits a string on a newlines, providing various cleanups such as trimming and elimination of blank lines.

A newline is represented by one of "\n", " \r", or "\r\n".

The limit parameter controls the number of times the pattern is applied and therefore affects the length of the resulting array. If the limit n is greater than zero then the pattern will be applied at most n - 1 times, the array's length will be no greater than n, and the array's last entry will contain all input beyond the last matched delimiter. If n is non-positive then the pattern will be applied as many times as possible and the array can have any length. If n is zero then the pattern will be applied as many times as possible, the array can have any length, and trailing empty strings will be discarded.

Parameters:
str - The string to split.
limit - The result threshold, as described above.
trim - If true, trims each string in the array of leading and trailing whitespace.
remove_blank_lines - If true, removes any strings out of the array that only contain whitespace, shortening the length of the array.
Returns:
The array of strings computed by splitting the input around newlines.

splitStackTrace

public static String[] splitStackTrace(Throwable ex)

Takes what would normally be output from Throwable.printStackTrace() and breaks it into an array of Strings (one per line).

Parameters:
ex - The exception to process.
Returns:
The array of strings.

startsWithIgnoreCase

public static boolean startsWithIgnoreCase(String str,
                                           String prefix)
Tests if the string starts with the specified prefix, ignoring case. This is really just a thin wrapper around String.regionMatches(boolean, int, String, int, int) that calculates the right offsets.

Parameters:
str - The string to check.
prefix - The prefix.
Returns:
Returns true if str starts with prefix, ignoring case. Note that the result will be true if prefix is an empty string or is equal to str as determined by the equalsIgnoreCase(Object) method.

startsWithIgnoreCase

public static boolean startsWithIgnoreCase(String str,
                                           String prefix,
                                           int toffset)
Tests if the string starts with the specified prefix, ignoring case. This is really just a thin wrapper around String.regionMatches(boolean, int, String, int, int) that calculates the right offsets.

Parameters:
str - The string to check.
prefix - The prefix.
toffset - The position in str to start comparison from.
Returns:
Returns true if str starts with prefix, ignoring case. Note that the result will be true if prefix is an empty string or is equal to str as determined by the equalsIgnoreCase(Object) method.

trim

public static StringBuilder trim(StringBuilder buff)

Trims the string builder contents of any leading and trailing whitespace.

See note above for our definition of whitespace.

Parameters:
buff -
Returns:
Returns buff.

trimToEmpty

public static String trimToEmpty(String str)

Trims the string of any leading and trailing whitespace, but also returns a zero length string if the parameter was null. Does not allocate a new string if it does not need to.

See note above for our definition of whitespace.

Parameters:
str -
Returns:
Return the trimmed string. If str was null then return a zero length string.

trimToNull

public static String trimToNull(String str)

Trims the string of any leading and trailing whitespace, returning null if the result is a zero length string, or the parameter was null to begin with. Does not allocate a new string if it does not need to.

See note above for our definition of whitespace.

Parameters:
str -
Returns:
Return the trimmed string, or null if str was null or the result is a zero length string.