org.xins.common.text
Class TextUtils

java.lang.Object
  extended byorg.xins.common.text.TextUtils

public final class TextUtils
extends Object

Text-related utility functions.

Since:
XINS 1.0.0
Version:
$Revision: 1.30 $ $Date: 2008/07/04 10:22:47 $
Author:
Ernst de Haan

Method Summary
static String firstCharLower(String text)
          Tranforms the given String to the similar String, but starting with a lowercase.
static String firstCharUpper(String text)
          Tranforms the given String to the similar String, but starting with an uppercase.
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 removeCharacter(char charToRemove, String text)
          Removes the given character from the given String.
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

quote

public static String quote(String s)
Quotes the specified string, or returns "(null)" if it is null.

Parameters:
s - the input string, or null.
Returns:
if s != null the quoted string, otherwise the string "(null)".

quote

public static String quote(Object o)
Quotes the textual presentation (returned by toString()) of the specified object, or returns "(null)" if the object is null.

Parameters:
o - the object, or null.
Returns:
if o != null then o.toString() quoted, otherwise the string "(null)".
Since:
XINS 1.0.1

isEmpty

public static boolean isEmpty(String s)
Determines if the specified string is null or an empty string.

Parameters:
s - the string, or null.
Returns:
true if s == null || s.length() < 1.
Since:
XINS 1.0.1

trim

public static String trim(String s,
                          String ifEmpty)
Trims the specified string, or returns an empty string if the argument is null.

Parameters:
s - the string, or null.
ifEmpty - the string to return if s == null || s.trim().length < 1.
Returns:
the trimmed version of the string (see String.trim()) or ifEmpty if s == null or s.trim().length < 1.
Since:
XINS 1.3.0

replace

public static String replace(String s,
                             Properties replacements,
                             String prefix,
                             String suffix)
                      throws IllegalArgumentException
Replaces substrings in a string. The substrings to be replaced are passed in a 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".

Parameters:
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.
Returns:
the String with the replacements.
Throws:
IllegalArgumentException - if one of the mandatory arguments is missing.
Since:
XINS 1.4.0.

firstCharUpper

public static String firstCharUpper(String text)
Tranforms the given String to the similar String, but starting with an uppercase.

Parameters:
text - the text to transform, can be null
Returns:
the transformed text, the return value will start with an uppercase. null is returned if the text was null.
Since:
XINS 2.0.

firstCharLower

public static String firstCharLower(String text)
Tranforms the given String to the similar String, but starting with a lowercase.

Parameters:
text - the text to transform, can be null
Returns:
the transformed text, the return value will start with a lowercase. null is returned if the text was null.
Since:
XINS 2.0.

removeCharacter

public static String removeCharacter(char charToRemove,
                                     String text)
Removes the given character from the given String.

Parameters:
charToRemove - the character that should be removed from the String.
text - the text from which the charecter should be removed, can be null.
Returns:
the text without the character or null if the input text is null.
Since:
XINS 2.0.


See http://www.xins.org/.