com.mizar.commons.lang
Class StringUtils

java.lang.Object
  extended by org.apache.commons.lang.StringUtils
      extended by com.mizar.commons.lang.StringUtils

public class StringUtils
extends org.apache.commons.lang.StringUtils


Field Summary
protected static java.lang.String[] BYTE_AS_HEX
           
protected static char[] VOWELS
           
 
Fields inherited from class org.apache.commons.lang.StringUtils
EMPTY, INDEX_NOT_FOUND
 
Constructor Summary
protected StringUtils()
           
 
Method Summary
static java.lang.String arrayToString(java.lang.String[] array, java.lang.String separators)
          Takes an array of tokens and converts into separator-separated string.
static java.lang.String changeWhitespaceToPercents(java.lang.String string)
          Trims and wraps a string and replaces all whitespace with single % signs.
static java.lang.String chop(java.lang.String string, int i)
          Chop i characters off the end of a string.
static java.lang.String chop(java.lang.String string, int i, java.lang.String eol)
          Chop i characters off the end of a string.
static java.lang.String collapseNewlines(java.lang.String argStr)
          Remove/collapse multiple newline characters.
static java.lang.String collapseSpaces(java.lang.String string)
          Remove/collapse multiple spaces.
static java.lang.String columnToLabel(java.lang.String inString)
          This rather special purpose method converts strings like COLUMN_NAME to Column Name
static java.lang.String concat(java.util.List list)
          Concatenates a list of objects as a String.
static int decodeRGBHex(java.lang.String hexColor)
           
static java.lang.String digitsRangeFrom(java.lang.String range)
          Extract the first part of a digits range.
static java.lang.String digitsRangeTo(java.lang.String range)
          Extract the last part of a digits range.
static java.lang.String doubleTick(java.lang.String varchar)
          converts single ticks to double ticks, e.g.
static java.lang.String escapeWithSeq(java.lang.String inString, java.lang.String sEsc, java.lang.String spSeq)
          Allows the ability to add special ESC character to prepend special characters, which is useful for Oracle SQL, or forming URLs.
static java.lang.String fileContentsToString(java.lang.String file)
          Read the contents of a file and place them in a string object.
static java.lang.String firstLetterCaps(java.lang.String data)
           Makes the first letter caps and the rest lowercase.
static java.lang.String fromCamelCase(java.lang.String inString)
          Converts a camelCase string to a human-readable string fromCamelCase("totUseArea") returns "Tot Use Area"
static java.lang.String getCommonPrefix(java.lang.String[] strings)
           
static java.lang.String getOracleUsernameOrPassword(java.lang.String suggest)
           
static java.lang.String getProperty(java.lang.String label, java.lang.String string)
          A case-insensitive label=value parser
static boolean hasLength(java.lang.String string)
           
static boolean isAlphaSpace(java.lang.String s)
           
static boolean isBlank(java.lang.String string)
           
static boolean isDecimalOnly(java.lang.String s)
          Determines if the string is a valid decimal number.
static boolean isDigitsRangeOnly(java.lang.String s)
          Determines if the string represents a valid digit range.
static boolean isValidEmail(java.lang.String s)
          Returns true is the submitted email addresses is compatible with RFC 2822.
static java.lang.String joinDoubleArr(double[] d, java.lang.String separator)
           
static java.lang.String leftBack(java.lang.String source, java.lang.String searchFor)
          Returns the substring to the left of the specified substring in the specified String, starting from the right.
static void main(java.lang.String[] args)
           
static java.lang.String middle(java.lang.String source, java.lang.String start, java.lang.String end)
          Returns the substring between two substrings.
static java.lang.String normalizePath(java.lang.String path)
          Return a context-relative path, beginning with a "/", that represents the canonical version of the specified path after ".." and "." elements are resolved out.
static java.lang.String nullTrim(java.lang.String s)
          Trim the string, but pass a null through.
static java.lang.String removeDuplicateWhitespace(java.lang.String inputString)
          Removes duplicate whitespace from a string

Converts "this is a string" into "this is a string".
static java.lang.String removeWhitespace(java.lang.String inputString)
           
static java.lang.String replace(java.lang.String source, java.lang.String[] searchFor, java.lang.String replaceWith)
          Replaces several substrings in a string.
static java.lang.String replaceDuplicateWhitespace(java.lang.String inputString, java.lang.String replacement)
          Reaplces whitespace in a string with a given string
static java.lang.String replacePattern(java.lang.String patternString, java.lang.String inputString, java.lang.String replacement)
           
static java.lang.String replaceVars(java.lang.String origString, java.util.Map vars)
          Performs variable substitution for a string.
static java.lang.String rightBack(java.lang.String source, java.lang.String searchFor)
          Returns the substring to the right of the specified substring in the specified String, starting from the right.
static java.lang.String shorten(java.lang.String string, int maxLength)
          The method removes vowels attempting to shorten string to maxLength.
static java.util.Map sortMapByValue(java.util.Map map)
          Returns map sorted by value
static java.lang.String[] split(java.lang.String line, java.lang.String delim)
          Create a string array from a string separated by delim
static java.util.Map splitStringPairs(java.lang.String list, java.lang.String separator, java.lang.String pairSeparator)
          Converts separated list of pairs into an array list
static java.util.Map splitStringPairs(java.lang.String list, java.lang.String separator, java.lang.String pairSeparator, boolean sortByValue)
          Same as splitStringPairs but returnes a sequenced map sorted by entry value
static java.lang.String stackTrace(java.lang.Throwable e)
          Returns the output of printStackTrace as a String.
static java.lang.String stripExtension(java.lang.String filename)
          Given a filename, strips the .extension
static java.lang.String subString(java.lang.String string, int length)
          This method is required because String.substr(0,n) fails when n is less than String.area()
static java.lang.String toCamelCase(java.lang.String inString)
          Convert a variety of token separated string patterns to camelCase.
static java.lang.String toCamelCase(java.lang.String inString, java.lang.String tokens)
          Convert a variety of token separated string patterns to camelCase.
static java.lang.String toCurrency(java.lang.Double amount, java.lang.String iso4127CurrencyCode)
          If the iso4127CurrencyCode is not valid then the number will still be returned but without a currency symbol.
static java.lang.String toDollarsAndCents(java.lang.Double amount)
           
static java.lang.String toHex(byte[] bytes)
          This is a passthrough to the com.apache.commons.lang.StringUtils method to satisfy a JDeveloper compiler problem
static java.lang.String toMixedCase(java.lang.String inString)
          The method reduces the input string to lower case and then converts all characters preceded by a blank to upper case.
static java.lang.String trim(java.lang.String string)
           
static java.util.List trimStrings(java.util.List list)
          Trim all strings in a List.
static java.lang.String unique(java.lang.String source)
          A utility method to remove duplicate characters from a string.
static java.lang.String wrapInSimpleHtml(java.util.List<java.lang.String> strings, boolean paragraph)
           
static java.lang.String wrapWithPercents(java.lang.String string)
          Trims and wraps a string with percent signs, which is useful for Oracle SQL wildcarding.
 
Methods inherited from class org.apache.commons.lang.StringUtils
abbreviate, abbreviate, abbreviateMiddle, capitalise, capitaliseAllWords, capitalize, center, center, center, chomp, chomp, chompLast, chompLast, chop, chopNewline, clean, concatenate, contains, contains, containsAny, containsAny, containsIgnoreCase, containsNone, containsNone, containsOnly, containsOnly, countMatches, defaultIfBlank, defaultIfEmpty, defaultString, defaultString, deleteSpaces, deleteWhitespace, difference, endsWith, endsWithAny, endsWithIgnoreCase, equals, equalsIgnoreCase, escape, getChomp, getLevenshteinDistance, getNestedString, getNestedString, getPrechomp, indexOf, indexOf, indexOf, indexOf, indexOfAny, indexOfAny, indexOfAny, indexOfAnyBut, indexOfAnyBut, indexOfDifference, indexOfDifference, indexOfIgnoreCase, indexOfIgnoreCase, isAllLowerCase, isAllUpperCase, isAlpha, isAlphanumeric, isAlphanumericSpace, isAsciiPrintable, isEmpty, isNotBlank, isNotEmpty, isNumeric, isNumericSpace, isWhitespace, join, join, join, join, join, join, join, join, join, lastIndexOf, lastIndexOf, lastIndexOf, lastIndexOf, lastIndexOfAny, lastIndexOfIgnoreCase, lastIndexOfIgnoreCase, lastOrdinalIndexOf, left, leftPad, leftPad, leftPad, length, lowerCase, lowerCase, mid, normalizeSpace, ordinalIndexOf, overlay, overlayString, prechomp, remove, remove, removeEnd, removeEndIgnoreCase, removeStart, removeStartIgnoreCase, repeat, repeat, replace, replace, replaceChars, replaceChars, replaceEach, replaceEachRepeatedly, replaceOnce, reverse, reverseDelimited, reverseDelimitedString, right, rightPad, rightPad, rightPad, split, split, split, splitByCharacterType, splitByCharacterTypeCamelCase, splitByWholeSeparator, splitByWholeSeparator, splitByWholeSeparatorPreserveAllTokens, splitByWholeSeparatorPreserveAllTokens, splitPreserveAllTokens, splitPreserveAllTokens, splitPreserveAllTokens, splitPreserveAllTokens, startsWith, startsWithAny, startsWithIgnoreCase, strip, strip, stripAll, stripAll, stripEnd, stripStart, stripToEmpty, stripToNull, substring, substring, substringAfter, substringAfterLast, substringBefore, substringBeforeLast, substringBetween, substringBetween, substringsBetween, swapCase, trimToEmpty, trimToNull, uncapitalise, uncapitalize, upperCase, upperCase
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BYTE_AS_HEX

protected static final java.lang.String[] BYTE_AS_HEX

VOWELS

protected static final char[] VOWELS
Constructor Detail

StringUtils

protected StringUtils()
Method Detail

toHex

public static java.lang.String toHex(byte[] bytes)
This is a passthrough to the com.apache.commons.lang.StringUtils method to satisfy a JDeveloper compiler problem

Parameters:
stringArray -
Returns:

decodeRGBHex

public static int decodeRGBHex(java.lang.String hexColor)
Parameters:
hexColor - a six hexidecimal RBG color code
Returns:
a RBG int suitable to construct a java.awt.Color instance

isDecimalOnly

public static boolean isDecimalOnly(java.lang.String s)
Determines if the string is a valid decimal number. That is it has only digits and no more than 1 decimal point.

Parameters:
s -
Returns:
true if s only contains the digits 0-9 and no more than one decimal point.

isAlphaSpace

public static boolean isAlphaSpace(java.lang.String s)

isDigitsRangeOnly

public static boolean isDigitsRangeOnly(java.lang.String s)
Determines if the string represents a valid digit range. The string must have the form "[int]-[int]", or "[int] to [int]" or "[int]/[int]".

Parameters:
s - any String
Returns:
true if s is of the form "111-999" or "111 to 999 or 123/234"

isValidEmail

public static boolean isValidEmail(java.lang.String s)
Returns true is the submitted email addresses is compatible with RFC 2822.

The function can't check if the email address is deliverable but can check if it meets all the criteria for being generally valid. This will mean that asdf@asdf.asdf will be considered a valid email address by this function.

Parameters:
s -
Returns:

getProperty

public static java.lang.String getProperty(java.lang.String label,
                                           java.lang.String string)
A case-insensitive label=value parser

Parameters:
label - the label to test for
string - a string in the form label=value
Returns:
value if label is found, otherwise null

digitsRangeFrom

public static java.lang.String digitsRangeFrom(java.lang.String range)
Extract the first part of a digits range. It will return "111" from "111-999"

Parameters:
range - a String in the form 111-999 or 111 to 999
Returns:
the first sequence of digits
See Also:
digitsRangeTo(String), isDigitsRangeOnly(String)

digitsRangeTo

public static java.lang.String digitsRangeTo(java.lang.String range)
Extract the last part of a digits range. It will return "999" from "111-999"

Parameters:
range - a String in the form 111-999 or 111 to 999
Returns:
the second sequence of digits
See Also:
digitsRangeFrom(String), isDigitsRangeOnly(String)

toCamelCase

public static java.lang.String toCamelCase(java.lang.String inString)
Convert a variety of token separated string patterns to camelCase. Tokens include underbar, dash, period, and whitespace.

toCamelCase(String s) calls toCamelCase(String s, String t) where t is "_ \\.-".

Examples:

toCamelCase("MY_TABLE") returns myTable
toCamelCase("_MY_TABLE") returns MyTable
toCamelCase("MY-TABLE") returns myTable

Parameters:
inString - an input string of the form TABLE_NAME
Returns:
input string in camelCase or the original inString if no matching tokens are found.

toCamelCase

public static java.lang.String toCamelCase(java.lang.String inString,
                                           java.lang.String tokens)
Convert a variety of token separated string patterns to camelCase. Tokens This string will be place inside of square brackets and used as follows:

java.util.regex.Pattern pattern = Pattern.compile("["+tokens+"]([a-zA-Z])", Pattern.CASE_INSENSITIVE);

Examples:

toCamelCase("MY_TABLE") returns myTable
toCamelCase("_MY_TABLE") returns MyTable
toCamelCase("MY-TABLE") returns myTable

Parameters:
inString - an input string of the form TABLE_NAME
tokens - a string of token separators that will trigger a camel's hump.
Returns:
input string in camelCase or the original inString if no matching tokens are found.

fromCamelCase

public static java.lang.String fromCamelCase(java.lang.String inString)
Converts a camelCase string to a human-readable string fromCamelCase("totUseArea") returns "Tot Use Area"

Parameters:
inString - an input string presumably in camelCase format
Returns:
input string with spaces inserted between camelCase words and The First Letter Of Every Word Capitalized

columnToLabel

public static java.lang.String columnToLabel(java.lang.String inString)
This rather special purpose method converts strings like COLUMN_NAME to Column Name

Parameters:
inString - a String that presumably has underbar characters in it.
Returns:
a mixed case string without underbars
See Also:
StringUtils.replace(String, String, String), toMixedCase(String)

escapeWithSeq

public static java.lang.String escapeWithSeq(java.lang.String inString,
                                             java.lang.String sEsc,
                                             java.lang.String spSeq)
Allows the ability to add special ESC character to prepend special characters, which is useful for Oracle SQL, or forming URLs. This utility will not escape a sequence that has already been escaped. "Bob's and Carol's Tavern","'","'" becomes "Bob''s and Carol''s Tavern" "A good website www.test.com","www","http://" becomes "A good website http://www.test.com"

Parameters:
inString - the string that contains a character or a sequence to be escaped
sEsc - a String that is the character or sequence that needs to be escaped
spSeq - a String that is the character or sequence that has special meaning used to escape a sequence
Returns:
string with special charaters or sequences prepended with escapse clauses

wrapWithPercents

public static java.lang.String wrapWithPercents(java.lang.String string)
Trims and wraps a string with percent signs, which is useful for Oracle SQL wildcarding. " All these nights " becomes "%All these nights%"

Parameters:
string -
Returns:
string wrapped with % signs

changeWhitespaceToPercents

public static java.lang.String changeWhitespaceToPercents(java.lang.String string)
Trims and wraps a string and replaces all whitespace with single % signs. " All these nights " becomes "%All%these%nights%"

Parameters:
string -
Returns:
string with leading and trailing % signs and all whitespace replace by single % signs

toMixedCase

public static java.lang.String toMixedCase(java.lang.String inString)
The method reduces the input string to lower case and then converts all characters preceded by a blank to upper case. The method also handles words beginning Mc and Mac resulting in McDonald and MacDonald. This method is not very efficient and should therefore be used with caution.

Parameters:
inString - for example "MACDOWELL ST"
Returns:
a mixed case string

removeDuplicateWhitespace

public static java.lang.String removeDuplicateWhitespace(java.lang.String inputString)
Removes duplicate whitespace from a string

Converts "this is a string" into "this is a string".

Parameters:
inputString - String to remove duplicate whitespace
Returns:
String with extra whitespace removed

replaceDuplicateWhitespace

public static java.lang.String replaceDuplicateWhitespace(java.lang.String inputString,
                                                          java.lang.String replacement)
Reaplces whitespace in a string with a given string

Parameters:
inputString - string to search for whitespace
replacement - string to be substituted into inputString
Returns:
modified inputString with duplicate whitespace replaced with replacement

doubleTick

public static java.lang.String doubleTick(java.lang.String varchar)
converts single ticks to double ticks, e.g. "Dave's and Martha's Tavern" becomes "Dave''s and Martha''s Tavern"

Parameters:
varchar -
Returns:

replacePattern

public static java.lang.String replacePattern(java.lang.String patternString,
                                              java.lang.String inputString,
                                              java.lang.String replacement)

concat

public static java.lang.String concat(java.util.List list)
Concatenates a list of objects as a String.

Parameters:
list - The list of objects to concatenate.
Returns:
A text representation of the concatenated objects.

firstLetterCaps

public static java.lang.String firstLetterCaps(java.lang.String data)

Makes the first letter caps and the rest lowercase.

For example fooBar becomes Foobar.

Parameters:
data - capitalize this
Returns:
String

split

public static java.lang.String[] split(java.lang.String line,
                                       java.lang.String delim)
Create a string array from a string separated by delim

Parameters:
line - the line to split
delim - the delimter to split by
Returns:
a string array of the split fields

chop

public static java.lang.String chop(java.lang.String string,
                                    int i)
Chop i characters off the end of a string. This method assumes that any EOL characters in String s and the platform EOL will be the same. A 2 character EOL will count as 1 character.

Parameters:
string - String to chop.
i - Number of characters to chop.
Returns:
String with processed answer.

chop

public static java.lang.String chop(java.lang.String string,
                                    int i,
                                    java.lang.String eol)
Chop i characters off the end of a string. A 2 character EOL will count as 1 character.

Parameters:
string - String to chop.
i - Number of characters to chop.
eol - A String representing the EOL (end of line).
Returns:
String with processed answer.

fileContentsToString

public static java.lang.String fileContentsToString(java.lang.String file)
Read the contents of a file and place them in a string object.

Parameters:
file - path to file.
Returns:
String contents of the file.

collapseNewlines

public static java.lang.String collapseNewlines(java.lang.String argStr)
Remove/collapse multiple newline characters.

Parameters:
String - string to collapse newlines in.
Returns:
String

collapseSpaces

public static java.lang.String collapseSpaces(java.lang.String string)
Remove/collapse multiple spaces.

Parameters:
string - string to remove multiple spaces from.
Returns:
String

stackTrace

public static final java.lang.String stackTrace(java.lang.Throwable e)
Returns the output of printStackTrace as a String.

Parameters:
e - A Throwable.
Returns:
A String.

normalizePath

public static final java.lang.String normalizePath(java.lang.String path)
Return a context-relative path, beginning with a "/", that represents the canonical version of the specified path after ".." and "." elements are resolved out. If the specified path attempts to go outside the boundaries of the current context (i.e. too many ".." path elements are present), return null instead.

Parameters:
path - Path to be normalized
Returns:
String normalized path

subString

public static java.lang.String subString(java.lang.String string,
                                         int length)
This method is required because String.substr(0,n) fails when n is less than String.area()

Parameters:
length - the maximum area of string to return
Returns:
the input string trimed to a area of no more than area characters

trimStrings

public static java.util.List trimStrings(java.util.List list)
Trim all strings in a List. Changes the strings in the existing list.

Parameters:
list -
Returns:

nullTrim

public static java.lang.String nullTrim(java.lang.String s)
Trim the string, but pass a null through.

Parameters:
s -
Returns:

arrayToString

public static final java.lang.String arrayToString(java.lang.String[] array,
                                                   java.lang.String separators)
Takes an array of tokens and converts into separator-separated string.

Parameters:
array - The array of strings input.
separators - The string separator.
Returns:
String A string containing tokens separated by seperator.

stripExtension

public static java.lang.String stripExtension(java.lang.String filename)
Given a filename, strips the .extension


replaceVars

public static java.lang.String replaceVars(java.lang.String origString,
                                           java.util.Map vars)
Performs variable substitution for a string. String is scanned for ${variable_name} and if one is found, it is replaced with corresponding value from the vars hashtable.

Parameters:
origString - unmodified string
vars - Hashtable of replacement values
Returns:
modified string
Throws:
java.lang.Exception

splitStringPairs

public static java.util.Map splitStringPairs(java.lang.String list,
                                             java.lang.String separator,
                                             java.lang.String pairSeparator)
Converts separated list of pairs into an array list

Parameters:
list - list of values separated by the separator parameter
separator - defaults to comma
Returns:
sorted map

splitStringPairs

public static java.util.Map splitStringPairs(java.lang.String list,
                                             java.lang.String separator,
                                             java.lang.String pairSeparator,
                                             boolean sortByValue)
Same as splitStringPairs but returnes a sequenced map sorted by entry value

Parameters:
list -
separator -
pairSeparator -
Returns:

sortMapByValue

public static java.util.Map sortMapByValue(java.util.Map map)
Returns map sorted by value

Parameters:
map -
Returns:

rightBack

public static java.lang.String rightBack(java.lang.String source,
                                         java.lang.String searchFor)
Returns the substring to the right of the specified substring in the specified String, starting from the right.

Parameters:
source - the source String to search.
searchFor - the substring to search for in source.
Returns:
the substring that is to the right of searchFor in source, starting from the right.

leftBack

public static java.lang.String leftBack(java.lang.String source,
                                        java.lang.String searchFor)
Returns the substring to the left of the specified substring in the specified String, starting from the right.

Parameters:
source - the source String to search.
searchFor - the substring to search for in source.
Returns:
the substring that is to the left of searchFor in source, starting from the right.

middle

public static java.lang.String middle(java.lang.String source,
                                      java.lang.String start,
                                      java.lang.String end)
Returns the substring between two substrings. I.e. StringUtils.middle("This i a big challenge", "a", "challenge") returns " big ".

Parameters:
source - the String to search.
start - the String to the left to search for, from the left.
end - the String to the right to search for, from the right.

replace

public static java.lang.String replace(java.lang.String source,
                                       java.lang.String[] searchFor,
                                       java.lang.String replaceWith)
Replaces several substrings in a string.

Parameters:
source - the source String to replace substrings in.
searchFor - the substrings to search for.
replaceWith - what to replace every searchFor with,

unique

public static java.lang.String unique(java.lang.String source)
A utility method to remove duplicate characters from a string. For example, it would convert "hello" to "helo", and "abcd123abcaaa" to "abcd123".

Parameters:
source - the String to remove all duplicate characters in.
Returns:
a String with no duplicate characters.

joinDoubleArr

public static java.lang.String joinDoubleArr(double[] d,
                                             java.lang.String separator)

getOracleUsernameOrPassword

public static java.lang.String getOracleUsernameOrPassword(java.lang.String suggest)

removeWhitespace

public static java.lang.String removeWhitespace(java.lang.String inputString)

hasLength

public static boolean hasLength(java.lang.String string)
Parameters:
string - can be null or zero area.
Returns:
true if not null and area greater than 0

trim

public static java.lang.String trim(java.lang.String string)

isBlank

public static boolean isBlank(java.lang.String string)
Parameters:
string - can be null or zero area.
Returns:
true if string is null, zero area, or only whitespace; false in all other conditions.

toDollarsAndCents

public static java.lang.String toDollarsAndCents(java.lang.Double amount)
Parameters:
amount -
Returns:
See Also:
toCurrency(java.lang.Double, java.lang.String)

toCurrency

public static java.lang.String toCurrency(java.lang.Double amount,
                                          java.lang.String iso4127CurrencyCode)
If the iso4127CurrencyCode is not valid then the number will still be returned but without a currency symbol.

Parameters:
amount -
iso4127CurrencyCode - for example USD, EUR, CAD, JPY, etc.
Returns:

shorten

public static java.lang.String shorten(java.lang.String string,
                                       int maxLength)
The method removes vowels attempting to shorten string to maxLength. It removes the last vowel first, then the first vowel, then the last, then the first; and so on. Once all the vowels are removed the method returns; so if there are more the maxLength non-vowels in string string will be returned with more than maxLength characters in the returned string

Parameters:
string -
maxLength -
Returns:

wrapInSimpleHtml

public static java.lang.String wrapInSimpleHtml(java.util.List<java.lang.String> strings,
                                                boolean paragraph)

getCommonPrefix

public static java.lang.String getCommonPrefix(java.lang.String[] strings)

main

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