| java.lang.Object com.mockrunner.util.common.StringUtil
StringUtil | public class StringUtil (Code) | | Simple util class for String related methods.
|
Method Summary | |
public static void | appendObjectsAsString(StringBuffer buffer, List data) Appends the entries in the specified List as strings
with a terminating "\n" after each row. | public static void | appendTabs(StringBuffer buffer, int number) Appends number tabs (\t) to the buffer. | public static int | compare(String string1, String string2) Compares two strings and returns the last
index where the two string are equal. | public static int | countMatches(String string, String other) Returns how many times string contains
other . | public static String | fieldToString(String fieldName, Object field) Helper method for toString() implementations.
Returns a string "field name: value" . | public static String | lowerCase(String string, int index) Converts the character at the specified index to
lowercase and returns the resulting string. | public static String | lowerCase(String string, int startIndex, int endIndex) Converts the character in the specified index range to
lowercase and returns the resulting string. | public static boolean | matchesContains(String source, String target, boolean caseSensitive) Returns if source contains target ,
ignoring case, if caseSensitive is false . | public static boolean | matchesExact(String source, String target, boolean caseSensitive) Returns if the specified strings are equal, ignoring
case, if caseSensitive is false . | public static boolean | matchesPerl5(String source, String target, boolean caseSensitive) Returns if the regular expression target matches
source , ignoring case, if caseSensitive
is false . | public static String | replaceAll(String source, String match, String replacement) Replaces all occurrences of match in
source with replacement . | public static String[] | split(String string, String delim, boolean doTrim) Splits a string into tokens. |
appendObjectsAsString | public static void appendObjectsAsString(StringBuffer buffer, List data)(Code) | | Appends the entries in the specified List as strings
with a terminating "\n" after each row.
Parameters: buffer - the buffer Parameters: data - the List with the data |
appendTabs | public static void appendTabs(StringBuffer buffer, int number)(Code) | | Appends number tabs (\t) to the buffer.
Parameters: buffer - the buffer Parameters: number - the number of tabs to append |
compare | public static int compare(String string1, String string2)(Code) | | 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 Parameters: string2 - the second string the last index where the strings are equal |
countMatches | public static int countMatches(String string, String other)(Code) | | Returns how many times string contains
other .
Parameters: string - the string to search Parameters: other - the string that is searched the number of occurences |
fieldToString | public static String fieldToString(String fieldName, Object field)(Code) | | Helper method for toString() implementations.
Returns a string "field name: value" . Handles
null values, collections and arrays. If the
field is a collection or an array, the returned string will
be:
"field name 0: value0\nfield name 1: value1"
Parameters: fieldName - the field name Parameters: field - the field value a suitable string for toString() implementations |
lowerCase | public static String lowerCase(String string, int index)(Code) | | Converts the character at the specified index to
lowercase and returns the resulting string.
Parameters: string - the string to convert Parameters: index - the index where the character is set to lowercase the converted string throws: IndexOutOfBoundsException - if the index is out ofrange |
lowerCase | public static String lowerCase(String string, int startIndex, int endIndex)(Code) | | 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 Parameters: startIndex - the index to start, inclusive Parameters: endIndex - the index to end, exclusive the converted string throws: IndexOutOfBoundsException - if the index is out ofrange |
matchesContains | public static boolean matchesContains(String source, String target, boolean caseSensitive)(Code) | | Returns if source contains target ,
ignoring case, if caseSensitive is false .
Parameters: source - the source String Parameters: target - the target String Parameters: caseSensitive - is the comparison case sensitive true if the strings matchesfalse otherwise |
matchesExact | public static boolean matchesExact(String source, String target, boolean caseSensitive)(Code) | | Returns if the specified strings are equal, ignoring
case, if caseSensitive is false .
Parameters: source - the source String Parameters: target - the target String Parameters: caseSensitive - is the comparison case sensitive true if the strings matchesfalse otherwise |
matchesPerl5 | public static boolean matchesPerl5(String source, String target, boolean caseSensitive)(Code) | | Returns if the regular expression target matches
source , ignoring case, if caseSensitive
is false .
Parameters: source - the source String Parameters: target - the target String Parameters: caseSensitive - is the comparison case sensitive true if the strings matchesfalse otherwise |
replaceAll | public static String replaceAll(String source, String match, String replacement)(Code) | | Replaces all occurrences of match in
source with replacement .
Parameters: source - the source string Parameters: match - the string that is searched Parameters: replacement - the replacement string the modified string throws: IllegalArgumentException - if any argument is null orif match is the empty string |
split | public static String[] split(String string, String delim, boolean doTrim)(Code) | | 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 Parameters: delim - the delimiter Parameters: doTrim - should each token be trimmed the array of tokens |
|
|