public class

Conversion

extends Object
java.lang.Object
   ↳ com.pnfsoftware.jeb.util.Conversion

Class Overview

Utility methods for safe conversions of string or boxed representations of numbers, to numbers.

By default, it is assumed that the string represents a number in base 10. The exceptions are:

  • Strings starting with "0x" or ending with "h": assume base 16
  • Strings starting with "0?" (? denoting any character): assume base 8

Summary

Public Constructors
Conversion()
Public Methods
static int stringToInt(String s, int def)
Convert to integer.
static int stringToInt(String s)
Convert to long with a default value of zero.
static long stringToLong(String s, long def)
Convert to long.
static long stringToLong(String s)
Convert to long with a default value of zero.
static int toInt(Object o, int def)
Best effort conversion of an object to an integer.
static int toInt(Object o)
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

Public Constructors

public Conversion ()

Public Methods

public static int stringToInt (String s, int def)

Convert to integer.

Parameters
s input string
def the default value
Returns
  • the converted value or the default value on error

public static int stringToInt (String s)

Convert to long with a default value of zero.

Parameters
s input string
Returns
  • the converted value or zero on error

public static long stringToLong (String s, long def)

Convert to long.

Parameters
s input string
def the default value
Returns
  • the converted value or the default value on error

public static long stringToLong (String s)

Convert to long with a default value of zero.

Parameters
s input string
Returns
  • the converted value or zero on error

public static int toInt (Object o, int def)

Best effort conversion of an object to an integer.

Parameters
o a String or an Integer
def default value to return if the conversion fails
Returns
  • the converted int

public static int toInt (Object o)

Best effort conversion of an object to an integer. If the conversion fails, the value returned is 0.

Parameters
o a String or an Integer
Returns
  • the converted int

public static long toLong (Object o)

Best effort conversion of an object to an integer. If the conversion fails, the value returned is 0.

Parameters
o a String or an Long
Returns
  • the converted long

public static long toLong (Object o, long def)

Best effort conversion of an object to a long.

Parameters
o a String or an Long
def default value to return if the conversion fails
Returns
  • the converted long