com.mockrunner.util.common
Class StringUtil

java.lang.Object
  extended bycom.mockrunner.util.common.StringUtil

public class StringUtil
extends java.lang.Object

Simple util class for String related methods.


Constructor Summary
StringUtil()
           
 
Method Summary
static void appendObjectsAsString(java.lang.StringBuffer buffer, java.util.List data)
          Appends the entries in the specified List as strings with a terminating "\n" after each row.
static void appendTabs(java.lang.StringBuffer buffer, int number)
          Appends number tabs (\t) to the buffer.
static int compare(java.lang.String string1, java.lang.String string2)
          Compares two strings and returns the last index where the two string are equal.
static int countMatches(java.lang.String string, java.lang.String other)
          Returns how many times string contains other.
static java.lang.String lowerCase(java.lang.String string, int index)
          Converts the character at the specified index to lowercase and returns the resulting string.
static java.lang.String lowerCase(java.lang.String string, int startIndex, int endIndex)
          Converts the character in the specified index range to lowercase and returns the resulting string.
static boolean matchesContains(java.lang.String source, java.lang.String target, boolean caseSensitive)
          Returns if source contains target, ignoring case, if caseSensitive is false.
static boolean matchesExact(java.lang.String source, java.lang.String target, boolean caseSensitive)
          Returns if the specified strings are equal, ignoring case, if caseSensitive is false.
static boolean matchesPerl5(java.lang.String source, java.lang.String target, boolean caseSensitive)
          Returns if the regular expression target matches source, ignoring case, if caseSensitive is false.
static java.lang.String[] split(java.lang.String string, java.lang.String delim, boolean doTrim)
          Splits a string into tokens.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringUtil

public StringUtil()
Method Detail

compare

public static int compare(java.lang.String string1,
                          java.lang.String string2)
Compares two strings and returns the last index where the two string are equal. If the first characters of the two string do not match or if at least one of the two strings is empty, -1 is returned.

Parameters:
string1 - the first string
string2 - the second string
Returns:
the last index where the strings are equal

lowerCase

public static java.lang.String lowerCase(java.lang.String string,
                                         int index)
Converts the character at the specified index to lowercase and returns the resulting string.

Parameters:
string - the string to convert
index - the index where the character is set to lowercase
Returns:
the converted string
Throws:
java.lang.IndexOutOfBoundsException - if the index is out of range

lowerCase

public static java.lang.String lowerCase(java.lang.String string,
                                         int startIndex,
                                         int endIndex)
Converts the character in the specified index range to lowercase and returns the resulting string. If the provided endIndex is smaller or equal to startIndex, the endIndex is set to startIndex + 1.

Parameters:
string - the string to convert
startIndex - the index to start, inclusive
endIndex - the index to end, exclusive
Returns:
the converted string
Throws:
java.lang.IndexOutOfBoundsException - if the index is out of range

appendObjectsAsString

public static void appendObjectsAsString(java.lang.StringBuffer buffer,
                                         java.util.List data)
Appends the entries in the specified List as strings with a terminating "\n" after each row.

Parameters:
buffer - the buffer
data - the List with the data

appendTabs

public static void appendTabs(java.lang.StringBuffer buffer,
                              int number)
Appends number tabs (\t) to the buffer.

Parameters:
buffer - the buffer
number - the number of tabs to append

split

public static java.lang.String[] split(java.lang.String string,
                                       java.lang.String delim,
                                       boolean doTrim)
Splits a string into tokens. Similar to StringTokenizer except that empty tokens are recognized and added as null. With a delimiter of ";" the string "a;;b;c;;" will split into ["a"] [null] ["b"] ["c"] [null].

Parameters:
string - the String
delim - the delimiter
doTrim - should each token be trimmed
Returns:
the array of tokens

countMatches

public static int countMatches(java.lang.String string,
                               java.lang.String other)
Returns how many times string contains other.

Parameters:
string - the string to search
other - the string that is searched
Returns:
the number of occurences

matchesExact

public static boolean matchesExact(java.lang.String source,
                                   java.lang.String target,
                                   boolean caseSensitive)
Returns if the specified strings are equal, ignoring case, if caseSensitive is false.

Parameters:
source - the source String
target - the target String
caseSensitive - is the comparison case sensitive
Returns:
true if the strings matches false otherwise

matchesContains

public static boolean matchesContains(java.lang.String source,
                                      java.lang.String target,
                                      boolean caseSensitive)
Returns if source contains target, ignoring case, if caseSensitive is false.

Parameters:
source - the source String
target - the target String
caseSensitive - is the comparison case sensitive
Returns:
true if the strings matches false otherwise

matchesPerl5

public static boolean matchesPerl5(java.lang.String source,
                                   java.lang.String target,
                                   boolean caseSensitive)
Returns if the regular expression target matches source, ignoring case, if caseSensitive is false.

Parameters:
source - the source String
target - the target String
caseSensitive - is the comparison case sensitive
Returns:
true if the strings matches false otherwise