com.jstatcom.util
Class UString

java.lang.Object
  extended by com.jstatcom.util.UString

public final class UString
extends java.lang.Object

A collection of static methods that are related to strings and formatting.

Author:
Markus Kraetzig

Field Summary
static java.lang.String NAN_STRING
           
static java.lang.String NAN_STRING_ALT
           
static java.lang.String NEGINF_STRING
           
static java.lang.String POSINF_STRING
           
static java.lang.String SIGPOSINF_STRING
           
 
Constructor Summary
UString()
           
 
Method Summary
static java.lang.String capitalizeFirst(java.lang.String s)
          Resturns string with first characted capitalized, rest lowercase.
static java.lang.String formatNumber(double number, java.text.NumberFormat format, int precision)
          Formats number with format if format !
static java.lang.Double parseToNumber(java.lang.String text)
          Parses a given string to a Double if possible and returns it.
static java.lang.String replaceAllSubStrings(java.lang.String origString, java.lang.String substring, java.lang.String replacementString)
          This method replaces all occurences of a substring in an original string with a replacement string.
static java.lang.String replaceSubString(java.lang.String origString, java.lang.String substring, java.lang.String replacementString)
          This method replaces the first occurence of a substring in an original string with a replacement string.
static java.lang.String replaceSubString(java.lang.String origString, java.lang.String substring, java.lang.String replacementString, int pos)
          This method replaces the first occurence of a substring in an original string with a replacement string, starting from a given position.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NAN_STRING

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

NAN_STRING_ALT

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

POSINF_STRING

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

SIGPOSINF_STRING

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

NEGINF_STRING

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

UString

public UString()
Method Detail

formatNumber

public static java.lang.String formatNumber(double number,
                                            java.text.NumberFormat format,
                                            int precision)
Formats number with format if format != null. Otherwise return number as a string. The formatter respects the given precision.

Parameters:
number - the double to format
format - the formatter, can be null
precision - number of digits right to the decimal point
Returns:
a formatted string with number

parseToNumber

public static java.lang.Double parseToNumber(java.lang.String text)
Parses a given string to a Double if possible and returns it. NaN, (+)Infinity, and -Infinity, are recognized. If the given string is empty, NaN is returned.

Parameters:
text - a string that should represent a number, scientific notation is recognized as well
Returns:
the assembled Double or null if something went wrong
Throws:
java.lang.IllegalArgumentException - if (text == null)

replaceAllSubStrings

public static java.lang.String replaceAllSubStrings(java.lang.String origString,
                                                    java.lang.String substring,
                                                    java.lang.String replacementString)
This method replaces all occurences of a substring in an original string with a replacement string. It does not work with regular expressions.

Parameters:
origString - the string to work on
substring - must occur completely in origString for the replacement to work
replacementString - the string with which substring is replaced
Returns:
a new string with the replacement(s) or
origString if any of the parameters is null, if substring is empty or if substring does not occur in origString

replaceSubString

public static java.lang.String replaceSubString(java.lang.String origString,
                                                java.lang.String substring,
                                                java.lang.String replacementString)
This method replaces the first occurence of a substring in an original string with a replacement string. It does not work with regular expressions.

Parameters:
origString - the string to work on
substring - must occur completely in origString for the replacement to work
replacementString - the string with which substring is replaced
Returns:
a new string with the replacement or
origString if any of the parameters is null, if substring is empty or if substring does not occur in origString

replaceSubString

public static java.lang.String replaceSubString(java.lang.String origString,
                                                java.lang.String substring,
                                                java.lang.String replacementString,
                                                int pos)
This method replaces the first occurence of a substring in an original string with a replacement string, starting from a given position. It does not work with regular expressions.

Parameters:
origString - the string to work on
substring - must occur completely in origString for the replacement to work
replacementString - the string with which substring is replaced
pos - the index in origString to start searching for substring, if < 0 pos is set to 0
Returns:
a new string with the replacement or
origString if any of the parameters is null, if substring is empty or if substring does not occur in origString or if pos >= origString.length()

capitalizeFirst

public static java.lang.String capitalizeFirst(java.lang.String s)
Resturns string with first characted capitalized, rest lowercase. Useful for names.

Parameters:
s -
Returns:
string with first char upper case, rest lowercase or null if s == null