java.lang.Object | |
↳ | com.pnfsoftware.jeb.util.encoding.Conversion |
Utility methods for safe conversions of strings or boxed representations of numbers, to numbers. Base 10, 16 and 8 are supported. Numbers in bases 16 and 8 require explicit prefix or suffix. Otherwise, it is assumed that the string represents a number in base 10. The exceptions are:
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Conversion() |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
static int |
getHexPossibility(String s)
Determine if a string may, must, or cannot be representing a hexadecimal number.
| ||||||||||
static int |
stringToInt(String s, int def, int defaultBase)
Convert to int.
| ||||||||||
static int |
stringToInt(String s, int def)
Convert to int.
| ||||||||||
static int |
stringToInt(String s)
Convert to int.
| ||||||||||
static Integer | stringToIntUnsafe(String s) | ||||||||||
static long |
stringToLong(String s, long def)
Convert to long.
| ||||||||||
static long |
stringToLong(String s)
Convert to long.
| ||||||||||
static long |
stringToLong(String s, long def, int defaultBase)
Convert to long.
| ||||||||||
static Long | stringToLongUnsafe(String s) | ||||||||||
static int |
toInt(Object o)
Best effort conversion of an object to an integer.
| ||||||||||
static int |
toInt(Object o, int def)
Best effort conversion of an object to an integer.
| ||||||||||
static long |
toLong(Object o)
Best effort conversion of an object to an integer.
| ||||||||||
static long |
toLong(Object o, long def)
Best effort conversion of an object to a long.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Determine if a string may, must, or cannot be representing a hexadecimal number.
Convert to int.
s | input string |
---|---|
def | the default value |
Convert to int. The default conversion base, if undetermined, will be 10.
s | input string |
---|---|
def | value to be returned on error |
Convert to int. The default conversion base, if undetermined, will be 10.
s | input string |
---|
NumberFormatException |
---|
Convert to long. The default conversion base, if undetermined, will be 10.
s | input string |
---|---|
def | value to be returned on error |
Convert to long. The default conversion base, if undetermined, will be 10.
s | input string |
---|
Convert to long.
s | the input string |
---|---|
def | the default value if the conversion failed |
defaultBase | the default base if the base representation could not be determined |
Best effort conversion of an object to an integer. If the conversion fails, the value returned is 0.
o | a String or an Integer |
---|
Best effort conversion of an object to an integer.
o | a String or an Integer |
---|---|
def | default value to return if the conversion fails |
Best effort conversion of an object to an integer. If the conversion fails, the value returned is 0.
o | a String or an Long |
---|
Best effort conversion of an object to a long.
o | a String or an Long |
---|---|
def | default value to return if the conversion fails |