Sharkysoft home

lava.string
Class NumberString

java.lang.Object
  |
  +--lava.string.NumberString

public class NumberString
extends java.lang.Object

Converts strings to numbers.

Details: NumberString is a collection of functions that perform various conversions from Strings into numeric types.

Author:
Sharky

Constructor Summary
NumberString()
           
 
Method Summary
static java.math.BigInteger toBigInteger(java.lang.String s)
          Converts numeric string to BigInteger.
static java.lang.Integer toSignedInt(java.lang.String s)
          Decodes signed int.
static java.lang.Integer toSignedInt(java.lang.String s, int radix)
          Safely converts String to int.
static java.lang.Long toSignedLong(java.lang.String s)
          Decodes signed long.
static java.lang.Integer toUnsignedInt(java.lang.String s, int radix)
          Safely converts String to unsigned int.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NumberString

public NumberString()
Method Detail

toBigInteger

public static java.math.BigInteger toBigInteger(java.lang.String s)
Converts numeric string to BigInteger.

Details: toBigInteger accepts numeric strings in the following form:

and safely converts them to BigIntegers without threat of throwing an exception. (The BigInteger constructors and methods can't do this.) If the supplied string is null or not in any of the above forms, null is returned. (BigInteger can't do this either!) In no case will an exception be thrown. (Nor this... :-)

Parameters:
s - the string
Returns:
the BigInteger
Since:
1998.11.18

toSignedLong

public static final java.lang.Long toSignedLong(java.lang.String s)
Decodes signed long.

Details: toSignedLong is functionally the same as toBigInteger, except that toSignedLong attempts to decode a long instead of a BigInteger. Failure occurs if the string does not contain one of the forms recognized by toBigInteger or if the string represents a number that is outside of the range of a signed long. If the conversion is successful, a Long representing the converted value is returned. Otherwise, null is returned.

Parameters:
s - the string to decode
Returns:
the decoded value
Since:
2000.02.21

toSignedInt

public static final java.lang.Integer toSignedInt(java.lang.String s)
Decodes signed int.

Details: toSignedInt is functionally the same as toBigInteger, except that toSignedInt attempts to decode an int instead of a BigInteger. Failure occurs if the string does not contain one of the forms recognized by toBigInteger or if the string represents a number that is outside of the range of a signed int. If the conversion is successful, an Integer representing the converted value is returned. Otherwise, null is returned.

Parameters:
s - the string to decode
Returns:
the decoded value
Since:
2000.02.21

toSignedInt

public static final java.lang.Integer toSignedInt(java.lang.String s,
                                                  int radix)
Safely converts String to int.

Details: toSignedInt converts a numeric string to a signed 32-bit integer.

Parameters:
s - the string to convert
radix - the radix in which the string's numeric value is expressed
Returns:
an Integer representing the converted value, or null if the conversion failed

toUnsignedInt

public static final java.lang.Integer toUnsignedInt(java.lang.String s,
                                                    int radix)
Safely converts String to unsigned int.

Details: Converts a numeric string to an unsigned 32-bit integer. Note that while the data type returned represents a signed integer, the bits of that integer reflect an unsigned conversion.

Parameters:
s - the string to convert
radix - the radix in which the string's numeric value is expressed
Returns:
an Integer representing the converted value, or null if the conversion failed

Sharkysoft home