com.jaxfront.core.util
Class StringUtils

java.lang.Object
  extended by com.jaxfront.core.util.StringUtils

public class StringUtils
extends java.lang.Object

Provides string utilities.


Field Summary
static java.lang.String doubleQuote
           
static java.lang.String newLine
           
static java.lang.String newTab
           
static java.lang.String space
           
 
Constructor Summary
StringUtils()
           
 
Method Summary
static boolean checkDistance(java.lang.String source, char[] aChar, int distance)
           
static boolean checkDistance(java.lang.String source, char aChar, int distance)
           
static int compareNatural(java.text.Collator collator, java.lang.String s, java.lang.String t)
           Compares two strings using the given collator and comparing contained numbers based on their numeric values.
static int compareNatural(java.lang.String s, java.lang.String t)
           Compares two strings using the current locale's rules and comparing contained numbers based on their numeric values.
static int compareNaturalAscii(java.lang.String s, java.lang.String t)
           Compares two strings using each character's Unicode value for non-digit characters and the numeric values off any contained numbers.
static int compareNaturalIgnoreCaseAscii(java.lang.String s, java.lang.String t)
           Compares two strings using each character's Unicode value - ignoring upper/lower case - for non-digit characters and the numeric values of any contained numbers.
static java.lang.String format(boolean left, char fill, int size, java.lang.String text)
          Returns a formatted string.
static void format(boolean left, char fill, int size, java.lang.String text, java.lang.StringBuffer buffer)
          Formats a specified string and appends the formatted string to the buffer.
static java.util.Comparator getNaturalComparator()
          Returns a comparator that compares contained numbers based on their numeric values and compares other parts using the current locale's order rules.
static java.util.Comparator getNaturalComparator(java.text.Collator collator)
          Returns a comparator that compares contained numbers based on their numeric values and compares other parts using the given collator.
static java.util.Comparator getNaturalComparatorAscii()
          Returns a comparator that compares contained numbers based on their numeric values and compares other parts based on each character's Unicode value.
static java.util.Comparator getNaturalComparatorIgnoreCaseAscii()
          Returns a comparator that compares contained numbers based on their numeric values and compares other parts based on each character's Unicode value while ignore upper/lower case differences.
static java.util.Comparator getNaturalTypeTreeLabelComparator()
          Returns a comparator that compares contained numbers based on their numeric values and compares other parts using the current locale's order rules.
static java.util.Comparator getNaturalTypeTreeLabelComparator(java.text.Collator collator)
          Returns a comparator that compares contained numbers based on their numeric values and compares other parts using the given collator.
static java.util.Comparator getNaturalTypeXPathComparator()
          Returns a comparator that compares contained numbers based on their numeric values and compares other parts using the current locale's order rules.
static java.util.Comparator getNaturalTypeXPathComparator(java.text.Collator collator)
          Returns a comparator that compares contained numbers based on their numeric values and compares other parts using the given collator.
static int indexOfIgnoreCase(java.lang.String string, java.lang.String substring, int fromIndex)
          Returns the index within the specified string of the first occurrence of the specified substring ignoring case considerations and starting at the specified index.
static boolean isInteger(java.lang.String myInput)
           
static boolean isNumeric(java.lang.String text)
          Checks whether the given input string is numeric.
static void main(java.lang.String[] args)
           
static int numberOfDigits(java.lang.String text)
          Counts the number of digits in the specified text.
static java.lang.String removeSpaceChars(java.lang.String result)
           
static java.lang.String removeSpecialChars(java.lang.String result)
           
static java.lang.String removeSpecialChars(java.lang.String result, boolean spaceIncluded)
           
static java.lang.String replace(java.lang.String text, java.lang.String oldCharacters, java.lang.String newCharacters)
          Replaces indicated characters with other characters.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

newLine

public static final java.lang.String newLine

newTab

public static final java.lang.String newTab

doubleQuote

public static final java.lang.String doubleQuote
See Also:
Constant Field Values

space

public static final java.lang.String space
See Also:
Constant Field Values
Constructor Detail

StringUtils

public StringUtils()
Method Detail

format

public static java.lang.String format(boolean left,
                                      char fill,
                                      int size,
                                      java.lang.String text)
Returns a formatted string.

Parameters:
left - true means left alignment otherwise rigth alignment
fill - filling character if the specified text is smaller than the resulting size
size - size of the formatted string
text - string which should be formated
Returns:
formatted string

format

public static void format(boolean left,
                          char fill,
                          int size,
                          java.lang.String text,
                          java.lang.StringBuffer buffer)
Formats a specified string and appends the formatted string to the buffer.

Parameters:
left - true means left alignment otherwise rigth alignment
fill - filling character if the specified text is smaller than the resulting size
size - size of the formatted string
text - string which should be formated
buffer - buffer where the formatted string will be appended

replace

public static java.lang.String replace(java.lang.String text,
                                       java.lang.String oldCharacters,
                                       java.lang.String newCharacters)
Replaces indicated characters with other characters.

Parameters:
text - string where characters should be replaced
oldCharacters - the character to be replaced by newCharacters.
newCharacters - the character replacing oldCharacters.
Returns:
replaced string.

numberOfDigits

public static int numberOfDigits(java.lang.String text)
Counts the number of digits in the specified text.

Parameters:
text - string
Returns:
number of digits in the specified text.

indexOfIgnoreCase

public static int indexOfIgnoreCase(java.lang.String string,
                                    java.lang.String substring,
                                    int fromIndex)
Returns the index within the specified string of the first occurrence of the specified substring ignoring case considerations and starting at the specified index. The integer returned is the smallest value k such that:
    string.startsWith(substring, <i>k</i>)
 
is true.

Parameters:
string - any string.
substring - any string.
fromIndex - the index from which to start the search.
Returns:
if the second string argument occurs as a substring within the first string argument, then the index of the first character of the first such substring is returned; if it does not occur as a substring, -1 is returned.
Throws:
java.lang.NullPointerException - if string or substring is null.

removeSpecialChars

public static java.lang.String removeSpecialChars(java.lang.String result,
                                                  boolean spaceIncluded)

removeSpecialChars

public static java.lang.String removeSpecialChars(java.lang.String result)

removeSpaceChars

public static java.lang.String removeSpaceChars(java.lang.String result)

isNumeric

public static boolean isNumeric(java.lang.String text)
Checks whether the given input string is numeric.

Parameters:
text - the text
Returns:
true when the given text represents an integer or double value

isInteger

public static boolean isInteger(java.lang.String myInput)

main

public static void main(java.lang.String[] args)

checkDistance

public static boolean checkDistance(java.lang.String source,
                                    char aChar,
                                    int distance)

checkDistance

public static boolean checkDistance(java.lang.String source,
                                    char[] aChar,
                                    int distance)

getNaturalComparator

public static java.util.Comparator getNaturalComparator()
Returns a comparator that compares contained numbers based on their numeric values and compares other parts using the current locale's order rules.

For example in German locale this will be a comparator that handles umlauts correctly and ignores upper/lower case differences.

Returns:

A string comparator that uses the current locale's order rules and handles embedded numbers correctly.

See Also:
getNaturalComparator(java.text.Collator)

getNaturalComparator

public static java.util.Comparator getNaturalComparator(java.text.Collator collator)
Returns a comparator that compares contained numbers based on their numeric values and compares other parts using the given collator.

Parameters:
collator - used for locale specific comparison of text (non-number) subwords - must not be null
Returns:

A string comparator that uses the given Collator to compare subwords and handles embedded numbers correctly.

See Also:
getNaturalComparator()

getNaturalTypeTreeLabelComparator

public static java.util.Comparator getNaturalTypeTreeLabelComparator()
Returns a comparator that compares contained numbers based on their numeric values and compares other parts using the current locale's order rules.

For example in German locale this will be a comparator that handles umlauts correctly and ignores upper/lower case differences.

Returns:

A string comparator that uses the current locale's order rules and handles embedded numbers correctly.

See Also:
getNaturalComparator(java.text.Collator)

getNaturalTypeTreeLabelComparator

public static java.util.Comparator getNaturalTypeTreeLabelComparator(java.text.Collator collator)
Returns a comparator that compares contained numbers based on their numeric values and compares other parts using the given collator.

Parameters:
collator - used for locale specific comparison of text (non-number) subwords - must not be null
Returns:

A string comparator that uses the given Collator to compare subwords and handles embedded numbers correctly.

See Also:
getNaturalComparator()

getNaturalTypeXPathComparator

public static java.util.Comparator getNaturalTypeXPathComparator()
Returns a comparator that compares contained numbers based on their numeric values and compares other parts using the current locale's order rules.

For example in German locale this will be a comparator that handles umlauts correctly and ignores upper/lower case differences.

Returns:

A string comparator that uses the current locale's order rules and handles embedded numbers correctly.

See Also:
getNaturalComparator(java.text.Collator)

getNaturalTypeXPathComparator

public static java.util.Comparator getNaturalTypeXPathComparator(java.text.Collator collator)
Returns a comparator that compares contained numbers based on their numeric values and compares other parts using the given collator.

Parameters:
collator - used for locale specific comparison of text (non-number) subwords - must not be null
Returns:

A string comparator that uses the given Collator to compare subwords and handles embedded numbers correctly.

See Also:
getNaturalComparator()

getNaturalComparatorAscii

public static java.util.Comparator getNaturalComparatorAscii()
Returns a comparator that compares contained numbers based on their numeric values and compares other parts based on each character's Unicode value.

Returns:

a string comparator that does case sensitive comparisons on pure ascii strings and handles embedded numbers correctly.

Do not use if your app might ever run on any locale that uses more than 7-bit ascii characters.
See Also:
getNaturalComparator(), getNaturalComparator(java.text.Collator)

getNaturalComparatorIgnoreCaseAscii

public static java.util.Comparator getNaturalComparatorIgnoreCaseAscii()
Returns a comparator that compares contained numbers based on their numeric values and compares other parts based on each character's Unicode value while ignore upper/lower case differences. Do not use if your app might ever run on any locale that uses more than 7-bit ascii characters.

Returns:

a string comparator that does case insensitive comparisons on pure ascii strings and handles embedded numbers correctly.

See Also:
getNaturalComparator(), getNaturalComparator(java.text.Collator)

compareNatural

public static int compareNatural(java.lang.String s,
                                 java.lang.String t)

Compares two strings using the current locale's rules and comparing contained numbers based on their numeric values.

This is probably the best default comparison to use.

If you know that the texts to be compared are in a certain language that differs from the default locale's langage, then get a collator for the desired locale (Collator.getInstance(java.util.Locale)) and pass it to compareNatural(java.text.Collator, String, String)

Parameters:
s - first string
t - second string
Returns:
zero iff s and t are equal, a value less than zero iff s lexicographically precedes t and a value larger than zero iff s lexicographically follows t

compareNatural

public static int compareNatural(java.text.Collator collator,
                                 java.lang.String s,
                                 java.lang.String t)

Compares two strings using the given collator and comparing contained numbers based on their numeric values.

Parameters:
s - first string
t - second string
Returns:
zero iff s and t are equal, a value less than zero iff s lexicographically precedes t and a value larger than zero iff s lexicographically follows t

compareNaturalAscii

public static int compareNaturalAscii(java.lang.String s,
                                      java.lang.String t)

Compares two strings using each character's Unicode value for non-digit characters and the numeric values off any contained numbers.

(This will probably make sense only for strings containing 7-bit ascii characters only.)

Returns:
zero iff s and t are equal, a value less than zero iff s lexicographically precedes t and a value larger than zero iff s lexicographically follows t

compareNaturalIgnoreCaseAscii

public static int compareNaturalIgnoreCaseAscii(java.lang.String s,
                                                java.lang.String t)

Compares two strings using each character's Unicode value - ignoring upper/lower case - for non-digit characters and the numeric values of any contained numbers.

(This will probably make sense only for strings containing 7-bit ascii characters only.)

Returns:
zero iff s and t are equal, a value less than zero iff s lexicographically precedes t and a value larger than zero iff s lexicographically follows t