org.ibisph.util
Class StrLib

java.lang.Object
  extended by org.ibisph.util.StrLib

public abstract class StrLib
extends java.lang.Object

StrLib is an abstract class with various utility methods for String manipulation and other odd ball methods.

In addition to being abstract each method in the class is static. Access the methods by referencing the class and method name.

    Example: StrLib.occurs("This is an example", "example");
 
In this example the occurs method will be executed using the provided parameters.

Author:
Garth Braithwaite, STG

Constructor Summary
StrLib()
           
 
Method Summary
static java.lang.String buildCSV(java.lang.String[] array)
          Builds a comma separated string based on the string array passed in.
static java.lang.String capitalize(java.lang.String s)
          Capitalize the first letter of the string.
static java.lang.String capitalizeWordsFirstLetter(java.lang.String sourceString)
          Capitalizes the first letter of each word in a String.
static java.lang.String clean(java.lang.String source, java.lang.String getRidOf)
          Cleans out all occurrences of the specified characters within the search String.
static java.lang.String cleanEnd(java.lang.String source, java.lang.String getRidOf)
          Removes all occurrences of the specified characters from the end of the source String.
static java.lang.String cleanStart(java.lang.String source, java.lang.String getRidOf)
          Removes all occurrences of the specified characters from the start of the source String.
static java.lang.String dbQuote(java.lang.String source)
          Replaces single quote marks ' with '' and places ' at the start and end of the string.
static java.lang.String getMaxLengthString(java.lang.String[] array)
          Returns the String with the greatest length contained within the array.
static int getMaxStringLength(java.lang.String[] array)
          Returns the greatest length of a string contained within the array.
static boolean isSomething(java.lang.String source)
          This method is used to test for values being not null and non blank.
static boolean isTorYorX(java.lang.String source)
          Helper that localizes testing if a string contains True/False, Yes/No, or simply an X.
static int occurs(java.lang.String source, java.lang.String value)
          Counts the occurrences of a String within a String.
static void searchAndReplace(java.lang.StringBuffer source, java.lang.String search, java.lang.String replace)
          Replaces all occurrences of a String within a StringBuffer with another String with all occurrences of String replaced by a new String.
static java.lang.String searchAndReplace(java.lang.String source, java.lang.String[][] searchAndReplace)
          Returns a new string which is built by searching the source string for all occurrences of each searchAndReplace[x][0] string and replacing that part with the corresponding searchAndReplace[x][1] string.
static java.lang.String searchAndReplace(java.lang.String source, java.lang.String search, java.lang.String replace)
          Replaces all occurrences of a String within a String with another String.
static java.lang.String trunc(java.lang.String source, int length)
          Truncates a String to a specified length starting from the left most character of the String.
static java.lang.String truncateLeft(java.lang.String source, int length)
          Truncates a String to a specified length starting from the left most character of the String.
static java.lang.String truncateRight(java.lang.String source, int length)
          Truncates a String to a specified length starting from the right most character of the String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StrLib

public StrLib()
Method Detail

occurs

public static int occurs(java.lang.String source,
                         java.lang.String value)
Counts the occurrences of a String within a String.

Parameters:
source - A String.
value - String that is the value to count.
Returns:
Count of occurrences.

capitalize

public static java.lang.String capitalize(java.lang.String s)
Capitalize the first letter of the string.

Parameters:
s - java.lang.String

capitalizeWordsFirstLetter

public static java.lang.String capitalizeWordsFirstLetter(java.lang.String sourceString)
Capitalizes the first letter of each word in a String.

Parameters:
sourceString - Text to be capitalized.
Returns:
String with the first letter of each word capitalized.

truncateLeft

public static java.lang.String truncateLeft(java.lang.String source,
                                            int length)
Truncates a String to a specified length starting from the left most character of the String.

Parameters:
source - Text to be trimmed.
length - Amount of the desired String to be returned.
Returns:
Trimmed string.

trunc

public static java.lang.String trunc(java.lang.String source,
                                     int length)
Truncates a String to a specified length starting from the left most character of the String. Same as truncateLeft()...

Parameters:
source - Text to be trimmed.
length - Amount of the desired String to be returned.
Returns:
Trimmed string.
See Also:
"truncateLeft"

truncateRight

public static java.lang.String truncateRight(java.lang.String source,
                                             int length)
Truncates a String to a specified length starting from the right most character of the String.

Parameters:
source - Text to be trimmed.
length - Amount of the desired String to be returned.
Returns:
Trimmed string.

searchAndReplace

public static java.lang.String searchAndReplace(java.lang.String source,
                                                java.lang.String search,
                                                java.lang.String replace)
Replaces all occurrences of a String within a String with another String. Differs from the replaceString method in that null strings are handled.

Parameters:
source - Text to be searched and replaced.
search - Text searched for.
replace - Text used to replace found sub strings with.
Returns:
String with all occurrences of search text replaced.

searchAndReplace

public static java.lang.String searchAndReplace(java.lang.String source,
                                                java.lang.String[][] searchAndReplace)
Returns a new string which is built by searching the source string for all occurrences of each searchAndReplace[x][0] string and replacing that part with the corresponding searchAndReplace[x][1] string.

Parameters:
source - Text to be searched and replaced.
searchAndReplace - 2-d dimensional String array which has element [0] containing the String to be searched for, and element [1] containing replace text.
Returns:
String based on the source String that has all occurrences of String[i][0] replaced with String [i][1].

searchAndReplace

public static void searchAndReplace(java.lang.StringBuffer source,
                                    java.lang.String search,
                                    java.lang.String replace)
Replaces all occurrences of a String within a StringBuffer with another String with all occurrences of String replaced by a new String.

Parameters:
source - StringBuffer which is the String to be searched.
search - Searched for text.
replace - Value to replace with.

clean

public static java.lang.String clean(java.lang.String source,
                                     java.lang.String getRidOf)
Cleans out all occurrences of the specified characters within the search String.

Parameters:
source - Text to be cleaned.
getRidOf - Contains character(s) to be removed from the source.
Returns:
String with all occurrences of any character within the getRidOf String having been replaced with "".

cleanStart

public static java.lang.String cleanStart(java.lang.String source,
                                          java.lang.String getRidOf)
Removes all occurrences of the specified characters from the start of the source String.

Parameters:
source - Text to be "left" cleaned of characters.
getRidOf - Contains character(s) to be removed from the start of the source string.
Returns:
String with all left or start of string occurrences of any character within the getRidOf String having been replaced with "".

cleanEnd

public static java.lang.String cleanEnd(java.lang.String source,
                                        java.lang.String getRidOf)
Removes all occurrences of the specified characters from the end of the source String.

Parameters:
source - Text to be "right" cleaned of characters.
getRidOf - Contains character(s) to be removed from the end of the source string.
Returns:
String with all right or end of string occurrences of any character within the getRidOf String having been replaced with "".

isTorYorX

public static boolean isTorYorX(java.lang.String source)
Helper that localizes testing if a string contains True/False, Yes/No, or simply an X. Used mainly for testing for/converting database T/F, Y/N type flags into a boolean.

Parameters:
source - Text to be interpreted as either true/false, yes/no or X which means (true).
Returns:
True if the String is "T/t/Y/y/True/Yes/X/x", else false.

isSomething

public static boolean isSomething(java.lang.String source)
This method is used to test for values being not null and non blank.

Parameters:
source - Text to be tested.
Returns:
true if the String is anything other than null or some series of blanks.

dbQuote

public static java.lang.String dbQuote(java.lang.String source)
Replaces single quote marks ' with '' and places ' at the start and end of the string. This method is useful for inserting a string into an Oracle db table when the string has an inside ' and the insertion method is a straight execSQL not a prepared statement.

Parameters:
source - A String to be operated on.
Returns:
String that starts and ends with single quote marks ' with all interanl ' quote marks changed to two '' single quote marks. If null then return "null" instead of '' string or throwing an exception.

buildCSV

public static java.lang.String buildCSV(java.lang.String[] array)
Builds a comma separated string based on the string array passed in.

Parameters:
array - A String array that contains the elements of the CSV.
Returns:
String with array elements all separated with a comma ",".

getMaxLengthString

public static java.lang.String getMaxLengthString(java.lang.String[] array)
Returns the String with the greatest length contained within the array.

Parameters:
array - A String array that contains the strings to be checked.
Returns:
Longest string contained within the array.

getMaxStringLength

public static int getMaxStringLength(java.lang.String[] array)
Returns the greatest length of a string contained within the array.

Parameters:
array - A String array that contains the strings to be checked.
Returns:
Value of length of the longest string contained within the array.