public class StringUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
LONG_TIME_FORMAT
Format string used for long time expressions which include hours.
|
static java.lang.String |
SHORT_TIME_FORMAT
Format string used for short time expressions which are less than an hour.
|
static java.lang.String |
SHORTER_TIME_FORMAT
Format string used for short time expressions which are less than ten minutes.
|
Constructor and Description |
---|
StringUtil() |
Modifier and Type | Method and Description |
---|---|
static boolean |
isEmpty(java.lang.String str)
Determines if given string is empty or null.
|
static java.lang.String |
join(java.util.List<java.lang.String> stringsToJoin,
java.lang.String separator)
Joins the Strings in the given List together into a single String using the specified separator String.
|
static java.lang.String |
join(java.lang.String[] stringsToJoin,
java.lang.String separator)
Joins the Strings in the given array together into a single String using the specified separator String.
|
static java.lang.CharSequence |
replaceAll(java.lang.CharSequence template,
java.lang.String[] sources,
java.lang.CharSequence[] destinations)
This method is based on Android's
TextUtils.replace(CharSequence, String[], CharSequence[]) and extends
its functionality by replacing all instances of each String specified in the sources parameter
with the associated destination CharSequence. |
static java.lang.String |
stringForTime(long milliseconds)
Formats the given time duration value (in milliseconds) as a time string in one of the following formats:
HH:MM:SS where the timeframe is greater than 1 hour
MM:SS where the timeframe is less than an hour
M:SS where the timeframe is less than ten minutes
|
public static final java.lang.String LONG_TIME_FORMAT
public static final java.lang.String SHORT_TIME_FORMAT
public static final java.lang.String SHORTER_TIME_FORMAT
public static boolean isEmpty(java.lang.String str)
str
- the String to evaluatepublic static java.lang.String join(java.util.List<java.lang.String> stringsToJoin, java.lang.String separator)
stringsToJoin
- the List of Strings to joinseparator
- the String to be inserted between each element of the arraypublic static java.lang.String stringForTime(long milliseconds)
milliseconds
- the time duration to format, in millisecondspublic static java.lang.String join(java.lang.String[] stringsToJoin, java.lang.String separator)
stringsToJoin
- the array of Strings to joinseparator
- the String to be inserted between each element of the arraypublic static java.lang.CharSequence replaceAll(java.lang.CharSequence template, java.lang.String[] sources, java.lang.CharSequence[] destinations)
TextUtils.replace(CharSequence, String[], CharSequence[])
and extends
its functionality by replacing all instances of each String specified in the sources parameter
with the associated destination CharSequence.
It is important to note that this exists for CharSequences (which are not necessarily Strings) that have
Spanned
portions and for which the relevant spans must be maintained. If we were to use
String.replaceAll(String, String)
in cases such as these, the span information would be lost.template
- the CharSequence on which we should perform replacementssources
- an Array of Strings to find and replace in templatedestinations
- an Array of CharSequences corresponding to the sources strings which will serve as replacementsTextUtils.replace(CharSequence, String[], CharSequence[])