com.xenonsoft.bridgetown.soa
Class StringUtils

java.lang.Object
  extended bycom.xenonsoft.bridgetown.soa.StringUtils

public class StringUtils
extends java.lang.Object

A set of static utility methods designed to keep the framework completely independent of any other framework except the standard Java libraries.

Version:
$Id: StringUtils.java,v 1.3 2005/02/23 01:31:10 peter_pilgrim Exp $
Author:
Peter Pilgrim, Aug 3, 2004 5:33:57 PM

Method Summary
static java.lang.String getBasenameOfClass(java.lang.Class clazz)
          Retrieves the basename of a fully qualified class.
static boolean getBoolean(java.lang.String s1)
          Utility to convert a string to a boolean
static java.lang.String getObjectIdentity(java.lang.Object obj)
          Retrieves the JVM standard object identity as a String in the format {CLASS_NAME}@{SystemHashCode}
static java.lang.String getPackageNameOfClass(java.lang.Class clazz)
          Retrieves the package name of a fully qualified class.
static java.lang.String getSystemIdentifer(java.lang.Object object)
          Retrieve the Java standard system identifier string of an Object.
static java.lang.String getSystemIdentiferShort(java.lang.Object object)
          Retrieve the Java standard system identifier string of an Object, but show only the basename of the class Here is an example e.g SubstringFilterStrategy@1e8a1f6
static boolean hasAllAlphanumeric(java.lang.String s1)
          Verify an input string contains only alphabetical or numerical characters in terms of unicode.
static boolean hasAllDigits(java.lang.String s1)
          Verify an input string contains all numerical (digit) characters
static boolean hasAllLetters(java.lang.String s1)
          Verify an input string contains all alphabetical characters in terms of unicode.
static boolean isBlankOrNull(java.lang.String s1)
          Return a boolean true if the input string is empty or null.
static java.lang.String join(java.util.Collection collection, java.lang.String delimiter)
          Joins a Java collection of strings with a delimiter to produce one single String
static java.lang.String join(java.lang.String[] arr)
          Joins an array of strings with a comma-space delimiter to produce one single String
static java.lang.String join(java.lang.String[] arr, java.lang.String delimiter)
          Joins an array of strings with a delimiter to produce one single String
static boolean matchArgument(java.lang.String ref, java.lang.String arg)
          A convenience static method for interpreting command line arguments with wildcard names.
static java.lang.String notNull(java.lang.String s1)
          Returns a String that is guaranteed not to be null.
static byte parseStringToByte(java.lang.String input)
          Converts a text input String to a primitive byte value NB: If the value fails conversion the default value is zero.
static byte parseStringToByte(java.lang.String input, byte defaultValue)
          Converts a text input String to a primitive byte value
static double parseStringToDouble(java.lang.String input)
          Converts a text input String to a primitive double value NB: If the value fails conversion the default value is zero.
static double parseStringToDouble(java.lang.String input, double defaultValue)
          Converts a text input String to a primitive double value
static float parseStringToFloat(java.lang.String input)
          Converts a text input String to a primitive float value NB: If the value fails conversion the default value is zero.
static float parseStringToFloat(java.lang.String input, float defaultValue)
          Converts a text input String to a primitive float value
static int parseStringToInt(java.lang.String input)
          Converts a text input String to a primitive int value NB: If the value fails conversion the default value is zero.
static int parseStringToInt(java.lang.String input, int defaultValue)
          Converts a text input String to a primitive int value
static long parseStringToLong(java.lang.String input)
          Converts a text input String to a primitive long value NB: If the value fails conversion the default value is zero.
static long parseStringToLong(java.lang.String input, long defaultValue)
          Converts a text input String to a primitive long value
static short parseStringToShort(java.lang.String input)
          Converts a text input String to a primitive short value NB: If the value fails conversion the default value is zero.
static short parseStringToShort(java.lang.String input, short defaultValue)
          Converts a text input String to a primitive short value
static java.lang.String[] splice(java.lang.String input)
          Break up a comma or semi-colon delimited input string into a constituent parts (an array of String) objects.
static java.lang.String[] splice(java.lang.String input, java.lang.String delimiters, boolean trimElem)
          Break up an input string to a constituent parts (an array of String) objects.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

notNull

public static java.lang.String notNull(java.lang.String s1)
Returns a String that is guaranteed not to be null. If the input String is null then a blank string is returned, otherwise the supplied string is returned instead.

Returns:
the non-null string

isBlankOrNull

public static boolean isBlankOrNull(java.lang.String s1)
Return a boolean true if the input string is empty or null.

Parameters:
s1 - the input string
Returns:
boolean true the string is blank or null

getBoolean

public static boolean getBoolean(java.lang.String s1)
Utility to convert a string to a boolean


getObjectIdentity

public static java.lang.String getObjectIdentity(java.lang.Object obj)
Retrieves the JVM standard object identity as a String in the format {CLASS_NAME}@{SystemHashCode}

Returns:
the object id string

hasAllDigits

public static boolean hasAllDigits(java.lang.String s1)
Verify an input string contains all numerical (digit) characters

Parameters:
s1 - the input string
Returns:
the boolean result

hasAllLetters

public static boolean hasAllLetters(java.lang.String s1)
Verify an input string contains all alphabetical characters in terms of unicode.

Parameters:
s1 - the input string
Returns:
the boolean result

hasAllAlphanumeric

public static boolean hasAllAlphanumeric(java.lang.String s1)
Verify an input string contains only alphabetical or numerical characters in terms of unicode.

Parameters:
s1 - the input string
Returns:
the boolean result

join

public static java.lang.String join(java.lang.String[] arr)
Joins an array of strings with a comma-space delimiter to produce one single String

Parameters:
arr - the array of string
Returns:
the joined String

join

public static java.lang.String join(java.lang.String[] arr,
                                    java.lang.String delimiter)
Joins an array of strings with a delimiter to produce one single String

Parameters:
arr - the array of string
delimiter - the delimiter string
Returns:
the joined String

join

public static java.lang.String join(java.util.Collection collection,
                                    java.lang.String delimiter)
Joins a Java collection of strings with a delimiter to produce one single String

Parameters:
delimiter - the delimiter string
Returns:
the joined String
Throws:
java.lang.ClassCastException - if an element in the supplied collection is not a String

splice

public static java.lang.String[] splice(java.lang.String input)
Break up a comma or semi-colon delimited input string into a constituent parts (an array of String) objects.

Parameters:
input - the original input s1tring
Returns:
the spliced String array
See Also:
splice(String, String, boolean)

splice

public static java.lang.String[] splice(java.lang.String input,
                                        java.lang.String delimiters,
                                        boolean trimElem)
Break up an input string to a constituent parts (an array of String) objects.

Parameters:
input - the original input string
delimiters - the delimited characeters
trimElem - boolean value, true then each element gets an haircu t and generally tidies up
Returns:
the spliced String array

matchArgument

public static boolean matchArgument(java.lang.String ref,
                                    java.lang.String arg)
A convenience static method for interpreting command line arguments with wildcard names.

Given a reference string --desc*(ription), then a matching command line argument is a member of the following set:

  1. --description
  2. --descriptio
  3. --descripti
  4. --descrip
  5. --descri
  6. --descr

NB: The string matching takes place from right to left

Parameters:
ref - the reference argument
arg - the command line argument supplied to the program
Returns:
the boolean result, true if there is a match

parseStringToShort

public static short parseStringToShort(java.lang.String input,
                                       short defaultValue)
Converts a text input String to a primitive short value

Parameters:
input - the input text string
defaultValue - the default value to use if the conversion fails
Returns:
the converted value or default value

parseStringToInt

public static int parseStringToInt(java.lang.String input,
                                   int defaultValue)
Converts a text input String to a primitive int value

Parameters:
input - the input text string
defaultValue - the default value to use if the conversion fails
Returns:
the converted value or default value

parseStringToLong

public static long parseStringToLong(java.lang.String input,
                                     long defaultValue)
Converts a text input String to a primitive long value

Parameters:
input - the input text string
defaultValue - the default value to use if the conversion fails
Returns:
the converted value or default value

parseStringToFloat

public static float parseStringToFloat(java.lang.String input,
                                       float defaultValue)
Converts a text input String to a primitive float value

Parameters:
input - the input text string
defaultValue - the default value to use if the conversion fails
Returns:
the converted value or default value

parseStringToDouble

public static double parseStringToDouble(java.lang.String input,
                                         double defaultValue)
Converts a text input String to a primitive double value

Parameters:
input - the input text string
defaultValue - the default value to use if the conversion fails
Returns:
the converted value or default value

parseStringToByte

public static byte parseStringToByte(java.lang.String input,
                                     byte defaultValue)
Converts a text input String to a primitive byte value

Parameters:
input - the input text string
defaultValue - the default value to use if the conversion fails
Returns:
the converted value or default value

parseStringToShort

public static short parseStringToShort(java.lang.String input)
Converts a text input String to a primitive short value

NB: If the value fails conversion the default value is zero.

Parameters:
input - the input text string
Returns:
the converted value.
See Also:
parseStringToShort(String, short)

parseStringToInt

public static int parseStringToInt(java.lang.String input)
Converts a text input String to a primitive int value

NB: If the value fails conversion the default value is zero.

Parameters:
input - the input text string
Returns:
the converted value.
See Also:
parseStringToInt(String, int)

parseStringToLong

public static long parseStringToLong(java.lang.String input)
Converts a text input String to a primitive long value

NB: If the value fails conversion the default value is zero.

Parameters:
input - the input text string
Returns:
the converted value.
See Also:
parseStringToLong(String, long)

parseStringToFloat

public static float parseStringToFloat(java.lang.String input)
Converts a text input String to a primitive float value

NB: If the value fails conversion the default value is zero.

Parameters:
input - the input text string
Returns:
the converted value.
See Also:
parseStringToFloat(String, float)

parseStringToDouble

public static double parseStringToDouble(java.lang.String input)
Converts a text input String to a primitive double value

NB: If the value fails conversion the default value is zero.

Parameters:
input - the input text string
Returns:
the converted value.
See Also:
parseStringToDouble(String, double)

parseStringToByte

public static byte parseStringToByte(java.lang.String input)
Converts a text input String to a primitive byte value

NB: If the value fails conversion the default value is zero.

Parameters:
input - the input text string
Returns:
the converted value.
See Also:
parseStringToByte(String, byte)

getBasenameOfClass

public static java.lang.String getBasenameOfClass(java.lang.Class clazz)
Retrieves the basename of a fully qualified class. For example the basename of java.util.HashMap is just HashMap. On the other hand, a class in the default package is just itself.

Parameters:
clazz - the class to retrieve the basename class from
Returns:
the basename of this class

getPackageNameOfClass

public static java.lang.String getPackageNameOfClass(java.lang.Class clazz)
Retrieves the package name of a fully qualified class. For example the package name of java.util.HashMap is just java.util. On the other hand, a class in the default package is just ""

Parameters:
clazz - the class to retrieve the basename class from
Returns:
the basename of this class

getSystemIdentifer

public static java.lang.String getSystemIdentifer(java.lang.Object object)
Retrieve the Java standard system identifier string of an Object. Here is an example e.g com.csfb.csar.filter.strategy.SubstringFilterStrategy@1e8a1f6

Parameters:
object - the object
Returns:
the system identifier
See Also:
getSystemIdentifer(Object)

getSystemIdentiferShort

public static java.lang.String getSystemIdentiferShort(java.lang.Object object)
Retrieve the Java standard system identifier string of an Object, but show only the basename of the class Here is an example e.g SubstringFilterStrategy@1e8a1f6

Parameters:
object - the object
Returns:
the system identifier
See Also:
getBasenameOfClass(Class), getSystemIdentifer(Object)


Copyright © 2005 XeNoNSoFT.com. All Rights Reserved.