org.stringer.util
Class StringKit

java.lang.Object
  |
  +--org.stringer.util.StringKit

public class StringKit
extends java.lang.Object

Static methods for common String tasks.

Author:
R. Kevin Cole kcole@users.sourceforge.net

Field Summary
private static java.lang.String EMPTY_STRING
           
private static long initial_hash
           
private static java.lang.String LINE_SEPARATOR
          The system line separator.
private static long[] mix_master
           
 
Constructor Summary
private StringKit()
          This class has a private constructor to prevent it from being instantiated.
 
Method Summary
private static long buzhash(java.lang.StringBuffer arg)
           
static java.lang.String filterMultipleConsecutive(java.lang.String input, java.lang.String filter)
          Filters out multiple consecutive instances of a given string.
static int indexOfDigit(java.lang.String s)
          Returns the index of the first digit in s.
static java.lang.String randomString(int length)
          Returns a random lower case letter-only string with length characters.
private static java.lang.String removeAll(java.lang.String input, java.lang.String filter)
          Removes all instances of a given string from an input.
static java.lang.String replace(java.lang.String str, java.lang.String pattern, java.lang.String replace)
          Replaces all occurences of pattern in str by replace.
static java.lang.String replaceIgnoreCase(java.lang.String str, java.lang.String pattern, java.lang.String replace)
          Same as replace(java.lang.String, java.lang.String, java.lang.String) except that character case is ignored.
static java.lang.String splitAt(java.lang.String str, java.lang.String separator)
          Splits a string at the last occurence of a separator string and returns the remaining text.
static java.lang.String strip(java.lang.String s)
          Removes all characters from a string that are not letters.
static java.lang.String tab(int level)
          Returns a string consisting of the specified number of tab characters.
static int[] toIntArray(java.lang.String value, java.lang.String separators)
          Convert a string to an array of integers.
static java.util.List toList(java.lang.String value, java.lang.String separators)
          Create a linked list of strings, by breaking a source string into pieces at ever occurrence of characters in a separator string.
static java.lang.String toString(java.util.Collection c, java.lang.String separator)
          Flatten a collection to a string with individual elements separated by separator
static java.lang.String toString(int[] array, java.lang.String separator)
          Convert an array of integers into a delimiter separated String.
static java.lang.String toString(java.lang.String[] array, java.lang.String separator)
          Concatenate an array of strings into a delimiter separated String.
static java.lang.String[] toStringArray(java.lang.String value, java.lang.String separators)
          Convert a string to an array of strings.
static java.util.List wordSplit(java.lang.String input)
          Splits a string into words, breaking according to the whitespace rules in the Character class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LINE_SEPARATOR

private static final java.lang.String LINE_SEPARATOR
The system line separator.


EMPTY_STRING

private static final java.lang.String EMPTY_STRING
See Also:
Constant Field Values

mix_master

private static long[] mix_master

initial_hash

private static long initial_hash
Constructor Detail

StringKit

private StringKit()
This class has a private constructor to prevent it from being instantiated.

Method Detail

buzhash

private static long buzhash(java.lang.StringBuffer arg)

replace

public static java.lang.String replace(java.lang.String str,
                                       java.lang.String pattern,
                                       java.lang.String replace)
Replaces all occurences of pattern in str by replace.

Parameters:
str - characters in this string are replaced.
pattern - the string to be replaced.
replace - the "find" string is replaced with this string.
Returns:
the modified instance of s

replaceIgnoreCase

public static java.lang.String replaceIgnoreCase(java.lang.String str,
                                                 java.lang.String pattern,
                                                 java.lang.String replace)
Same as replace(java.lang.String, java.lang.String, java.lang.String) except that character case is ignored.

Parameters:
pattern - the string to be replaced.
replace - the "pattern" string is replaced with this string.
Returns:
the string with "pattern" characters replaced by "replace" characters.

filterMultipleConsecutive

public static java.lang.String filterMultipleConsecutive(java.lang.String input,
                                                         java.lang.String filter)
Filters out multiple consecutive instances of a given string.

Parameters:
input - the string to filter
Returns:
the string without multiple consecutive instances of filterChar

removeAll

private static java.lang.String removeAll(java.lang.String input,
                                          java.lang.String filter)
Removes all instances of a given string from an input.

Parameters:
input - the string to filter
filter - the string to remove
Returns:
the input with all instances of filter removed
Throws:
java.lang.StringIndexOutOfBoundsException - if there is malformed text in the input.

tab

public static java.lang.String tab(int level)
Returns a string consisting of the specified number of tab characters.

Parameters:
level - the number of tab characters requested.

randomString

public static java.lang.String randomString(int length)
Returns a random lower case letter-only string with length characters.


strip

public static java.lang.String strip(java.lang.String s)
Removes all characters from a string that are not letters. Non-letters are determined by the java class Character.

Parameters:
s - the string to be stripped
Returns:
an instance of the input string with all non-letters stripped.

indexOfDigit

public static int indexOfDigit(java.lang.String s)
Returns the index of the first digit in s.

Parameters:
s - the index of the first digit in this string is found.
Returns:
-1, if the parameter does not contain any digits otherwise the index of the first digit is returned.

splitAt

public static java.lang.String splitAt(java.lang.String str,
                                       java.lang.String separator)
Splits a string at the last occurence of a separator string and returns the remaining text.

Parameters:
str - the string to be split at the separator
separator - the string at which the split will occur
Returns:
if separator is not found in stran empty string is returned, else a new string containing the text to the right of the separator is returned.

toStringArray

public static java.lang.String[] toStringArray(java.lang.String value,
                                               java.lang.String separators)
Convert a string to an array of strings. The string boundaries are defined by a string of separators.

For example, to break a string into words we break at every space, linefeed, carriage return, form feed and tab character
toStringArray( s, "\t\n\f\r ");

note that this will not delete any control-characters found in the string.


toIntArray

public static int[] toIntArray(java.lang.String value,
                               java.lang.String separators)
                        throws java.lang.NumberFormatException
Convert a string to an array of integers. The string boundaries are defined by a string of separators.

Throws:
java.lang.NumberFormatException

toList

public static java.util.List toList(java.lang.String value,
                                    java.lang.String separators)
Create a linked list of strings, by breaking a source string into pieces at ever occurrence of characters in a separator string.


toString

public static java.lang.String toString(int[] array,
                                        java.lang.String separator)
Convert an array of integers into a delimiter separated String.


toString

public static java.lang.String toString(java.lang.String[] array,
                                        java.lang.String separator)
Concatenate an array of strings into a delimiter separated String.


toString

public static java.lang.String toString(java.util.Collection c,
                                        java.lang.String separator)
Flatten a collection to a string with individual elements separated by separator

Parameters:
c - the collection to be converted to a delimited string.
separator - the string used to separate individual elements in the resulting string.
Returns:
the collection as a single string with elements separated by a separator string.

wordSplit

public static java.util.List wordSplit(java.lang.String input)
Splits a string into words, breaking according to the whitespace rules in the Character class.

Parameters:
input - the input to split
Returns:
the input split into words


Copyright © R. Kevin Cole. All Rights Reserved.