org.apache.empire.commons
Class StringUtils

java.lang.Object
  extended by org.apache.empire.commons.StringUtils

public class StringUtils
extends java.lang.Object

This class contains common functions for comparing and converting values of type String.


Method Summary
static java.lang.String arrayToString(java.lang.Object[] array, java.lang.String separator)
          Converts an array of objects to a string.
static java.lang.String coalesce(java.lang.String preferred, java.lang.String alternative)
          Returns the preferred String if it is not empty ot the alternative String otherwise.
static java.lang.String collectionToString(java.util.Collection<? extends java.lang.Object> c, java.lang.String separator)
          Converts an collection of objects to a string.
static boolean isEmail(java.lang.String s)
           
static boolean isEmpty(java.lang.String s)
           
static boolean isValid(java.lang.String s)
           
static java.lang.String nullIfEmpty(java.lang.Object value)
          Returns null if the value supplied is null or an empty String.
static java.lang.String replace(java.lang.String source, java.lang.String find, java.lang.String replace)
          Replaces all occances of first character in a string by a string.
static java.lang.String replaceAll(java.lang.String source, java.lang.String find, java.lang.String replace)
          Returns a String with all occurrences of from within orig replaced with to.
static java.lang.String replaceBRbyLF(java.lang.String s)
           
static java.lang.String[] stringToArray(java.lang.String string, java.lang.String separator)
          Converts a string to an array of objects.
static java.lang.String toString(java.lang.Object value)
          Converts a value to a string.
static java.lang.String toString(java.lang.Object[] array)
          Converts an array of objects to a string.
static java.lang.String toString(java.lang.Object[] array, java.lang.String defValue)
          Converts an array of objects to a string.
static java.lang.String toString(java.lang.Object value, java.lang.String defValue)
          Converts a value to a string.
static java.lang.String trimAll(java.lang.String orig)
           
static java.lang.String validate(java.lang.String s)
          Validates a given string.
static java.lang.String valueOf(java.lang.Object value)
          Converts a value to a string.
static java.lang.String valueOf(java.lang.Object[] array)
          Converts an objects to a string.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

toString

public static java.lang.String toString(java.lang.Object value,
                                        java.lang.String defValue)
Converts a value to a string. If the value is null then the default value is returned.

Parameters:
value - the value to convert
defValue - default value which to return if value is null
Returns:
returns a String representation of the value or null if value is null

toString

public static java.lang.String toString(java.lang.Object value)
Converts a value to a string. If the value is null then null will be returned.

Parameters:
value - the value to convert
Returns:
returns a String representation of the value or null if value is null

toString

public static java.lang.String toString(java.lang.Object[] array,
                                        java.lang.String defValue)
Converts an array of objects to a string.

Parameters:
array - array of objects
defValue - default value which to return if array is null
Returns:
returns a String representation of the array or the defaultValue if array is null

toString

public static java.lang.String toString(java.lang.Object[] array)
Converts an array of objects to a string.

Parameters:
array - array of objects
Returns:
returns a String representation of the array or null if the array is null

valueOf

public static java.lang.String valueOf(java.lang.Object value)
Converts a value to a string. if the value is null an empty string is returned.

Parameters:
value - the value to convert
Returns:
returns a String representation of the Object or an empty stringif o is null

valueOf

public static java.lang.String valueOf(java.lang.Object[] array)
Converts an objects to a string.

Parameters:
array - array of objects
Returns:
returns a String representation of the array or an empty String if the array is null

coalesce

public static java.lang.String coalesce(java.lang.String preferred,
                                        java.lang.String alternative)
Returns the preferred String if it is not empty ot the alternative String otherwise.

Parameters:
preferred - the preferred String
alternative - the alternative String if the preferred String is not valid
Returns:
the preferred String if it is not empty ot the alternative String otherwise

nullIfEmpty

public static java.lang.String nullIfEmpty(java.lang.Object value)
Returns null if the value supplied is null or an empty String.

Parameters:
value - the value to check
Returns:
null if the value supplied is null or an empty String or the value as a string otherwise

arrayToString

public static java.lang.String arrayToString(java.lang.Object[] array,
                                             java.lang.String separator)
Converts an array of objects to a string.

Parameters:
array - array of objects
Returns:
returns a String

stringToArray

public static java.lang.String[] stringToArray(java.lang.String string,
                                               java.lang.String separator)
Converts a string to an array of objects.

Parameters:
string - the source string to parse
separator - the separator string by which the parts are separated
Returns:
returns a String

collectionToString

public static java.lang.String collectionToString(java.util.Collection<? extends java.lang.Object> c,
                                                  java.lang.String separator)
Converts an collection of objects to a string.

Parameters:
c - the collection to add
Returns:
returns a String

isEmpty

public static boolean isEmpty(java.lang.String s)

isValid

public static boolean isValid(java.lang.String s)

isEmail

public static boolean isEmail(java.lang.String s)

validate

public static java.lang.String validate(java.lang.String s)
Validates a given string. If the string is empty then null is returned. Otherwise the trimmed string is returned.

Parameters:
s - the string to validate
Returns:
the string or null if s was empty.

replace

public static java.lang.String replace(java.lang.String source,
                                       java.lang.String find,
                                       java.lang.String replace)
Replaces all occances of first character in a string by a string.

Parameters:
source - the original String.
find - the String to be replaced
replace - the replacement string
Returns:
a new string with all occurances of find in source replaced by replace

replaceAll

public static java.lang.String replaceAll(java.lang.String source,
                                          java.lang.String find,
                                          java.lang.String replace)
Returns a String with all occurrences of from within orig replaced with to. If orig contains no occurrences of from, or if from is equal to to,orig itself is returned rather than a copy being made. If orig is null, null is returned.

Parameters:
source - the original String.
find - the String to be replaced
replace - the replacement string
Returns:
a new string with all occurances of find in source replaced by replace

replaceBRbyLF

public static java.lang.String replaceBRbyLF(java.lang.String s)

trimAll

public static java.lang.String trimAll(java.lang.String orig)