com.boylesoftware.cb2.util
Class TextUtils

java.lang.Object
  extended bycom.boylesoftware.cb2.util.TextUtils

public class TextUtils
extends java.lang.Object

Collection of useful text and string processing static functions.

Version:
$Id: TextUtils.java,v 1.6 2004/04/04 20:13:45 levahim Exp $
Author:
Lev Himmelfarb

Nested Class Summary
static class TextUtils.MapValueGetter
          Standard implementation of ValueGetter interface, which takes values for macros from a map object.
static interface TextUtils.ValueGetter
          Interface used by the replaceMacros methods to get values for macros.
 
Constructor Summary
TextUtils()
           
 
Method Summary
static java.lang.String arrayToString(java.lang.Object[] src)
          Calls arrayToString(src, 0, src.length).
static java.lang.String arrayToString(java.lang.Object[] src, int startIndex, int length)
          Returns string representation of data in the specified array of objects.
static java.lang.String getNullIfEmpty(java.lang.String s)
          If the input string is not null, not zero length and does not consist of only whitespace characters, this method trims it and returns the result.
static boolean isEmpty(java.lang.String s)
          Checks if the specified string is "empty".
static boolean isValidEmailAddress(java.lang.String s)
          Tells if the specified string is valid email address.
static java.lang.String replaceMacros(java.lang.CharSequence input, TextUtils.ValueGetter valueGetter)
          This method replaces all occurencies of ${name} in the input string with respective values provided by the specified value getter.
static java.lang.String replaceMacros(java.lang.CharSequence input, TextUtils.ValueGetter valueGetter, boolean leaveNotFoundMacros)
          This method replaces all occurencies of ${name} in the input string with respective values provided by the specified value getter.
static java.lang.String timeIntervalToString(long interval)
          Render a readable string representation of a time interval.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextUtils

public TextUtils()
Method Detail

replaceMacros

public static java.lang.String replaceMacros(java.lang.CharSequence input,
                                             TextUtils.ValueGetter valueGetter)
This method replaces all occurencies of ${name} in the input string with respective values provided by the specified value getter. If no value is returned by the getter for the name name then the ${name} is replaced with an empty string.

Parameters:
input - the input string containing macros in the form ${name}.
valueGetter - implementation of TextUtils.ValueGetter interface, which provides values for macros.
Returns:
the input string with macros replaces with the corresponding values.

replaceMacros

public static java.lang.String replaceMacros(java.lang.CharSequence input,
                                             TextUtils.ValueGetter valueGetter,
                                             boolean leaveNotFoundMacros)
This method replaces all occurencies of ${name} in the input string with respective values provided by the specified value getter.

Parameters:
input - the input string containing macros in the form ${name}.
valueGetter - implementation of TextUtils.ValueGetter interface, which provides values for macros.
leaveNotFoundMacros - if true and no value was found for the macro, that is the value getter returned null, the macro tag is copied to the output intact, otherwise the tag is replaced with an empty string.
Returns:
the input string with macros replaces with the corresponding values.

arrayToString

public static java.lang.String arrayToString(java.lang.Object[] src)
Calls arrayToString(src, 0, src.length).

Parameters:
src - the input array.
Returns:
readable representation of the data in the array.

arrayToString

public static java.lang.String arrayToString(java.lang.Object[] src,
                                             int startIndex,
                                             int length)
Returns string representation of data in the specified array of objects. The elements of the specified array may be arrays too, but not of any primitive type. This method is convenient for logging when you want to see contents of an array in a readable format in a log or debug printout.

Parameters:
src - the input array.
startIndex - index of the first element in the array.
length - number of array elements to process.
Returns:
readable representation of the data in the array.

timeIntervalToString

public static java.lang.String timeIntervalToString(long interval)
Render a readable string representation of a time interval. This method can be used when you want to display a time interval value in the user interface, log, or any other place where a human would see it.

Examples of the method's output:

 0.028s
 50.315s
 00:40:53
 15:20:45
 21d 15:20:45
 

Parameters:
interval - the time interval in milliseconds.
Returns:
human-readable representation of the specified time interval.

isEmpty

public static boolean isEmpty(java.lang.String s)
Checks if the specified string is "empty". A string is considered "empty" if it is null, zero length or consists of only whitespace characters.

Parameters:
s - string to check, can be null.
Returns:
true if the specified string is empty.

getNullIfEmpty

public static java.lang.String getNullIfEmpty(java.lang.String s)
If the input string is not null, not zero length and does not consist of only whitespace characters, this method trims it and returns the result. Otherwise, it returns null.

Parameters:
s - the input string, can be null.
Returns:
trimmed input string or null if the input string is "empty" in terms of TextUtils.isEmpty method.

isValidEmailAddress

public static boolean isValidEmailAddress(java.lang.String s)
Tells if the specified string is valid email address.

Parameters:
s - the string to test, should be trimmed, allowed to be null.
Returns:
true if the specified string is not null and denotes a syntactically valid email address.


Copyright © 2002,2003,2004 - Boyle Software, Inc.