ucar.unidata.util
Class StringUtil

java.lang.Object
  extended by ucar.unidata.util.StringUtil

public class StringUtil
extends java.lang.Object

String utilities


Field Summary
static boolean debug
          debug flag
static java.lang.String[] ordinalNames
          Ordinal names for images
 
Constructor Summary
StringUtil()
           
 
Method Summary
static java.lang.String allow(java.lang.String x, java.lang.String allowChars, char replaceChar)
          Replace any char not alphanumeric or in allowChars by replaceChar.
static java.lang.StringBuffer append(java.lang.StringBuffer sb, java.lang.Object s1)
          A utility method to an append to a StringBuffer.
static java.lang.StringBuffer append(java.lang.StringBuffer sb, java.lang.Object s1, java.lang.Object s2)
          A utility method to do multiple appends to a StringBuffer.
static java.lang.StringBuffer append(java.lang.StringBuffer sb, java.lang.Object s1, java.lang.Object s2, java.lang.Object s3)
          A utility method to do multiple appends to a StringBuffer.
static java.lang.StringBuffer append(java.lang.StringBuffer sb, java.lang.Object s1, java.lang.Object s2, java.lang.Object s3, java.lang.Object s4)
          A utility method to do multiple appends to a StringBuffer.
static java.lang.StringBuffer append(java.lang.StringBuffer sb, java.lang.Object s1, java.lang.Object s2, java.lang.Object s3, java.lang.Object s4, java.lang.Object s5)
          A utility method to do multiple appends to a StringBuffer.
static java.lang.String applyMacros(java.lang.String s, java.util.Hashtable props, boolean throwError)
          This takes a string of the following form.
static java.lang.String breakText(java.lang.String text, java.lang.String insert, int lineSize)
          Convert the given text to html by adding <br>.
static java.lang.String breakTextAtWords(java.lang.String text, java.lang.String insert, int lineSize)
          Break the given text into lines, respecting word boundaries (blank space).
static java.lang.String camelCase(java.lang.String s)
          Camel case a string (eg howard -> Howard)
static java.lang.String collapseWhitespace(java.lang.String s)
          Collapse continuous whitespace into one single " ".
static boolean containsRegExp(java.lang.String patternString)
          See if a pattern string contains regular expression characters (^,*,$,+).
static java.lang.String escape(java.lang.String x, java.lang.String okChars)
          Escape any char not alphanumeric or in okChars.
static java.lang.String escape2(java.lang.String x, java.lang.String reservedChars)
          Escape any char in reservedChars.
static java.util.List expandIso8601(java.lang.String time)
          A first attempt at parsing a dttm range string
static java.lang.String filter(java.lang.String x, java.lang.String okChars)
          Remove any char not alphanumeric or in okChars.
static java.lang.String filter7bits(java.lang.String s)
          Remove all but printable 7bit ascii
static java.lang.String findFormatString(java.lang.String macroName, java.lang.String macroDelimiter, java.lang.String text)
          Return the format string in the given text for the given macro.
static java.lang.Object findMatch(java.lang.String source, java.util.List patternList, java.util.List results, java.lang.Object dflt)
          Run through the List of patterns (pattern, result) and return corresponding result whose pattern matches the source string.
static java.lang.Object findMatch(java.lang.String source, java.util.List patternList, java.lang.Object dflt)
          Run through the List of Objects and return the Object whose toString matches the source string.
static java.lang.String findPattern(java.lang.String source, java.lang.String patternString)
          Find the pattern in a string
static java.lang.String getAnOrA(java.lang.String subject)
          Get "a" or "an" for prefixing to a string based on the first character
static boolean isDigits(java.lang.String s)
          Return true if all characters are numeric.
static boolean isLowerCase(java.lang.String s)
          Is the string all lower case?
static boolean isUpperCase(java.lang.String s)
          Is the string all upper case?
static java.lang.String join(java.lang.String[] args)
          Merge the given strings, using a space between each.
static java.lang.String join(java.lang.String delimiter, java.util.List args)
          Merge the given strings, using the given delimiter between each.
static java.lang.String join(java.lang.String delimiter, java.util.List args, boolean ignoreEmptyStrings)
          Merge the given strings, using the given delimiter between each.
static java.lang.String join(java.lang.String delimiter, java.lang.Object[] args)
          Merge the given strings, using the given delimiter between each.
static java.lang.String join(java.lang.String delimiter, java.lang.Object[] args, boolean ignoreEmptyStrings)
          Merge the given strings, using the given delimiter between each.
static java.lang.String listToString(java.util.List l)
          Take the List of objects and return a String of all the list's elements toString values appended to each other, separated by semicolons
static java.lang.String[] listToStringArray(java.util.List objectList)
          Take the List of objects and return a String array of the toString values of each object in the list.
static void main(java.lang.String[] args)
          Method for debugging.
static void main2(java.lang.String[] args)
          test
static void main3(java.lang.String[] args)
          test
static int match(java.lang.String s1, java.lang.String s2)
          Count number of chars that match in two strings, starting from front.
static boolean notEmpty(java.lang.String s)
          Check if the string is not empty
static java.lang.String padLeft(java.lang.String s, int desiredLength)
          Pad the given string with spaces on the left up to the given length.
static java.lang.String padLeft(java.lang.String s, int desiredLength, java.lang.String padString)
          Pad the given string with padString on the left up to the given length.
static java.lang.String padRight(java.lang.String s, int desiredLength)
          Pad the given string with spaces on the right up to the given length.
static java.lang.String padRight(java.lang.String s, int desiredLength, java.lang.String padString)
          Pad the given string with padString on the right up to the given length.
static java.lang.String padZero(int value, int numDigits)
          Left pad the given value with zeros up to the number of digits
static double[][] parseCoordinates(java.lang.String coords)
          Parse the lat/lon/alt coordinate string
static java.util.List parseCsv(java.lang.String s, boolean skipFirst)
          Parse a comma separated value (CVS) String
static java.util.Date parseDate(java.lang.String dttm)
          Parse the date.
static java.util.Hashtable parseHtmlProperties(java.lang.String s)
          Parse HTML Properties
static java.util.List parseIntegerListString(java.lang.String s)
          Parse the given string and return a list of Integer values.
static java.util.Date parseIso8601(java.lang.String time)
          Not working yet but this is supposed to parse an iso8601 date format
static java.util.List<java.lang.String[]> parseLineWords(java.lang.String content, int[] indices, int[] lengths, java.lang.String lineDelimiter, java.lang.String commentString, boolean trimWords)
          This splits the given content String into a set of lines (delimited by the given lineDelimiter).
static java.util.List<java.lang.String[]> parseLineWords(java.lang.String content, int[] lengths, java.lang.String lineDelimiter, java.lang.String commentString, boolean trimWords)
          This splits the given content String into a set of lines (delimited by the given lineDelimiter).
static java.util.Hashtable parsePropertiesString(java.lang.String s)
          Parse the semi-colon delimited string of name=value properties.
static long parseTimePeriod(java.lang.String s)
          Note, right now this just parses the hour/minute/second periods
static java.lang.String quoteHtmlContent(java.lang.String x)
          Replace special characters with entities for HTML content.
static java.lang.String quoteXmlAttribute(java.lang.String x)
          Replace special characters with entities for XML attributes.
static java.lang.String quoteXmlContent(java.lang.String x)
          Replace special characters with entities for XML attributes.
static boolean regexpMatch(java.lang.String input, java.lang.String patternString)
          Match a regular expression
static java.lang.String remove(java.lang.String s, int c)
          Remove all occurrences of the character c in the string s.
static java.lang.String remove(java.lang.String s, java.lang.String sub)
          Remove all occurrences of the substring sub in the string s.
static java.lang.String removeWhitespace(java.lang.String inputString)
          Remove any whitespace (ie., Character.isWhitespace) from the input string.
static java.lang.String repeat(java.lang.String s, int cnt)
          Concatentate the given string cnt times
static void replace(java.lang.StringBuffer sb, char out, java.lang.String in)
          Replace any char "out" in sb with "in".
static java.lang.String replace(java.lang.String x, char[] replaceChar, java.lang.String[] replaceWith)
          Replace all occurences of replaceChar with replaceWith
static java.lang.String replace(java.lang.String s, char out, java.lang.String in)
          Replace any char "out" in s with "in".
static java.lang.String replace(java.lang.String string, java.lang.String pattern, java.lang.String value)
          Replaces all occurrences of "pattern" in "string" with "value"
static java.lang.String replaceDate(java.lang.String s, java.lang.String macroName, java.util.Date date)
          Replace the macro within s with the formatted date.
static java.lang.String replaceDate(java.lang.String s, java.lang.String macroName, java.util.Date date, java.lang.String macroPrefix, java.lang.String macroSuffix)
          Replace the macro within s with the formatted date.
static java.util.List replaceList(java.util.List sourceList, java.lang.String[] patterns, java.lang.String[] values)
          Construct and return a list of Strings where each string is the result of replacing all of the patterns with the corresponding values for each String in the given sourceList .
static java.lang.String replaceList(java.lang.String v, java.util.List patterns, java.util.List values)
          Replaces all occurrences of "patterns" in "v" with "values"
static java.lang.String replaceList(java.lang.String v, java.lang.String[] patterns, java.lang.String[] values)
          Replaces all occurrences of "patterns" in "v" with "values"
static java.lang.String shorten(java.lang.String s, int length)
          Shorten a string using elipses (...)
static java.util.List<java.lang.String> split(java.lang.Object source)
          Tokenize the toString value of the given source object, splitting on ",".
static java.util.List<java.lang.String> split(java.lang.Object source, java.lang.String delimiter)
          Tokenize the toString value of the given source object, splitting on the given delimiter.
static java.util.List<java.lang.String> split(java.lang.Object source, java.lang.String delimiter, boolean trim)
          Tokenize the toString value of the given source object, splitting on the given delimiter.
static java.util.List<java.lang.String> split(java.lang.Object source, java.lang.String delimiter, boolean trim, boolean excludeZeroLength)
          Tokenize the toString value of the given source object, splitting on the given delimiter.
static java.lang.String[] split(java.lang.String s, java.lang.String delimiter, int cnt)
          Split the given string into the first cnt number of substrings as delimited by the given delimiter.
static java.util.List<java.lang.String> splitMacros(java.lang.String s)
          This parses the given string with the following form.
static java.util.List<java.lang.String> splitUpTo(java.lang.String s, java.lang.String delimiter, int cnt)
          Split up to a certain number of characters
static java.util.List<java.lang.String> splitWithQuotes(java.lang.String s)
          tokenize the given string on spaces.
static boolean startsWithVowel(java.lang.String value)
          Check to see if the string starts with a vowel.
static boolean stringMatch(java.lang.String input, java.lang.String patternString)
          Check if the given input String matches the given pattern String.
static boolean stringMatch(java.lang.String input, java.lang.String patternString, boolean substring, boolean caseSensitive)
          Check if the given input String matches the given pattern String.
static java.lang.String stripAndReplace(java.lang.String s, java.lang.String pattern1, java.lang.String pattern2, java.lang.String replace)
          Replaces all occurrences of the strings delimited by patter1/pattern2 with replace, e.g.: "pattern1 ...
static java.lang.String stripHtmlTag(java.lang.String html)
          Remove any beginning or ending <html> tags
static java.lang.String stripTags(java.lang.String html)
          Remove all text contained within "< >" tags.
static void substitute(java.lang.StringBuffer sbuff, java.lang.String match, java.lang.String subst)
          Find all occurences of the "match" in original, and substitute the "subst" string, directly into the original.
static java.lang.String substitute(java.lang.String original, java.lang.String[] match, java.lang.String[] subst)
          Find all occurences of match strings in original, and substitute the corresponding subst string.
static java.lang.String substitute(java.lang.String original, java.lang.String match, java.lang.String subst)
          Find all occurences of the "match" in original, and substitute the "subst" string.
static java.lang.String toHexString(java.awt.Color c)
          Convert the given color to is string hex representation
static java.util.List toString(java.util.List l)
          Convert the list of objects to a list of strings.
static java.lang.String toString(java.lang.Object[] array)
          Create a string representation of the given array
static java.lang.String unescape(java.lang.String x)
          This finds any '%xx' and converts to the equivilent char.
static java.lang.String unquoteXmlAttribute(java.lang.String x)
          Reverse XML quoting to recover the original string.
static java.lang.String unquoteXmlContent(java.lang.String x)
          Reverse XML quoting to recover the original string.
static void unreplace(java.lang.StringBuffer sb, java.lang.String out, char in)
          Replace any String "out" in sb with char "in".
static java.lang.String unreplace(java.lang.String x, java.lang.String[] orgReplace, char[] orgChar)
          Replace all occurences of orgReplace with orgChar; inverse of replace().
static java.lang.String wildcardToRegexp(java.lang.String wildcard)
          Change a wildcard expression to a proper regular expression
static java.lang.String zeroString(int value)
          If the given value is less than 10 than pad the String return with a leading "0".
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

debug

public static boolean debug
debug flag


ordinalNames

public static final java.lang.String[] ordinalNames
Ordinal names for images

Constructor Detail

StringUtil

public StringUtil()
Method Detail

notEmpty

public static boolean notEmpty(java.lang.String s)
Check if the string is not empty

Parameters:
s - String to check
Returns:
true if it's not the empty string (len > 0)

collapseWhitespace

public static java.lang.String collapseWhitespace(java.lang.String s)
Collapse continuous whitespace into one single " ".

Parameters:
s - operate on this string
Returns:
result with collapsed whitespace

remove

public static java.lang.String remove(java.lang.String s,
                                      java.lang.String sub)
Remove all occurrences of the substring sub in the string s.

Parameters:
s - operate on this string
sub - remove all occurrences of this substring.
Returns:
result with substrings removed

remove

public static java.lang.String remove(java.lang.String s,
                                      int c)
Remove all occurrences of the character c in the string s.

Parameters:
s - operate on this string
c - remove all occurrences of this character.
Returns:
result with any character c removed

findFormatString

public static java.lang.String findFormatString(java.lang.String macroName,
                                                java.lang.String macroDelimiter,
                                                java.lang.String text)
Return the format string in the given text for the given macro. text may contain a macro of the form 'macroDelimiter macroName:format string macroDelimiter' e.g.: %count:some format% This returns the format string

Parameters:
macroName - The name of the macro
macroDelimiter - The delimiter used. e.g. '%'
text - the text
Returns:
the format string or null

substitute

public static java.lang.String substitute(java.lang.String original,
                                          java.lang.String match,
                                          java.lang.String subst)
Find all occurences of the "match" in original, and substitute the "subst" string.

Parameters:
original - starting string
match - string to match
subst - string to substitute
Returns:
a new string with substitutions

repeat

public static java.lang.String repeat(java.lang.String s,
                                      int cnt)
Concatentate the given string cnt times

Parameters:
s - base string
cnt -
Returns:
repeated string

substitute

public static java.lang.String substitute(java.lang.String original,
                                          java.lang.String[] match,
                                          java.lang.String[] subst)
Find all occurences of match strings in original, and substitute the corresponding subst string.

Parameters:
original - starting string
match - array of strings to match
subst - array of strings to substitute
Returns:
a new string with substitutions

substitute

public static void substitute(java.lang.StringBuffer sbuff,
                              java.lang.String match,
                              java.lang.String subst)
Find all occurences of the "match" in original, and substitute the "subst" string, directly into the original.

Parameters:
sbuff - starting string buffer
match - string to match
subst - string to substitute

isDigits

public static boolean isDigits(java.lang.String s)
Return true if all characters are numeric.

Parameters:
s - operate on this String
Returns:
true if all characters are numeric

quoteHtmlContent

public static java.lang.String quoteHtmlContent(java.lang.String x)
Replace special characters with entities for HTML content. special: '&', '"', '\'', '<', '>', '\n'

Parameters:
x - string to quote
Returns:
equivilent string using entities for any special chars

quoteXmlContent

public static java.lang.String quoteXmlContent(java.lang.String x)
Replace special characters with entities for XML attributes. special: '&', '<', '>', '\'', '"', '\r', '\n'

Parameters:
x - string to quote
Returns:
equivilent string using entities for any special chars

unquoteXmlContent

public static java.lang.String unquoteXmlContent(java.lang.String x)
Reverse XML quoting to recover the original string.

Parameters:
x - string to quote
Returns:
equivilent string

quoteXmlAttribute

public static java.lang.String quoteXmlAttribute(java.lang.String x)
Replace special characters with entities for XML attributes. special: '&', '<', '>', '\'', '"', '\r', '\n'

Parameters:
x - string to quote
Returns:
equivilent string using entities for any special chars

unquoteXmlAttribute

public static java.lang.String unquoteXmlAttribute(java.lang.String x)
Reverse XML quoting to recover the original string.

Parameters:
x - string to quote
Returns:
equivilent string

replace

public static java.lang.String replace(java.lang.String x,
                                       char[] replaceChar,
                                       java.lang.String[] replaceWith)
Replace all occurences of replaceChar with replaceWith

Parameters:
x - operate on this string
replaceChar - get rid of these
replaceWith - replace with these
Returns:
resulting string

unreplace

public static java.lang.String unreplace(java.lang.String x,
                                         java.lang.String[] orgReplace,
                                         char[] orgChar)
Replace all occurences of orgReplace with orgChar; inverse of replace().

Parameters:
x - operate on this string
orgReplace - get rid of these
orgChar - replace with these
Returns:
resulting string

match

public static int match(java.lang.String s1,
                        java.lang.String s2)
Count number of chars that match in two strings, starting from front.

Parameters:
s1 - compare this string
s2 - compare this string
Returns:
number of matching chars, starting from first char

replace

public static void replace(java.lang.StringBuffer sb,
                           char out,
                           java.lang.String in)
Replace any char "out" in sb with "in".

Parameters:
sb - StringBuffer to replace
out - repalce this character
in - with this string

unreplace

public static void unreplace(java.lang.StringBuffer sb,
                             java.lang.String out,
                             char in)
Replace any String "out" in sb with char "in".

Parameters:
sb - StringBuffer to replace
out - repalce this String
in - with this char

replace

public static java.lang.String replace(java.lang.String s,
                                       char out,
                                       java.lang.String in)
Replace any char "out" in s with "in".

Parameters:
s - string to replace
out - repalce this character
in - with this string
Returns:
modified string if needed

escape

public static java.lang.String escape(java.lang.String x,
                                      java.lang.String okChars)
Escape any char not alphanumeric or in okChars. Escape by replacing char with %xx (hex). LOOK: need to check for %, replace with %%

Parameters:
x - escape this string
okChars - these are ok.
Returns:
equivilent escaped string.

escape2

public static java.lang.String escape2(java.lang.String x,
                                       java.lang.String reservedChars)
Escape any char in reservedChars. Escape by replacing char with %xx (hex). LOOK: need to check for %, replace with %%

Parameters:
x - escape this string
reservedChars - these must be replaced
Returns:
equivilent escaped string.

toHexString

public static java.lang.String toHexString(java.awt.Color c)
Convert the given color to is string hex representation

Parameters:
c - color
Returns:
hex represenation

filter7bits

public static java.lang.String filter7bits(java.lang.String s)
Remove all but printable 7bit ascii

Parameters:
s - filter this string
Returns:
filtered string.

filter

public static java.lang.String filter(java.lang.String x,
                                      java.lang.String okChars)
Remove any char not alphanumeric or in okChars.

Parameters:
x - filter this string
okChars - these are ok.
Returns:
filtered string.

allow

public static java.lang.String allow(java.lang.String x,
                                     java.lang.String allowChars,
                                     char replaceChar)
Replace any char not alphanumeric or in allowChars by replaceChar.

Parameters:
x - operate on this string
allowChars - these are ok.
replaceChar - thar char to replace
Returns:
resulting string.

unescape

public static java.lang.String unescape(java.lang.String x)
This finds any '%xx' and converts to the equivilent char. Inverse of escape().

Parameters:
x -
Returns:
original String.

findMatch

public static java.lang.Object findMatch(java.lang.String source,
                                         java.util.List patternList,
                                         java.lang.Object dflt)
Run through the List of Objects and return the Object whose toString matches the source string. If none found then return the dflt value.

Parameters:
source - Source String to match on.
patternList - List of objects whose toString is the pattern.
dflt - The default if nothing matches.
Returns:
The Object whose toString matches the source or the dflt if no matches found.

findMatch

public static java.lang.Object findMatch(java.lang.String source,
                                         java.util.List patternList,
                                         java.util.List results,
                                         java.lang.Object dflt)
Run through the List of patterns (pattern, result) and return corresponding result whose pattern matches the source string. If none found then return the dflt.

Parameters:
source - Source String to match on.
patternList - List of objects whose toString is the pattern.
results - The list of return objects.
dflt - The default if nothing matches.
Returns:
The return Object whose toString matches the source or the dflt if no matches found.

containsRegExp

public static boolean containsRegExp(java.lang.String patternString)
See if a pattern string contains regular expression characters (^,*,$,+).

Parameters:
patternString - pattern string to check
Returns:
true if it contains (^,*,$,+).

stringMatch

public static boolean stringMatch(java.lang.String input,
                                  java.lang.String patternString)
Check if the given input String matches the given pattern String. First see if input.equals (patternString). If true then return true. Next if there are no regular expression characters (look for ^, $, *, and +) in the patternString then return false. Else treat the patternString as a regexp and return if it matches the input.

Parameters:
input - The input source string.
patternString - The regular expression pattern.
Returns:
true if the pattern match the input.

stringMatch

public static boolean stringMatch(java.lang.String input,
                                  java.lang.String patternString,
                                  boolean substring,
                                  boolean caseSensitive)
Check if the given input String matches the given pattern String. First see if input.equals (patternString). If true then return true. Next, if the pattern string is a simple "*" or begins with a "*" or starts with the prefix "glob:" then is is a glob style pattern and we convert it to a regexp. Next if there are no regular expression characters (look for ^, $, *, and +) in the patternString then return false. Else treat the patternString as a regexp and return if it matches the input.

Parameters:
input - The input source string.
patternString - The regular expression pattern.
substring - Search for substrings
caseSensitive - Is case sensitive
Returns:
true if the pattern match the input.

regexpMatch

public static boolean regexpMatch(java.lang.String input,
                                  java.lang.String patternString)
Match a regular expression

Parameters:
input - string to match
patternString - reg ex pattern string
Returns:
true if a match

wildcardToRegexp

public static java.lang.String wildcardToRegexp(java.lang.String wildcard)
Change a wildcard expression to a proper regular expression

Parameters:
wildcard - wildcard string (*, ?);
Returns:
the corresponding regular expression

startsWithVowel

public static boolean startsWithVowel(java.lang.String value)
Check to see if the string starts with a vowel.

Parameters:
value - String to check
Returns:
true if value starts with a, e, i, o, or u (but not sometimes y). Check is case insensitive.

breakText

public static java.lang.String breakText(java.lang.String text,
                                         java.lang.String insert,
                                         int lineSize)
Convert the given text to html by adding <br>. If there are new lines then we replace them with a space. Then we break the lines into 50 character (or so) chunks, adding br tags.

Parameters:
text - The text to convert
insert - string to insert
lineSize - line size to insert at
Returns:
The text with added br tags.

breakTextAtWords

public static java.lang.String breakTextAtWords(java.lang.String text,
                                                java.lang.String insert,
                                                int lineSize)
Break the given text into lines, respecting word boundaries (blank space).

Parameters:
text - The text to convert
insert - break to insert
lineSize - line size to insert at
Returns:
The text with added br tags.

stripHtmlTag

public static java.lang.String stripHtmlTag(java.lang.String html)
Remove any beginning or ending <html> tags

Parameters:
html - the html
Returns:
the stripped html

stripTags

public static java.lang.String stripTags(java.lang.String html)
Remove all text contained within "< >" tags.

Parameters:
html - The source html string.
Returns:
The raw text.

stripAndReplace

public static java.lang.String stripAndReplace(java.lang.String s,
                                               java.lang.String pattern1,
                                               java.lang.String pattern2,
                                               java.lang.String replace)
Replaces all occurrences of the strings delimited by patter1/pattern2 with replace, e.g.: "pattern1 ... pattern2"

Parameters:
s - initial string
pattern1 - delimiter 1
pattern2 - delimiter 2
replace - replace with
Returns:
replaced string

removeWhitespace

public static java.lang.String removeWhitespace(java.lang.String inputString)
Remove any whitespace (ie., Character.isWhitespace) from the input string.

Parameters:
inputString - The string to remove the whitespace.
Returns:
The whitespaceless result.

zeroString

public static java.lang.String zeroString(int value)
If the given value is less than 10 than pad the String return with a leading "0".

Parameters:
value - The value.
Returns:
The String represenation of the value, padded with a leading "0" if value < 10

padZero

public static java.lang.String padZero(int value,
                                       int numDigits)
Left pad the given value with zeros up to the number of digits

Parameters:
value - The value.
numDigits - number of digits
Returns:
The String represenation of the value, padded with leading "0"-s if value < 10E(numDigits-1)

padLeft

public static java.lang.String padLeft(java.lang.String s,
                                       int desiredLength)
Pad the given string with spaces on the left up to the given length.

Parameters:
s - String to pad
desiredLength - ending length
Returns:
padded String

padLeft

public static java.lang.String padLeft(java.lang.String s,
                                       int desiredLength,
                                       java.lang.String padString)
Pad the given string with padString on the left up to the given length.

Parameters:
s - String to pad
desiredLength - ending length
padString - String to pad with (e.g, " ")
Returns:
padded String

padRight

public static java.lang.String padRight(java.lang.String s,
                                        int desiredLength)
Pad the given string with spaces on the right up to the given length.

Parameters:
s - String to pad
desiredLength - ending length
Returns:
padded String

padRight

public static java.lang.String padRight(java.lang.String s,
                                        int desiredLength,
                                        java.lang.String padString)
Pad the given string with padString on the right up to the given length.

Parameters:
s - String to pad
desiredLength - ending length
padString - String to pad with (e.g, " ")
Returns:
padded String

join

public static java.lang.String join(java.lang.String[] args)
Merge the given strings, using a space between each.

Parameters:
args - An array of Strings to merge.
Returns:
The given strings concatenated together with a space between each.

join

public static java.lang.String join(java.lang.String delimiter,
                                    java.lang.Object[] args)
Merge the given strings, using the given delimiter between each.

Parameters:
delimiter - The delimiter.
args - An array of Strings to merge.
Returns:
The given strings concatenated together with the delimiter between each.

join

public static java.lang.String join(java.lang.String delimiter,
                                    java.lang.Object[] args,
                                    boolean ignoreEmptyStrings)
Merge the given strings, using the given delimiter between each.

Parameters:
delimiter - The delimiter.
args - An array of Strings to merge.
ignoreEmptyStrings - Don't join empty strings
Returns:
The given strings concatenated together with the delimiter between each.

join

public static java.lang.String join(java.lang.String delimiter,
                                    java.util.List args)
Merge the given strings, using the given delimiter between each.

Parameters:
delimiter - The delimiter.
args - A List of objects whose toString value are merged.
Returns:
The given object.toString values concatenated together with the delimiter between each.

join

public static java.lang.String join(java.lang.String delimiter,
                                    java.util.List args,
                                    boolean ignoreEmptyStrings)
Merge the given strings, using the given delimiter between each.

Parameters:
delimiter - The delimiter.
args - A List of objects whose toString value are merged.
ignoreEmptyStrings - Should ignore empty strings
Returns:
The given object.toString values concatenated together with the delimiter between each.

split

public static java.util.List<java.lang.String> split(java.lang.Object source)
Tokenize the toString value of the given source object, splitting on ",".

Parameters:
source - The source object string.
Returns:
List of String tokens.

parseDate

public static java.util.Date parseDate(java.lang.String dttm)
Parse the date. Can be of a number of forms:
  yyyy-MM-dd HH:mm:ss z yyyy-MM-dd HH:mm:ss   yyyy-MM-dd HH:mm
   yyyy-MM-dd yyyyMMddHHmmss  yyyyMMddHHmm
   yyyyMMddHH yyyyMMdd
 

Parameters:
dttm - The date string
Returns:
The Date or null if not able to parse it

parseIntegerListString

public static java.util.List parseIntegerListString(java.lang.String s)
Parse the given string and return a list of Integer values. The String s is a comma separated list of integer values or integer ranges of the form start:end:stride where stride is optional. So s can be:
 1,2,3   - the numbers 1 2 and 3
 0:10,15:20,30  - 0-10, 15-20 and 30
 0:10:2   - 0,2,4,6,8,10
 

Parameters:
s - The string to parse
Returns:
List of Integers

parseLineWords

public static java.util.List<java.lang.String[]> parseLineWords(java.lang.String content,
                                                                int[] lengths,
                                                                java.lang.String lineDelimiter,
                                                                java.lang.String commentString,
                                                                boolean trimWords)
This splits the given content String into a set of lines (delimited by the given lineDelimiter). If a line begins with the given commentString it is ignored. If the length of the trim value of the line is 0 it is ignored. If a line is not to be ignored then the substrings defined by the given fromIndices/toIndices are extracted, placed into a String array and added to the result List.

Parameters:
content - The String to parse
lengths - the length of each word.
lineDelimiter - What to split the line content string on (usually "\n").
commentString - If non-null defines the comment String in the content.
trimWords - Do we trim each word.
Returns:
A list of String arrays that holds the words.

parseLineWords

public static java.util.List<java.lang.String[]> parseLineWords(java.lang.String content,
                                                                int[] indices,
                                                                int[] lengths,
                                                                java.lang.String lineDelimiter,
                                                                java.lang.String commentString,
                                                                boolean trimWords)
This splits the given content String into a set of lines (delimited by the given lineDelimiter). If a line begins with the given commentString it is ignored. If the length of the trim value of the line is 0 it is ignored. If a line is not to be ignored then the substrings defined by the given fromIndices/toIndices are extracted, placed into a String array and added to the result List.

Parameters:
content - The String to parse
indices - the index in the line which defines the word start.
lengths - the length of each word.
lineDelimiter - What to split the line content string on (usually "\n").
commentString - If non-null defines the comment String in the content.
trimWords - Do we trim each word.
Returns:
A list of String arrays that holds the words.

split

public static java.util.List<java.lang.String> split(java.lang.Object source,
                                                     java.lang.String delimiter)
Tokenize the toString value of the given source object, splitting on the given delimiter.

Parameters:
source - The source object string.
delimiter - The delimiter to break up the sourceString on.
Returns:
List of String tokens.

split

public static java.util.List<java.lang.String> split(java.lang.Object source,
                                                     java.lang.String delimiter,
                                                     boolean trim)
Tokenize the toString value of the given source object, splitting on the given delimiter. If trim is true the string trim each token.

Parameters:
source - The source object string.
delimiter - The delimiter to break up the sourceString on.
trim - Do we string trim the tokens.
Returns:
List of String tokens.

splitWithQuotes

public static java.util.List<java.lang.String> splitWithQuotes(java.lang.String s)
tokenize the given string on spaces. Respect double quotes

Parameters:
s - The string to tokenize
Returns:
the list of tokens

split

public static java.util.List<java.lang.String> split(java.lang.Object source,
                                                     java.lang.String delimiter,
                                                     boolean trim,
                                                     boolean excludeZeroLength)
Tokenize the toString value of the given source object, splitting on the given delimiter. If trim is true the string trim each token.

Parameters:
source - The source object string.
delimiter - The delimiter to break up the sourceString on.
trim - Do we string trim the tokens.
excludeZeroLength - If true then don't add in zero length strings.
Returns:
List of String tokens.

split

public static java.lang.String[] split(java.lang.String s,
                                       java.lang.String delimiter,
                                       int cnt)
Split the given string into the first cnt number of substrings as delimited by the given delimiter.

Parameters:
s - String to split
delimiter - token delimeter
cnt - max number of tokens
Returns:
array of strings or null if unable to split the string.

splitUpTo

public static java.util.List<java.lang.String> splitUpTo(java.lang.String s,
                                                         java.lang.String delimiter,
                                                         int cnt)
Split up to a certain number of characters

Parameters:
s - the string to split
delimiter - the delimiter
cnt - the max number
Returns:
the list of split strings

replaceDate

public static java.lang.String replaceDate(java.lang.String s,
                                           java.lang.String macroName,
                                           java.util.Date date)
Replace the macro within s with the formatted date. s can contain macros of the form ${macroName:some date format}

Parameters:
s - source string
macroName - macro name_
date - date to use
Returns:
formatted string

replaceDate

public static java.lang.String replaceDate(java.lang.String s,
                                           java.lang.String macroName,
                                           java.util.Date date,
                                           java.lang.String macroPrefix,
                                           java.lang.String macroSuffix)
Replace the macro within s with the formatted date. s can contain macros of the form macroName:some date format

Parameters:
s - source string
macroName - macro name_
date - date to use
macroPrefix - the macro prefix
macroSuffix - the macro suffix
Returns:
formatted string

listToStringArray

public static java.lang.String[] listToStringArray(java.util.List objectList)
Take the List of objects and return a String array of the toString values of each object in the list.

Parameters:
objectList - The list of objects.
Returns:
The array of the object string values.

listToString

public static java.lang.String listToString(java.util.List l)
Take the List of objects and return a String of all the list's elements toString values appended to each other, separated by semicolons

Parameters:
l - list of objects
Returns:
semicolon separated String of Strings.

toString

public static java.util.List toString(java.util.List l)
Convert the list of objects to a list of strings.

Parameters:
l - List of objects
Returns:
List of strings.

replace

public static java.lang.String replace(java.lang.String string,
                                       java.lang.String pattern,
                                       java.lang.String value)
Replaces all occurrences of "pattern" in "string" with "value"

Parameters:
string - string to munge
pattern - pattern to replace
value - replacement value
Returns:
munged string

replaceList

public static java.lang.String replaceList(java.lang.String v,
                                           java.lang.String[] patterns,
                                           java.lang.String[] values)
Replaces all occurrences of "patterns" in "v" with "values"

Parameters:
v - original String
patterns - patterns to match
values - replacement values
Returns:
munged String

replaceList

public static java.lang.String replaceList(java.lang.String v,
                                           java.util.List patterns,
                                           java.util.List values)
Replaces all occurrences of "patterns" in "v" with "values"

Parameters:
v - original String
patterns - patterns to match
values - replacement values
Returns:
munged String

replaceList

public static java.util.List replaceList(java.util.List sourceList,
                                         java.lang.String[] patterns,
                                         java.lang.String[] values)
Construct and return a list of Strings where each string is the result of replacing all of the patterns with the corresponding values for each String in the given sourceList .

Parameters:
sourceList - original list of Strings
patterns - patterns to replace
values - replacement values
Returns:
new list with replaced values

append

public static java.lang.StringBuffer append(java.lang.StringBuffer sb,
                                            java.lang.Object s1)
A utility method to an append to a StringBuffer. If the given object is null the string "null" will be appended. If non-null the we append to the StringBuffer the results of s1.toString ();

Parameters:
sb - StringBuffer to append to (may be null)
s1 - object to append
Returns:
StringBuffer with appended object

append

public static java.lang.StringBuffer append(java.lang.StringBuffer sb,
                                            java.lang.Object s1,
                                            java.lang.Object s2)
A utility method to do multiple appends to a StringBuffer. If the given object is null the string "null" will be appended. If non-null then we append to the StringBuffer the results of sn.toString ();

Parameters:
sb - StringBuffer to append to (may be null)
s1 - first object to append
s2 - second object to append
Returns:
StringBuffer with appended objects

append

public static java.lang.StringBuffer append(java.lang.StringBuffer sb,
                                            java.lang.Object s1,
                                            java.lang.Object s2,
                                            java.lang.Object s3)
A utility method to do multiple appends to a StringBuffer. If the given object is null the string "null" will be appended. If non-null then we append to the StringBuffer the results of sn.toString ();

Parameters:
sb - StringBuffer to append to (may be null)
s1 - first object to append
s2 - second object to append
s3 - third object to append
Returns:
StringBuffer with appended objects

append

public static java.lang.StringBuffer append(java.lang.StringBuffer sb,
                                            java.lang.Object s1,
                                            java.lang.Object s2,
                                            java.lang.Object s3,
                                            java.lang.Object s4)
A utility method to do multiple appends to a StringBuffer. If the given object is null the string "null" will be appended. If non-null then we append to the StringBuffer the results of sn.toString ();

Parameters:
sb - StringBuffer to append to (may be null)
s1 - first object to append
s2 - second object to append
s3 - third object to append
s4 - fourth object to append
Returns:
StringBuffer with appended objects

append

public static java.lang.StringBuffer append(java.lang.StringBuffer sb,
                                            java.lang.Object s1,
                                            java.lang.Object s2,
                                            java.lang.Object s3,
                                            java.lang.Object s4,
                                            java.lang.Object s5)
A utility method to do multiple appends to a StringBuffer. If the given object is null the string "null" will be appended. If non-null then we append to the StringBuffer the results of sn.toString ();

Parameters:
sb - StringBuffer to append to (may be null)
s1 - first object to append
s2 - second object to append
s3 - third object to append
s4 - fourth object to append
s5 - fifth object to append
Returns:
StringBuffer with appended objects

parseCsv

public static java.util.List parseCsv(java.lang.String s,
                                      boolean skipFirst)
Parse a comma separated value (CVS) String

Parameters:
s - String to parse
skipFirst - true to skip the first value
Returns:
list of parsed Strings

shorten

public static final java.lang.String shorten(java.lang.String s,
                                             int length)
Shorten a string using elipses (...)

Parameters:
s - String to shorten
length - shortened length where elipses will start
Returns:
shortened string.

toString

public static java.lang.String toString(java.lang.Object[] array)
Create a string representation of the given array

Parameters:
array - array to print
Returns:
array as a String

expandIso8601

public static java.util.List expandIso8601(java.lang.String time)
A first attempt at parsing a dttm range string

Parameters:
time - The time
Returns:
List iof times

findPattern

public static java.lang.String findPattern(java.lang.String source,
                                           java.lang.String patternString)
Find the pattern in a string

Parameters:
source - String to search
patternString - pattern
Returns:
the String that matches

isUpperCase

public static boolean isUpperCase(java.lang.String s)
Is the string all upper case?

Parameters:
s - string to check
Returns:
true if all uppercase

isLowerCase

public static boolean isLowerCase(java.lang.String s)
Is the string all lower case?

Parameters:
s - string to check
Returns:
true if all characters are lowercase

camelCase

public static java.lang.String camelCase(java.lang.String s)
Camel case a string (eg howard -> Howard)

Parameters:
s - string to camel case
Returns:
the camel cased string

parseIso8601

public static java.util.Date parseIso8601(java.lang.String time)
Not working yet but this is supposed to parse an iso8601 date format

Parameters:
time - date
Returns:
date

parseTimePeriod

public static long parseTimePeriod(java.lang.String s)
Note, right now this just parses the hour/minute/second periods

Parameters:
s - The date string
Returns:
The time

main2

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

Parameters:
args - args

parsePropertiesString

public static java.util.Hashtable parsePropertiesString(java.lang.String s)
Parse the semi-colon delimited string of name=value properties.

Parameters:
s - Semi-colon delimited name=value string
Returns:
properties

parseHtmlProperties

public static java.util.Hashtable parseHtmlProperties(java.lang.String s)
Parse HTML Properties

Parameters:
s - the string
Returns:
a hashtable of properties

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Method for debugging.

Parameters:
args - arguments
Throws:
java.lang.Exception - some problem

main3

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

Parameters:
args - args

splitMacros

public static java.util.List<java.lang.String> splitMacros(java.lang.String s)
This parses the given string with the following form.
some text ${macro1} more text ... ${macro2} ... ${macroN} end text
It returns a list that flip-flops between the text and the macro:
  [some text, macro1, more text, ..., macro2, ..., macroN, end text]
 

Parameters:
s - String to parse
Returns:
List of tokens

applyMacros

public static java.lang.String applyMacros(java.lang.String s,
                                           java.util.Hashtable props,
                                           boolean throwError)
This takes a string of the following form.
some text ${macro1} more text ... ${macro2} ... ${macroN} end text
And replaces the macros with values from the given properties table If throwError is true then an IllegalArgumentException is thrown if the properties does not contain one of the macros

Parameters:
s - String to process
props - Contains the macro values
throwError - Throw exception when macro is missing
Returns:
Processed string

parseCoordinates

public static double[][] parseCoordinates(java.lang.String coords)
Parse the lat/lon/alt coordinate string

Parameters:
coords - comma and space separated coord string
Returns:
coords

getAnOrA

public static java.lang.String getAnOrA(java.lang.String subject)
Get "a" or "an" for prefixing to a string based on the first character

Parameters:
subject - subject to prefix
Returns:
"an" for vowels, "a" for consonants