public final class StringUtilities
extends java.lang.Object
(This is a cut-down version of the same class in ph-commons-util.)
| 限定符和类型 | 字段和说明 |
|---|---|
static java.lang.String[] |
EMPTY_STRING_ARRAY
Shared instance of an empty array of Strings, which is sometimes useful!
|
| 构造器和说明 |
|---|
StringUtilities() |
| 限定符和类型 | 方法和说明 |
|---|---|
static java.lang.String |
emptyIfNull(java.lang.String string)
Convenience method that turns a String to an empty String ("") if it is null.
|
static boolean |
fromBinaryValues(java.lang.String value,
java.lang.String trueValue,
java.lang.String falseValue)
Converts the given String argument to a boolean using
the scheme trueValue => true, falseValue => false.
|
static boolean |
fromTrueFalse(java.lang.String value)
Converts the given String argument to a boolean using
the scheme "true"=>true, "false"=>false.
|
static boolean |
fromYesNo(java.lang.String value)
Converts the given String argument to a boolean using
the scheme "yes"=>true, "no"=>false.
|
static boolean |
isNullOrEmpty(java.lang.String string)
Tests whether the given String is null or empty ("").
|
static java.lang.String |
join(java.lang.Iterable<? extends java.lang.Object> objects,
java.lang.CharSequence separator)
Joins the given collection of Objects using the given
separator and each Object's normal toString() method.
|
static java.lang.String |
join(java.lang.Object[] objects,
java.lang.CharSequence separator)
Same as
join(Iterable, CharSequence) but simply takes an array
of Objects. |
static java.lang.String |
join(java.lang.Object[] objects,
java.lang.CharSequence separator,
int startIndex,
int endIndex)
Version of
join(Object[], CharSequence) that allows you to specify a range of
indices in the array to join. |
static void |
join(java.lang.StringBuilder resultBuilder,
java.lang.Object[] objects,
java.lang.CharSequence separator)
Version of
join(Object[], CharSequence) that allows you to pass in
a StringBuilder that the result will be built up in. |
static void |
join(java.lang.StringBuilder resultBuilder,
java.lang.Object[] objects,
java.lang.CharSequence separator,
int startIndex,
int endIndex)
Version of
join(Object[], CharSequence, int, int) that allows you to pass in
a StringBuilder that the result will be built up in. |
static java.lang.String |
nullIfEmpty(java.lang.String string)
Convenience method that turns a String to null if it is empty (i.e. "") or null.
|
static java.lang.String |
toTrueFalse(boolean state)
Trivial helper method to convert a boolean into either
"true" or "false" depending on its state.
|
static java.lang.String |
toYesNo(boolean state)
Trivial helper method to convert a boolean into either
"yes" or "no" depending on its state.
|
public static final java.lang.String[] EMPTY_STRING_ARRAY
public static java.lang.String join(java.lang.Iterable<? extends java.lang.Object> objects,
java.lang.CharSequence separator)
For example, joining the collection "a", "b", "c" with "/" gives "a/b/c".
objects - collection of Objects to joinseparator - separator to usepublic static java.lang.String join(java.lang.Object[] objects,
java.lang.CharSequence separator)
join(Iterable, CharSequence) but simply takes an array
of Objects.objects - array of Objects to joinseparator - separator to usepublic static void join(java.lang.StringBuilder resultBuilder,
java.lang.Object[] objects,
java.lang.CharSequence separator)
join(Object[], CharSequence) that allows you to pass in
a StringBuilder that the result will be built up in. This is useful if you need
to do add in other stuff later on.resultBuilder - StringBuilder to append results toobjects - array of Objects to joinseparator - separator to usepublic static java.lang.String join(java.lang.Object[] objects,
java.lang.CharSequence separator,
int startIndex,
int endIndex)
join(Object[], CharSequence) that allows you to specify a range of
indices in the array to join. This can be useful in some cases.objects - array of Objects to joinseparator - separator to usestartIndex - first index to joinendIndex - index after last one to joinpublic static void join(java.lang.StringBuilder resultBuilder,
java.lang.Object[] objects,
java.lang.CharSequence separator,
int startIndex,
int endIndex)
join(Object[], CharSequence, int, int) that allows you to pass in
a StringBuilder that the result will be built up in. This is useful if you need
to do add in other stuff later on.resultBuilder - StringBuilder to append results toobjects - array of Objects to joinseparator - separator to usestartIndex - first index to joinendIndex - index after last one to joinpublic static boolean isNullOrEmpty(java.lang.String string)
public static java.lang.String nullIfEmpty(java.lang.String string)
string - public static java.lang.String emptyIfNull(java.lang.String string)
string - public static java.lang.String toYesNo(boolean state)
state - boolean to convertpublic static java.lang.String toTrueFalse(boolean state)
state - boolean to convertpublic static boolean fromYesNo(java.lang.String value)
value - java.lang.IllegalArgumentException - if value if null or
neither "yes" or "no"public static boolean fromTrueFalse(java.lang.String value)
value - java.lang.IllegalArgumentException - if value if null or
neither "yes" or "no"public static boolean fromBinaryValues(java.lang.String value,
java.lang.String trueValue,
java.lang.String falseValue)
value - trueValue - value returning truefalseValue - value returning falsejava.lang.IllegalArgumentException - if value if null or
neither trueValue nor falseValue