com.mongodb.util
Class StringParseUtil

java.lang.Object
  extended by com.mongodb.util.StringParseUtil

public final class StringParseUtil
extends Object


Constructor Summary
StringParseUtil()
           
 
Method Summary
static boolean parseBoolean(String s, boolean d)
          Turns a string into a boolean value and returns a default value if unsuccessful.
static int parseIfInt(String s, int def)
           
static int parseInt(String s, int def)
          Turns a string into an int and returns a default value if unsuccessful.
static int parseInt(String s, int def, int[] lastIdx, boolean allowNegative)
          Turns a string into an int and returns a default value if unsuccessful.
static Number parseIntRadix(String s, int radix)
          Turns a string into an int using a given radix.
static Number parseNumber(String s, Number def)
          Turns a string into a Number and returns a default value if unsuccessful.
static Number parseStrict(String s)
          Use Java's "strict parsing" methods Integer.parseInt and Double.parseDouble to parse s "strictly".
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringParseUtil

public StringParseUtil()
Method Detail

parseBoolean

public static boolean parseBoolean(String s,
                                   boolean d)
Turns a string into a boolean value and returns a default value if unsuccessful.

Parameters:
s - the string to convert
d - the default value
Returns:
equivalent boolean value

parseInt

public static int parseInt(String s,
                           int def)
Turns a string into an int and returns a default value if unsuccessful.

Parameters:
s - the string to convert
def - the default value
Returns:
the int value

parseIntRadix

public static Number parseIntRadix(String s,
                                   int radix)
Turns a string into an int using a given radix.

Parameters:
s - the string to convert
radix - radix to use
Returns:
the int value

parseInt

public static int parseInt(String s,
                           int def,
                           int[] lastIdx,
                           boolean allowNegative)
Turns a string into an int and returns a default value if unsuccessful.

Parameters:
s - the string to convert
def - the default value
lastIdx - sets lastIdx[0] to the index of the last digit
allowNegative - if negative numbers are valid
Returns:
the int value

parseNumber

public static Number parseNumber(String s,
                                 Number def)
Turns a string into a Number and returns a default value if unsuccessful.

Parameters:
s - the string to convert
def - the default value
Returns:
the numeric value

parseStrict

public static Number parseStrict(String s)
Use Java's "strict parsing" methods Integer.parseInt and Double.parseDouble to parse s "strictly". i.e. if it's neither a double or an integer, fail.

Parameters:
s - the string to convert
Returns:
the numeric value

parseIfInt

public static int parseIfInt(String s,
                             int def)