public class NumberUtils
extends java.lang.Object
Constructor and Description |
---|
NumberUtils() |
Modifier and Type | Method and Description |
---|---|
static java.math.BigInteger |
byteArrayToPositive(byte[] rawBytes)
Convert rawBytes to bigInteger.
|
static <T> T |
convert(java.lang.Number number,
java.lang.Class<T> targetClass)
Convert
number to targetClass type. |
static <T> T |
parse(java.lang.String text,
java.lang.Class<?> clazz)
Parse
text and convert number. |
static <T> T |
parse(java.lang.String text,
java.lang.Class<T> targetClass,
java.text.NumberFormat numberFormat)
Parse string
text as numberFormat and convert to targetClass type
instance. |
static byte[] |
positiveToByteArray(java.math.BigInteger positiveNumber)
Convert
BigInteger into a byte array without additional sign byte to represent
canonical two's-complement form. |
public static <T> T convert(java.lang.Number number, java.lang.Class<T> targetClass) throws java.lang.IllegalArgumentException
number
to targetClass
type.T
- type to convertnumber
- instance to converttargetClass
- type class to convertjava.lang.IllegalArgumentException
- No rule for conversionpublic static <T> T parse(java.lang.String text, java.lang.Class<?> clazz)
text
and convert number.T
- type to converttext
- string to parseclazz
- type class to convertpublic static <T> T parse(java.lang.String text, java.lang.Class<T> targetClass, java.text.NumberFormat numberFormat)
text
as numberFormat
and convert to targetClass
type
instance.T
- type to converttext
- string to parsetargetClass
- type class to convertnumberFormat
- format to parsepublic static byte[] positiveToByteArray(java.math.BigInteger positiveNumber)
BigInteger
into a byte array without additional sign byte to represent
canonical two's-complement form. Eg. 255 is "11111111"
not
"00000000 1111 1111"
.positiveNumber
- a positive bigIntegerpositiveNumber
is null.public static java.math.BigInteger byteArrayToPositive(byte[] rawBytes)
rawBytes
- a rawBytes representing positive number without sign bit.BigInteger