gov.lbl.genome.common
Class StringUtil

java.lang.Object
  extended by gov.lbl.genome.common.StringUtil

public class StringUtil
extends java.lang.Object


Constructor Summary
StringUtil()
           
 
Method Summary
static java.lang.String condenseStrings(java.lang.String[] strings)
          Merge a String array into a single String using a chosen delimiter that does not occur in any of the strings.
static java.lang.String decode(java.lang.String s)
          Decodes a x-www-form-urlencoded to a String.
static java.lang.String decodeSpaces(java.lang.String string)
          replace "%20" by space
static java.lang.String encodeSpaces(java.lang.String string)
          replace spaces by "%20"
static java.lang.String filterDigits(java.lang.String str)
          throw exception if string contains non-digit characters
static java.lang.String[] getAutoStringList(java.lang.String string)
          Tokenize a String list using the first character of the string as the delimiter.
static java.lang.String getDateString(java.util.Date date)
          get Date String
static java.lang.String getDecimalString(double value, int decimalCount)
          Parses a formatted string representation of a double value, with the specified number of decimal digits.
static java.lang.Double getDouble(java.lang.String doubleString)
          Converts a String to a Double object.
static double getDouble(java.lang.String doubleString, double defaultValue)
          Converts a String to a double.
static double getDouble(java.awt.TextField textField, double defaultValue)
          Converts the input in a TextField to a double.
static double getDouble(java.awt.TextField textField, double defaultValue, double minValue, double maxValue)
          Converts the input in a TextField to a double, constrained by min and max values.
static int getInt(java.lang.String string, int defaultValue)
          Converts a String to an int.
static int getInt(java.lang.String string, int defaultValue, int minValue, int maxValue)
          Converts a String to an int, constrained by min and max values.
static int getInt(java.awt.TextField textField, int defaultValue)
          Converts the input in a TextField to an int.
static int getInt(java.awt.TextField textField, int defaultValue, int minValue, int maxValue)
          Converts the input in a TextField to an int, constrained by min and max values.
static int[] getIntArray(java.lang.String listString, int delimiter)
          Returns an Array of int using the given delimiter.
static java.lang.Integer getInteger(java.lang.String string)
          Converts a String to an Integer.
static java.lang.Long getLong(java.lang.String string)
          Converts a String to a Long.
static long getLong(java.lang.String string, long defaultValue)
          Converts a String to a long.
static long getLong(java.awt.TextField textField, long defaultValue)
          Converts the input in a TextField to a long.
static long getLong(java.awt.TextField textField, long defaultValue, long minValue, long maxValue)
          Converts the input in a TextField to a long, constrained by min and max values.
static long[] getLongArray(java.lang.String listString, int delimiter)
          Returns an Array of long using the given delimiter.
static int getOS(java.lang.String string)
          Returns the Operating System being used, as defined in the specified string.
static java.lang.String getStackTrace(java.lang.Throwable t)
           
static java.lang.String[] getStrings(java.util.Enumeration enumeration)
          Returns an Array of strings from an Enumeration object.
static java.lang.String[] getStrings(java.lang.String string, int delimiter, boolean emptyTokens)
          Tokenize a string using the given delimiter and return an array of the tokens found in the string.
static java.lang.String[] getStrings(java.lang.String string, int startIndex, int delimiter, boolean emptyTokens)
          Tokenize a string starting at the specified index.
static boolean isInteger(java.lang.String s)
           
static java.lang.Long parseFormattedLong(java.lang.String string)
          Parses a formatted string representation of a chromosome coordinate.
static java.lang.String quote(java.lang.String string)
          escape quotations
static java.lang.String replaceChar(java.lang.String string, char searchCh, char replaceCh)
          Replace all occurrences of one specified character with the other specified character.
static java.lang.String[] split(java.lang.String string, java.lang.String token)
          split the string using token.
static java.lang.String[] split(java.lang.String string, java.lang.String token, boolean returnDelims)
          split the string using token.
static boolean startsWithIgnoreCase(java.lang.String str, java.lang.String pre)
          return true if firts strings start with the same letters, ignoring letter case
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringUtil

public StringUtil()
Method Detail

isInteger

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

getInteger

public static java.lang.Integer getInteger(java.lang.String string)
Converts a String to an Integer. NULL is returned if the string is not a valid Integer format.


getInt

public static int getInt(java.lang.String string,
                         int defaultValue)
Converts a String to an int. The default value is returned if the string is not a valid Integer format.


getInt

public static int getInt(java.awt.TextField textField,
                         int defaultValue)
Converts the input in a TextField to an int. The default value is returned if the input is not valid Integer format.


getInt

public static int getInt(java.awt.TextField textField,
                         int defaultValue,
                         int minValue,
                         int maxValue)
Converts the input in a TextField to an int, constrained by min and max values. The default value is returned if the input is not valid Integer format.


getInt

public static int getInt(java.lang.String string,
                         int defaultValue,
                         int minValue,
                         int maxValue)
Converts a String to an int, constrained by min and max values. The default value is returned if the input is not valid Integer format.


getLong

public static java.lang.Long getLong(java.lang.String string)
Converts a String to a Long. NULL is returned if the string is not a valid Long format.


getLong

public static long getLong(java.lang.String string,
                           long defaultValue)
Converts a String to a long. The default value provided is returned if the string is not a valid Long format.


getLong

public static long getLong(java.awt.TextField textField,
                           long defaultValue)
Converts the input in a TextField to a long. The default value provided is returned if the input is not a valid Long format.


getLong

public static long getLong(java.awt.TextField textField,
                           long defaultValue,
                           long minValue,
                           long maxValue)
Converts the input in a TextField to a long, constrained by min and max values. The default value provided is returned if the input is not a valid Long format.


getDouble

public static java.lang.Double getDouble(java.lang.String doubleString)
Converts a String to a Double object. null is returned if the string is not a valid double format.


getDouble

public static double getDouble(java.lang.String doubleString,
                               double defaultValue)
Converts a String to a double. The default value provided is returned if the string is not a valid double format.


getDouble

public static double getDouble(java.awt.TextField textField,
                               double defaultValue)
Converts the input in a TextField to a double. The default value is returned if the input is not valid Double format.


getDouble

public static double getDouble(java.awt.TextField textField,
                               double defaultValue,
                               double minValue,
                               double maxValue)
Converts the input in a TextField to a double, constrained by min and max values. The default value is returned if the input is not valid Double format.


getStrings

public static java.lang.String[] getStrings(java.util.Enumeration enumeration)
Returns an Array of strings from an Enumeration object.


getIntArray

public static int[] getIntArray(java.lang.String listString,
                                int delimiter)
Returns an Array of int using the given delimiter. Empty tokens will be ignored and invalid number formats will be given the value 0. This method will not return null.


getLongArray

public static long[] getLongArray(java.lang.String listString,
                                  int delimiter)
Returns an Array of long using the given delimiter. Empty tokens will be ignored and invalid number formats will be given the value 0. This method will not return null.


getStackTrace

public static java.lang.String getStackTrace(java.lang.Throwable t)

parseFormattedLong

public static java.lang.Long parseFormattedLong(java.lang.String string)
Parses a formatted string representation of a chromosome coordinate. Acceptable formats include: 1000, 10k, 10K, 10m, 10M, 1.5k, 1.5K, 1.5m, 1.5M where "k" and "K" signify a factor of 1000 and "m" and "M" signify a factor of 1000000. Since the returned format is a Long, any decimal points that are remaining after multiplying by the "k" or "m" factor are truncated.


getDecimalString

public static java.lang.String getDecimalString(double value,
                                                int decimalCount)
Parses a formatted string representation of a double value, with the specified number of decimal digits.


getStrings

public static java.lang.String[] getStrings(java.lang.String string,
                                            int delimiter,
                                            boolean emptyTokens)
Tokenize a string using the given delimiter and return an array of the tokens found in the string. If emptyTokens is true, empty tokens will be returned. If emptyTokens is false, empty tokens will be ignored. For example: getStrings("x,y,,z", ',', true) --> { "x", "y", "", "z" } getStrings(",x,y,z,", ',', true) --> { "", "x", "y", "z", "" } getStrings(",,", ',', true) --> { "", "", "" } getStrings("x,,y", ',', false) --> { "x", "y" }


getStrings

public static java.lang.String[] getStrings(java.lang.String string,
                                            int startIndex,
                                            int delimiter,
                                            boolean emptyTokens)
Tokenize a string starting at the specified index.


getAutoStringList

public static java.lang.String[] getAutoStringList(java.lang.String string)
Tokenize a String list using the first character of the string as the delimiter. This is a good format for object serialization.


condenseStrings

public static java.lang.String condenseStrings(java.lang.String[] strings)
Merge a String array into a single String using a chosen delimiter that does not occur in any of the strings.


decode

public static java.lang.String decode(java.lang.String s)
Decodes a x-www-form-urlencoded to a String.

Parameters:
s - the String to decode
Returns:
the newly decoded String

quote

public static java.lang.String quote(java.lang.String string)
escape quotations

Parameters:
string - String
Returns:
String

getDateString

public static java.lang.String getDateString(java.util.Date date)
get Date String

Parameters:
date - Date
Returns:
String

replaceChar

public static java.lang.String replaceChar(java.lang.String string,
                                           char searchCh,
                                           char replaceCh)
Replace all occurrences of one specified character with the other specified character.


split

public static java.lang.String[] split(java.lang.String string,
                                       java.lang.String token)
split the string using token. Java 1.2 does not have split method

Parameters:
string - String
token - String
Returns:
String[]

split

public static java.lang.String[] split(java.lang.String string,
                                       java.lang.String token,
                                       boolean returnDelims)
split the string using token. return also delim. in the same array Java 1.2 does not have split method

Parameters:
string - String
token - String
returnDelims - boolean
Returns:
String[]

encodeSpaces

public static java.lang.String encodeSpaces(java.lang.String string)
replace spaces by "%20"

Parameters:
string - String
Returns:
String

decodeSpaces

public static java.lang.String decodeSpaces(java.lang.String string)
replace "%20" by space

Parameters:
string - String
Returns:
String

getOS

public static int getOS(java.lang.String string)
Returns the Operating System being used, as defined in the specified string.


filterDigits

public static java.lang.String filterDigits(java.lang.String str)
                                     throws VGBException
throw exception if string contains non-digit characters

Parameters:
str - String
Returns:
String
Throws:
VGBException

startsWithIgnoreCase

public static boolean startsWithIgnoreCase(java.lang.String str,
                                           java.lang.String pre)
return true if firts strings start with the same letters, ignoring letter case

Parameters:
str - String
pre - String
Returns:
boolean