com.ivata.mask.util
Class StringHandling

java.lang.Object
  extended bycom.ivata.mask.util.StringHandling

public final class StringHandling
extends java.lang.Object

StringHandling is a helper class for handling Strings. It contains methods for converting to and from different data types, and for handling null conditions.

Don't create an instance of this class; use the static final methods.

Since:
ivata masks 0.4 (2001-12-27)
Version:
$Revision: 1.3 $
Author:
Colin MacLeod colin.macleod@ivata.com

Method Summary
static java.lang.Boolean booleanValue(java.lang.String convertToBoolean)
           This method works like Boolean.valueOf, but allows null values without an exception, and also translates the string "on" as true which is useful for converting request values.
static java.lang.String generateRandomString(int length)
           Generates a random string of specified length, when the length 0 or less, defaults to 8 The string only consists of letters and numbers and the first character is always a letter.
static java.lang.String getNotNull(java.lang.Object check)
           If the string supplied is not null, return the string, otherwise return the empty string.
static java.lang.String getNotNull(java.lang.Object check, java.lang.String nullString)
           Handle null objects in a standard way.
static java.lang.Integer integerValue(java.lang.String convertToInteger)
           This method works like Integer.valueOf, but allows null values without an exception.
static boolean isNullOrEmpty(java.lang.String checkString)
           This method does just what it says: evaluates the String you give it and returns true if it is null or an empty string.
static java.lang.String toString(java.lang.Integer convert)
           Works like the standard Integer.toString() except that it allows null values, returning a null string in this case.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

booleanValue

public static java.lang.Boolean booleanValue(java.lang.String convertToBoolean)

This method works like Boolean.valueOf, but allows null values without an exception, and also translates the string "on" as true which is useful for converting request values.

Parameters:
convertToBoolean - a String to be converted to a boolean value. null Strings return in a null Boolean returned.
Returns:
null if convertToBoolean is null or if convertToBoolean equals the string "null". It returns a Boolean true value if the string is equal to "true" or "on" (ignoring case), otherwise a Boolean false value is returned.

generateRandomString

public static java.lang.String generateRandomString(int length)

Generates a random string of specified length, when the length 0 or less, defaults to 8 The string only consists of letters and numbers and the first character is always a letter.

Parameters:
length - the length of the string to generate.
Returns:
a random string of the specified length.

getNotNull

public static java.lang.String getNotNull(java.lang.Object check)

If the string supplied is not null, return the string, otherwise return the empty string.

Parameters:
check - an object to compare against null
Returns:
an empty string, if checkString is null, otherwise the value of checkString unaltered.
See Also:
getNotNull(Object o, String nullString)

getNotNull

public static java.lang.String getNotNull(java.lang.Object check,
                                          java.lang.String nullString)

Handle null objects in a standard way. If the object you pass is null, then the string nullString will be returned.

Parameters:
check - an object to compare against null
nullString - the string to return if o is null
Returns:
the parameter nullString if o is null, otherwise o.toString()
See Also:
getNotNull(Object check)

integerValue

public static java.lang.Integer integerValue(java.lang.String convertToInteger)

This method works like Integer.valueOf, but allows null values without an exception.

Parameters:
convertToInteger - a String to be converted to an integer number. null Strings return in a null Integer returned.
Returns:
null if convertToInteger is null or if convertToInteger equals the string value "null", otherwise an integer representing the base 10 value of convertToInteger.
See Also:
Integer.valueOf(String convertToInteger)

isNullOrEmpty

public static boolean isNullOrEmpty(java.lang.String checkString)

This method does just what it says: evaluates the String you give it and returns true if it is null or an empty string.

Parameters:
checkString - the string to check for being null or empty.
Returns:
true if checkString is null or an empty string

toString

public static java.lang.String toString(java.lang.Integer convert)

Works like the standard Integer.toString() except that it allows null values, returning a null string in this case.

Parameters:
convert - the Integer you want to convert to a string.
Returns:
null if the integer convert. is null, otherwise the string equivalent of convert.


Copyright © 2001-2005 ivata limited. All Rights Reserved.