@Test public final void shouldConvertNullToOne() { BigDecimal notNullDecimal = BigDecimal.TEN; BigDecimal fromNullRes = BigDecimalUtils.convertNullToOne(null); BigDecimal fromNotNullRes = BigDecimalUtils.convertNullToOne(notNullDecimal); Assert.assertEquals(0, notNullDecimal.compareTo(fromNotNullRes)); Assert.assertEquals(0, BigDecimal.ONE.compareTo(fromNullRes)); }
public static BigDecimal convertNullToOne(final Object value) { if (value == null) { return BigDecimal.ONE; } if (value instanceof BigDecimal) { return (BigDecimal) value; } return BigDecimal.valueOf(Double.valueOf(value.toString())); }
BigDecimalUtils { public static BigDecimal convertNullToOne(final Object value) { if (value == null) { return BigDecimal.ONE; } if (value instanceof BigDecimal) { return (BigDecimal) value; } return BigDecimal.valueOf(Double.valueOf(value.toString())); } }
BigDecimalUtils { public static BigDecimal convertNullToOne(final Object value) { if (value == null) { return BigDecimal.ONE; } if (value instanceof BigDecimal) { return (BigDecimal) value; } return BigDecimal.valueOf(Double.valueOf(value.toString())); } private  BigDecimalUtils(); }
BigDecimalUtils { public static BigDecimal convertNullToOne(final Object value) { if (value == null) { return BigDecimal.ONE; } if (value instanceof BigDecimal) { return (BigDecimal) value; } return BigDecimal.valueOf(Double.valueOf(value.toString())); } private  BigDecimalUtils(); static BigDecimal convertNullToZero(final Object value); static BigDecimal convertNullToOne(final Object value); static BigDecimal toPercent(final BigDecimal decimalValue, final MathContext mathContext); static boolean valueEquals(final BigDecimal d1, final BigDecimal d2); static Either<Exception, Optional<BigDecimal>> tryParse(final String maybeStringWithDecimal, final Locale locale); static Either<Exception, Optional<BigDecimal>> tryParseAndIgnoreSeparator(final String maybeStringWithDecimal, final Locale locale); static boolean checkIfCorrectDecimalValue(final Entity entity, final String decimalFieldName); static String toString(BigDecimal decimal,int maximumFractionDigits); }
BigDecimalUtils { public static BigDecimal convertNullToOne(final Object value) { if (value == null) { return BigDecimal.ONE; } if (value instanceof BigDecimal) { return (BigDecimal) value; } return BigDecimal.valueOf(Double.valueOf(value.toString())); } private  BigDecimalUtils(); static BigDecimal convertNullToZero(final Object value); static BigDecimal convertNullToOne(final Object value); static BigDecimal toPercent(final BigDecimal decimalValue, final MathContext mathContext); static boolean valueEquals(final BigDecimal d1, final BigDecimal d2); static Either<Exception, Optional<BigDecimal>> tryParse(final String maybeStringWithDecimal, final Locale locale); static Either<Exception, Optional<BigDecimal>> tryParseAndIgnoreSeparator(final String maybeStringWithDecimal, final Locale locale); static boolean checkIfCorrectDecimalValue(final Entity entity, final String decimalFieldName); static String toString(BigDecimal decimal,int maximumFractionDigits);  }