Top Fields Constructors Methods
org.jruby.util

pack-priv Class SafeDecimalParser

extends Object
Class Inheritance
Known Direct Subclasses
org.jruby.util.SafeDoubleParser, org.jruby.util.SafeFloatParser
Imports
java.math.BigDecimal

Field Summary

Modifier and TypeField and Description
protected static final BigDecimal
LOWER

Lower allowed value

private static final Double
LOWER_DOUBLE

Lower allowed value as Double

protected static final BigDecimal
MIDDLE

The middle of the bad interval - used for rounding bad values

private static final String
SUSPICIOUS_DIGITS

Digit sequence to trigger the slow path

protected static final BigDecimal
TWO

Constant 2

protected static final BigDecimal
UPPER

Upper allowed value

private static final Double
UPPER_DOUBLE

Upper allowed value as Double

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
protected static final double

Returns:

the double value
decimalValue
(Number number)

Safe way of getting the double value prevents BigDecimal from calling Double.parseDouble()

protected static final double

Returns:

the double value
decimalValue
(BigDecimal bigDecimal)

Safe way of getting the double value Prevents BigDecimal from calling Double.parseDouble()

protected static final Double

Returns:

The Double value
decimalValueOf
(String
The input String, can be null
s
)

Safe parsing of a String into a Double

private static final String

Returns:

A String containing only the digits
digits
(String
The non-null String value
s
)

Extract the digits from a numeric string

private static final boolean

Returns:

true if the value is dangerous, false otherwise
isDangerous
(BigDecimal
The big decimal value
bd
)

Tests if the value is in the dangerous interval

protected static final boolean

Returns:

true if the value is suspicious, false otherwise
isSuspicious
(String
The non-null input String
s
)

Heuristic test if we should look closer at the value

private static final Double

Returns:

the double value
parseSafely
(String
The non-null input String
s
)

Slow parsing of a suspicious value

Rounding takes place if the value is inside the bad interval

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

LOWERback to summary
protected static final BigDecimal LOWER

Lower allowed value

LOWER_DOUBLEback to summary
private static final Double LOWER_DOUBLE

Lower allowed value as Double

MIDDLEback to summary
protected static final BigDecimal MIDDLE

The middle of the bad interval - used for rounding bad values

SUSPICIOUS_DIGITSback to summary
private static final String SUSPICIOUS_DIGITS

Digit sequence to trigger the slow path

TWOback to summary
protected static final BigDecimal TWO

Constant 2

UPPERback to summary
protected static final BigDecimal UPPER

Upper allowed value

UPPER_DOUBLEback to summary
private static final Double UPPER_DOUBLE

Upper allowed value as Double

Constructor Detail

SafeDecimalParserback to summary
pack-priv SafeDecimalParser()

Method Detail

decimalValueback to summary
protected static final double decimalValue(Number number)

Safe way of getting the double value
prevents BigDecimal from calling Double.parseDouble()

Returns:double

the double value

decimalValueback to summary
protected static final double decimalValue(BigDecimal bigDecimal)

Safe way of getting the double value
Prevents BigDecimal from calling Double.parseDouble()

Returns:double

the double value

decimalValueOfback to summary
protected static final Double decimalValueOf(String s)

Safe parsing of a String into a Double

Parameters
s:String

The input String, can be null

Returns:Double

The Double value

digitsback to summary
private static final String digits(String s)

Extract the digits from a numeric string

Parameters
s:String

The non-null String value

Returns:String

A String containing only the digits

isDangerousback to summary
private static final boolean isDangerous(BigDecimal bd)

Tests if the value is in the dangerous interval

Parameters
bd:BigDecimal

The big decimal value

Returns:boolean

true if the value is dangerous, false otherwise

isSuspiciousback to summary
protected static final boolean isSuspicious(String s)

Heuristic test if we should look closer at the value

Parameters
s:String

The non-null input String

Returns:boolean

true if the value is suspicious, false otherwise

parseSafelyback to summary
private static final Double parseSafely(String s)

Slow parsing of a suspicious value

Rounding takes place if the value is inside the bad interval

Parameters
s:String

The non-null input String

Returns:Double

the double value