Package org.kiwiproject.base
Class KiwiBigDecimals
java.lang.Object
org.kiwiproject.base.KiwiBigDecimals
Utilities for working with
BigDecimal.
Neither Guava (e.g. DoubleMath) nor Apache Commons (e.g. NumberUtils) contained these exact
conversions when this was originally implemented. The Apache Commons NumberUtils does contain conversion
methods that accept a default value for null input, or if zero is OK as the default.
-
Method Summary
Modifier and TypeMethodDescriptionstatic doublerequireDouble(@NonNull BigDecimal value) Converts the givenBigDecimalto a primitive double.static DoubletoDoubleOrNull(@Nullable BigDecimal value) Converts a nullableBigDecimalto aDoubleor returns null if the given value is null.static OptionalDoubletoOptionalDouble(@Nullable BigDecimal value) Converts a nullableBigDecimalto anOptionalDouble.toOptionalDoubleObject(@Nullable BigDecimal value)
-
Method Details
-
toOptionalDouble
Converts a nullableBigDecimalto anOptionalDouble. Use this if you need a primitive double and want to avoid boxing.- Parameters:
value- the BigDecimal or null- Returns:
- an
OptionalDouble
-
toOptionalDoubleObject
Converts a nullableBigDecimalto anOptionalcontaining aDouble. Use this if you need a Double or if you need to perform further map operations on the value.Optionalhas map, filter, etc. whileOptionalDoubledoes not. -
toDoubleOrNull
Converts a nullableBigDecimalto aDoubleor returns null if the given value is null.- Parameters:
value- the BigDecimal or null- Returns:
- converted
Doubleor null
-
requireDouble
Converts the givenBigDecimalto a primitive double.- Parameters:
value- the non-null BigDecimal- Returns:
- a primitive double
- Throws:
IllegalArgumentException- if the given value is null
-