|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.xins.common.text.TextUtils
Text-related utility functions.
Method Summary | |
static boolean |
isEmpty(String s)
Determines if the specified string is null or an empty
string. |
static String |
quote(Object o)
Quotes the textual presentation (returned by toString() ) of
the specified object, or returns "(null)" if the object is
null . |
static String |
quote(String s)
Quotes the specified string, or returns "(null)" if it is
null . |
static String |
replace(String s,
Properties replacements,
String prefix,
String suffix)
Replaces substrings in a string. |
static String |
trim(String s,
String ifEmpty)
Trims the specified string, or returns an empty string if the argument is null . |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
public static String quote(String s)
"(null)"
if it is
null
.
s
- the input string, or null
.
s != null
the quoted string, otherwise the string
"(null)"
.public static String quote(Object o)
toString()
) of
the specified object, or returns "(null)"
if the object is
null
.
o
- the object, or null
.
o != null
then o.toString()
quoted,
otherwise the string "(null)"
.public static boolean isEmpty(String s)
null
or an empty
string.
s
- the string, or null
.
true
if s == null || s.length() < 1
.public static String trim(String s, String ifEmpty)
null
.
s
- the string, or null
.ifEmpty
- the string to return if
s == null || s.trim().length < 1
.
String.trim()
) or
ifEmpty
if
s == null
or s.trim().length < 1
.public static String replace(String s, Properties replacements, String prefix, String suffix) throws IllegalArgumentException
Properties
object. A prefix and a suffix can be
specified. These are prepended/appended to each of the search keys.
Example: If you have a string "Hello ${name}"
and you
would like to replace "${name}"
with "John"
and you would like to replace ${surname}
with
"Doe"
, use the following code:
String s = "Hello ${name}";
Properties replacements = new Properties();
replacements.put("name", "John");
replacements.put("surname", "Doe");
StringUtils.replace(s, replacements, "${", "}");
The result string will be "Hello John"
.
s
- the text string to which replacements should be applied, not null
.replacements
- the replacements to apply, not null
.prefix
- the optional prefix for the search keys, or null
.suffix
- the optional prefix for the search keys, or null
.
IllegalArgumentException
- if one of the mandatory arguments is missing.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |