Top Description Fields Constructors Methods
ch.randelshofer.fastdoubleparser

pack-priv final Class JavaBigDecimalFromCharArray

extends AbstractNumberParser
Class Inheritance
Imports
java.math.BigDecimal, .BigInteger, java.util.NavigableMap

Parses a double from a byte array.

Field Summary

Modifier and TypeField and Description
private static final int
MANY_DIGITS_THRESHOLD

Threshold on the number of input characters for selecting the algorithm optimised for few digits in the significand vs. the algorithm for many digits in the significand.

private static final int
private static final long
public static final int
Inherited from ch.randelshofer.fastdoubleparser.AbstractNumberParser:
CHAR_TO_HEX_MAPDECIMAL_POINT_CLASSILLEGAL_OFFSET_OR_ILLEGAL_LENGTHOTHER_CLASSSYNTAX_ERRORVALUE_EXCEEDS_LIMITS

Constructor Summary

AccessConstructor and Description
public
JavaBigDecimalFromCharArray()

Creates a new instance.

Method Summary

Modifier and TypeMethod and Description
public BigDecimal

Returns:

the parsed BigDecimal
parseBigDecimalString
(char[]
the input string
str
,
int
start of the input data
offset
,
int
length of the input data
length
)

Parses a BigDecimalString as specified in JavaBigDecimalParser.

pack-priv BigDecimal
parseBigDecimalStringWithManyDigits(char[] str, int offset, int length)

Parses a big decimal string that has many digits.

private BigDecimal

Returns:

the parsed big decimal
valueOfBigDecimalString
(char[]
the input string
str
,
int
the start index of the integer part of the significand
integerPartIndex
,
int
the index of the decimal point in the significand (same as exponentIndicatorIndex if there is no decimal point)
decimalPointIndex
,
int
the start index of the non-zero fractional part of the significand
nonZeroFractionalPartIndex
,
int
the index of the exponent indicator (same as end of string if there is no exponent indicator)
exponentIndicatorIndex
,
boolean
indicates that the significand is negative
isNegative
,
int
the exponent value
exponent
)

Parses a big decimal string after we have identified the parts of the significand, and after we have obtained the exponent value.

Inherited from ch.randelshofer.fastdoubleparser.AbstractNumberParser:
charAtcharAtcharAtlookupHexlookupHex

Field Detail

MANY_DIGITS_THRESHOLDback to summary
private static final int MANY_DIGITS_THRESHOLD

Threshold on the number of input characters for selecting the algorithm optimised for few digits in the significand vs. the algorithm for many digits in the significand.

Set this to Integer#MAX_VALUE if you only want to use the algorithm optimised for few digits in the significand.

Set this to 0 if you only want to use the algorithm for long inputs.

Rationale for choosing a specific threshold value: We speculate that we only need to use the algorithm for large inputs if there is zero chance, that we can parse the input with the algorithm for small inputs.

optional significant sign = 1
18 significant digits = 18
optional decimal point in significant = 1
optional exponent = 1
optional exponent sign = 1
10 exponent digits = 10
MAX_DIGIT_COUNTback to summary
private static final int MAX_DIGIT_COUNT

See JavaBigDecimalParser.

MAX_EXPONENT_NUMBERback to summary
private static final long MAX_EXPONENT_NUMBER
MAX_INPUT_LENGTHback to summary
public static final int MAX_INPUT_LENGTH

Constructor Detail

JavaBigDecimalFromCharArrayback to summary
public JavaBigDecimalFromCharArray()

Creates a new instance.

Method Detail

parseBigDecimalStringback to summary
public BigDecimal parseBigDecimalString(char[] str, int offset, int length)

Parses a BigDecimalString as specified in JavaBigDecimalParser.

Parameters
str:char[]

the input string

offset:int

start of the input data

length:int

length of the input data

Returns:BigDecimal

the parsed BigDecimal

Exceptions
NullPointerException:
if str is null
IllegalArgumentException:
if offset or length are illegal
NumberFormatException:
if the input string can not be parsed successfully
parseBigDecimalStringWithManyDigitsback to summary
pack-priv BigDecimal parseBigDecimalStringWithManyDigits(char[] str, int offset, int length)

Parses a big decimal string that has many digits.

valueOfBigDecimalStringback to summary
private BigDecimal valueOfBigDecimalString(char[] str, int integerPartIndex, int decimalPointIndex, int nonZeroFractionalPartIndex, int exponentIndicatorIndex, boolean isNegative, int exponent)

Parses a big decimal string after we have identified the parts of the significand, and after we have obtained the exponent value.

      integerPartIndex
      │  decimalPointIndex
      │  │  nonZeroFractionalPartIndex
      │  │  │  exponentIndicatorIndex
      ↓  ↓  ↓  ↓
    "-123.00456e-789"

Parameters
str:char[]

the input string

integerPartIndex:int

the start index of the integer part of the significand

decimalPointIndex:int

the index of the decimal point in the significand (same as exponentIndicatorIndex if there is no decimal point)

nonZeroFractionalPartIndex:int

the start index of the non-zero fractional part of the significand

exponentIndicatorIndex:int

the index of the exponent indicator (same as end of string if there is no exponent indicator)

isNegative:boolean

indicates that the significand is negative

exponent:int

the exponent value

Returns:BigDecimal

the parsed big decimal