Package org.jruby.util
Class SafeDecimalParser
java.lang.Object
org.jruby.util.SafeDecimalParser
- Direct Known Subclasses:
SafeDoubleParser,SafeFloatParser
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final BigDecimalLower allowed valueprivate static final DoubleLower allowed value as Doubleprotected static final BigDecimalThe middle of the bad interval - used for rounding bad valuesprivate static final StringDigit sequence to trigger the slow pathprotected static final BigDecimalConstant 2protected static final BigDecimalUpper allowed valueprivate static final DoubleUpper allowed value as Double -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static final doubledecimalValue(Number number) Safe way of getting the double value
prevents BigDecimal from calling Double.parseDouble()protected static final doubledecimalValue(BigDecimal bigDecimal) Safe way of getting the double value
Prevents BigDecimal from calling Double.parseDouble()protected static final DoubleSafe parsing of a String into a Doubleprivate static final StringExtract the digits from a numeric stringprivate static final booleanTests if the value is in the dangerous intervalprotected static final booleanHeuristic test if we should look closer at the valueprivate static final DoubleSlow parsing of a suspicious value
-
Field Details
-
TWO
Constant 2 -
LOWER
Lower allowed value -
UPPER
Upper allowed value -
MIDDLE
The middle of the bad interval - used for rounding bad values -
UPPER_DOUBLE
Upper allowed value as Double -
LOWER_DOUBLE
Lower allowed value as Double -
SUSPICIOUS_DIGITS
Digit sequence to trigger the slow path- See Also:
-
-
Constructor Details
-
SafeDecimalParser
SafeDecimalParser()
-
-
Method Details
-
isSuspicious
Heuristic test if we should look closer at the value- Parameters:
s- The non-null input String- Returns:
trueif the value is suspicious,falseotherwise
-
decimalValueOf
Safe parsing of a String into a Double- Parameters:
s- The input String, can be null- Returns:
- The Double value
-
decimalValue
Safe way of getting the double value
prevents BigDecimal from calling Double.parseDouble()- Parameters:
number-- Returns:
- the double value
-
decimalValue
Safe way of getting the double value
Prevents BigDecimal from calling Double.parseDouble()- Parameters:
bigDecimal-- Returns:
- the double value
-
parseSafely
Slow parsing of a suspicious valueRounding takes place if the value is inside the bad interval
- Parameters:
s- The non-null input String- Returns:
- the double value
-
digits
Extract the digits from a numeric string- Parameters:
s- The non-null String value- Returns:
- A String containing only the digits
-
isDangerous
Tests if the value is in the dangerous interval- Parameters:
bd- The big decimal value- Returns:
trueif the value is dangerous,falseotherwise
-