|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.evanmclean.evlib.lang.Str
public final class Str
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.
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
|
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
|
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
|
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
|
join(char sep,
Iterable<T> it)
Joins the elements in the provided iterable into a string. |
|
static
|
join(char sep,
Iterator<T> it)
Joins the elements in the provided iterator into a string. |
|
static
|
join(char sep,
Str.ToString<T> tos,
Iterable<T> it)
Joins the elements in the provided iterable into a string. |
|
static
|
join(char sep,
Str.ToString<T> tos,
Iterator<T> it)
Joins the elements in the provided iterator into a string. |
|
static
|
join(char sep,
Str.ToString<T> tos,
T... arr)
Joins the elements in the provided array into a string. |
|
static
|
join(char sep,
Str.ToString<T> tos,
T[] arr,
int start_index)
Joins the elements in the provided array into a string. |
|
static
|
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
|
join(char sep,
T... arr)
Joins the elements in the provided array into a string. |
|
static
|
join(char sep,
T[] arr,
int start_index)
Joins the elements in the provided array into a string. |
|
static
|
join(char sep,
T[] arr,
int start_index,
int end_index)
Joins the elements in the provided array into a string. |
|
static
|
join(StringBuilder buff,
char sep,
Iterable<T> it)
Appends the elements in the provided iterable onto a string builder. |
|
static
|
join(StringBuilder buff,
char sep,
Iterator<T> it)
Appends the elements in the provided iterator onto a string builder. |
|
static
|
join(StringBuilder buff,
char sep,
Str.ToString<T> tos,
Iterable<T> it)
Appends the elements in the provided iterable onto a string builder. |
|
static
|
join(StringBuilder buff,
char sep,
Str.ToString<T> tos,
Iterator<T> it)
Appends the elements in the provided iterator onto a string builder. |
|
static
|
join(StringBuilder buff,
char sep,
Str.ToString<T> tos,
T... arr)
Appends the elements in the provided array onto a string builder. |
|
static
|
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
|
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
|
join(StringBuilder buff,
char sep,
T... arr)
Appends the elements in the provided array onto a string builder. |
|
static
|
join(StringBuilder buff,
char sep,
T[] arr,
int start_index)
Appends the elements in the provided array onto a string builder. |
|
static
|
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
|
join(StringBuilder buff,
String sep,
Iterable<T> it)
Appends the elements in the provided iterable onto a string builder. |
|
static
|
join(StringBuilder buff,
String sep,
Iterator<T> it)
Appends the elements in the provided iterator onto a string builder. |
|
static
|
join(StringBuilder buff,
String sep,
Str.ToString<T> tos,
Iterable<T> it)
Appends the elements in the provided iterable onto a string builder. |
|
static
|
join(StringBuilder buff,
String sep,
Str.ToString<T> tos,
Iterator<T> it)
Appends the elements in the provided iterator onto a string builder. |
|
static
|
join(StringBuilder buff,
String sep,
Str.ToString<T> tos,
T... arr)
Appends the elements in the provided array onto a string builder. |
|
static
|
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
|
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
|
join(StringBuilder buff,
String sep,
T... arr)
Appends the elements in the provided array onto a string builder. |
|
static
|
join(StringBuilder buff,
String sep,
T[] arr,
int start_index)
Appends the elements in the provided array onto a string builder. |
|
static
|
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
|
join(String sep,
Iterable<T> it)
Joins the elements in the provided iterable into a string. |
|
static
|
join(String sep,
Iterator<T> it)
Joins the elements in the provided iterator into a string. |
|
static
|
join(String sep,
Str.ToString<T> tos,
Iterable<T> it)
Joins the elements in the provided iterable into a string. |
|
static
|
join(String sep,
Str.ToString<T> tos,
Iterator<T> it)
Joins the elements in the provided iterator into a string. |
|
static
|
join(String sep,
Str.ToString<T> tos,
T... arr)
Joins the elements in the provided array into a string. |
|
static
|
join(String sep,
Str.ToString<T> tos,
T[] arr,
int start_index)
Joins the elements in the provided array into a string. |
|
static
|
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
|
join(String sep,
T... arr)
Joins the elements in the provided array into a string. |
|
static
|
join(String sep,
T[] arr,
int start_index)
Joins the elements in the provided array into a string. |
|
static
|
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 |
---|
public static final String EMPTY
Method Detail |
---|
public static boolean endsWithIgnoreCase(String str, String suffix)
String.regionMatches(boolean, int, String, int, int)
that
calculates the right offsets.
str
- The string to check.suffix
- The suffix.
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.public static boolean equals(String lhs, String rhs)
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
lhs
- rhs
-
null
, or
lhs.equals(rhs)
returns true
.public static boolean equalsIgnoreCase(String lhs, String rhs)
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
lhs
- rhs
-
null
, or
lhs.equalsIgnoreCase(rhs)
returns true
.public static boolean equalsOneOf(String lhs, String... rhs)
lhs.equals()
for each of the other strings until one of
them returns true.
lhs
- The string to compare.rhs
- One or more string to compare against for equality.
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
.public static boolean equalsOneOfIgnoreCase(String lhs, String... rhs)
lhs.equalsIgnoreCase()
for each of the other strings
until one of them returns true.
lhs
- The string to compare.rhs
- One or more string to compare against for equality.
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
.public static String getStackTrace(Throwable ex)
Takes what would normally be output from
Throwable.printStackTrace()
and returns it as a string.
ex
- The exception to process.
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.
T
- Anything that implements CharSequence
(such as
Str.ToString
s).str
- alt
-
str
parameter if it is not null
,
zero length, and contains at least one non-whitespace character, otherwise return
alt
.public static <T extends CharSequence> T ifEmpty(T str, T alt)
null
or a zero length
string, otherwise return the second parameter.
T
- Anything that implements CharSequence
(such as
Str.ToString
s).str
- alt
-
str
if it is not null
or a zero
length string, otherwise return alt
.public static String ifNull(String str)
null
, otherwise return an
empty string.
str
-
str
if it is not null
, otherwise
return an empty string.public static <T extends CharSequence> T ifNull(T str, T alt)
null
, otherwise return
the second parameter.
T
- Anything that implements CharSequence
(such as
Str.ToString
s).str
- alt
-
str
if it is not null
, otherwise
return alt
.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.
str
-
true
if the parameter is null
,
zero length, or only contains whitespace.public static boolean isEmpty(CharSequence str)
true
if the parameter is null
or a zero
length string.
str
-
true
if the parameter is null
or
a zero length string.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.
str
-
true
if the parameter is not null
, not zero length, and contains at least one non-whitespace character.public static boolean isNotEmpty(CharSequence str)
true
if the parameter is not null
and not
a zero length string.
str
-
true
if the parameter is not null
and not a zero length string.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.
T
- <T>.toString()
called.sep
- What to insert between each element.it
- The elements to join together.
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.
T
- <T>.toString()
called.sep
- What to insert between each element.it
- The elements to join together.
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.
T
- <T>.toString()
called.sep
- What to insert between each element.arr
- The array of elements to join together.
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.
T
- <T>.toString()
called.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.
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.
T
- <T>.toString()
called.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.
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.
T
- sep
- What to insert between each element.tos
- Convert each object to the desired string format.it
- The elements to join together.
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.
T
- sep
- What to insert between each element.tos
- Convert each object to the desired string format.it
- The elements to join together.
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.
T
- sep
- What to insert between each element.tos
- Convert each object to the desired string format.arr
- The array of elements to join together.
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.
T
- 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.
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.
T
- 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.
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.
T
- <T>.toString()
called.sep
- What to insert between each element.it
- The elements to join together.
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.
T
- <T>.toString()
called.sep
- What to insert between each element.it
- The elements to join together.
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.
T
- <T>.toString()
called.sep
- What to insert between each element.arr
- The array of elements to join together.
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.
T
- <T>.toString()
called.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.
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.
T
- <T>.toString()
called.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.
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.
T
- sep
- What to insert between each element.tos
- Convert each object to the desired string format.it
- The elements to join together.
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.
T
- sep
- What to insert between each element.tos
- Convert each object to the desired string format.it
- The elements to join together.
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.
T
- sep
- What to insert between each element.tos
- Convert each object to the desired string format.arr
- The array of elements to join together.
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.
T
- 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.
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.
T
- 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.
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.
T
- <T>.toString()
called.buff
- The string builder to append to.sep
- What to insert between each element.it
- The elements to join together.
buff
parameter.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.
T
- <T>.toString()
called.buff
- The string builder to append to.sep
- What to insert between each element.it
- The elements to join together.
buff
parameter.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.
T
- <T>.toString()
called.buff
- The string builder to append to.sep
- What to insert between each element.arr
- The array of elements to join together.
buff
parameter.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.
T
- <T>.toString()
called.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.
buff
parameter.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.
T
- <T>.toString()
called.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.
buff
parameter.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.
T
- 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.
buff
parameter.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.
T
- 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.
buff
parameter.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.
T
- 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.
buff
parameter.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.
T
- 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.
buff
parameter.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.
T
- 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.
buff
parameter.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.
T
- <T>.toString()
called.buff
- The string builder to append to.sep
- What to insert between each element.it
- The elements to join together.
buff
parameter.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.
T
- <T>.toString()
called.buff
- The string builder to append to.sep
- What to insert between each element.it
- The elements to join together.
buff
parameter.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.
T
- <T>.toString()
called.buff
- The string builder to append to.sep
- What to insert between each element.arr
- The array of elements to join together.
buff
parameter.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.
T
- <T>.toString()
called.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.
buff
parameter.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.
T
- <T>.toString()
called.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.
buff
parameter.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.
T
- 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.
buff
parameter.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.
T
- 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.
buff
parameter.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.
T
- 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.
buff
parameter.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.
T
- 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.
buff
parameter.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.
T
- 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.
buff
parameter.public static int length(CharSequence str)
null
.
str
-
null
.public static StringBuilder ltrim(StringBuilder buff)
Trims the string builder contents of any leading whitespace.
See note above for our definition of whitespace.
buff
-
buff
.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.
str
-
str
was
null
then return a zero length string.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.
str
-
null
if str
was null
or the result is a zero length string.public static boolean notEquals(String lhs, String rhs)
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
lhs
- rhs
-
null
, or
lhs.equals(rhs)
returns true
.public static boolean notEqualsIgnoreCase(String lhs, String rhs)
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
lhs
- rhs
-
null
, or
lhs.equalsIgnoreCase(rhs)
returns true
.public static String replace(String orig, int start, int end, String replace)
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.
public static StringBuilder rtrim(StringBuilder buff)
Trims the string builder contents of any trailing whitespace.
See note above for our definition of whitespace.
buff
-
buff
.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.
str
-
str
was
null
then return a zero length string.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.
str
-
null
if str
was null
or the result is a zero length string.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.
regex
- The regular expression to split the strong on.str
- The string to 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.
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.
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.
regex
- The regular expression to split the strong on.str
- The string to split.limit
- The result threshold, as described above.
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.
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.
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.
str
- The string to split.
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.
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.
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.
str
- The string to split.limit
- The result threshold, as described above.
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.
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.
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).
ex
- The exception to process.
public static boolean startsWithIgnoreCase(String str, String prefix)
String.regionMatches(boolean, int, String, int, int)
that
calculates the right offsets.
str
- The string to check.prefix
- The prefix.
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.public static boolean startsWithIgnoreCase(String str, String prefix, int toffset)
String.regionMatches(boolean, int, String, int, int)
that
calculates the right offsets.
str
- The string to check.prefix
- The prefix.toffset
- The position in str
to start comparison from.
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.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.
buff
-
buff
.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.
str
-
str
was
null
then return a zero length string.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.
str
-
null
if str
was null
or the result is a zero length string.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |