class SafeDecimalParser
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
protected static java.math.BigDecimal |
LOWER
Lower allowed value
|
private static java.lang.Double |
LOWER_DOUBLE
Lower allowed value as Double
|
protected static java.math.BigDecimal |
MIDDLE
The middle of the bad interval - used for rounding bad values
|
private static java.lang.String |
SUSPICIOUS_DIGITS
Digit sequence to trigger the slow path
|
protected static java.math.BigDecimal |
TWO
Constant 2
|
protected static java.math.BigDecimal |
UPPER
Upper allowed value
|
private static java.lang.Double |
UPPER_DOUBLE
Upper allowed value as Double
|
| Constructor and Description |
|---|
SafeDecimalParser() |
| Modifier and Type | Method and Description |
|---|---|
protected static double |
decimalValue(java.math.BigDecimal bigDecimal)
Safe way of getting the double value
Prevents BigDecimal from calling Double.parseDouble() |
protected static double |
decimalValue(java.lang.Number number)
Safe way of getting the double value
prevents BigDecimal from calling Double.parseDouble() |
protected static java.lang.Double |
decimalValueOf(java.lang.String s)
Safe parsing of a String into a Double
|
private static java.lang.String |
digits(java.lang.String s)
Extract the digits from a numeric string
|
private static boolean |
isDangerous(java.math.BigDecimal bd)
Tests if the value is in the dangerous interval
|
protected static boolean |
isSuspicious(java.lang.String s)
Heuristic test if we should look closer at the value
|
private static java.lang.Double |
parseSafely(java.lang.String s)
Slow parsing of a suspicious value
|
protected static final java.math.BigDecimal TWO
protected static final java.math.BigDecimal LOWER
protected static final java.math.BigDecimal UPPER
protected static final java.math.BigDecimal MIDDLE
private static final java.lang.Double UPPER_DOUBLE
private static final java.lang.Double LOWER_DOUBLE
private static final java.lang.String SUSPICIOUS_DIGITS
protected static final boolean isSuspicious(java.lang.String s)
s - The non-null input Stringtrue if the value is suspicious, false otherwiseprotected static final java.lang.Double decimalValueOf(java.lang.String s)
s - The input String, can be nullprotected static final double decimalValue(java.lang.Number number)
number - protected static final double decimalValue(java.math.BigDecimal bigDecimal)
bigDecimal - private static final java.lang.Double parseSafely(java.lang.String s)
Rounding takes place if the value is inside the bad interval
s - The non-null input Stringprivate static final java.lang.String digits(java.lang.String s)
s - The non-null String valueprivate static final boolean isDangerous(java.math.BigDecimal bd)
bd - The big decimal valuetrue if the value is dangerous, false otherwise