return operator.apply(this);
@Deprecated public <T> T asType(Class<T> type, MonetaryOperator adjuster) { RoundedMoney amount = (RoundedMoney) adjuster.apply(this); return amount.asType(type); }
@Override public FastMoney with(MonetaryOperator operator) { Objects.requireNonNull(operator); try { return FastMoney.class.cast(operator.apply(this)); } catch (ArithmeticException e) { throw e; } catch (Exception e) { throw new MonetaryException("Operator failed: " + operator, e); } }
@Override public MonetaryAmount with(MonetaryOperator operator) { try { return operator.apply(this); } catch (MonetaryException e) { throw e; } catch (Exception e) { throw new MonetaryException("Exception during operator execution.", e); } }
@Override public Money with(MonetaryOperator operator) { Objects.requireNonNull(operator); try { return Money.class.cast(operator.apply(this)); } catch (MonetaryException e) { throw e; } catch (Exception e) { throw new MonetaryException("Operator failed: " + operator, e); } }
@Override public RoundedMoney with(MonetaryOperator operator) { Objects.requireNonNull(operator); try { return RoundedMoney.from(operator.apply(this)); } catch (MonetaryException | ArithmeticException e) { throw e; } catch (Exception e) { throw new MonetaryException("Query failed: " + operator, e); } }
/** * Test with(null) throws a NullPointerException. */ @SpecAssertion(section = "4.2.2", id = "422-E2") @Test(description = "4.2.2 Bad case: For each amount class, test with(), operator throws exception.") public void testWithNull4ProvidedOperators() { for (MonetaryOperator op : TCKTestSetup.getTestConfiguration().getMonetaryOperators4Test()) { try { op.apply(null); AssertJUnit.fail("Section 4.2.2: NullPointerException expected as operator was applied on null, " + "operator was " + op.getClass().getName()); } catch (NullPointerException e) { // OK, everything else makes the test fail! } } }
@Override public Long toNonNullValue(MonetaryAmount value) { if (!currencyUnit.equals(value.getCurrency())) { throw new IllegalStateException("Expected currency " + currencyUnit.getCurrencyCode() + " but was " + value.getCurrency()); } return MonetaryUtil.majorPart().apply(value).getNumber().longValue(); }
@Override public Long toNonNullValue(MonetaryAmount value) { if (!currencyUnit.equals(value.getCurrency())) { throw new IllegalStateException("Expected currency " + currencyUnit.getCurrencyCode() + " but was " + value.getCurrency()); } return MonetaryUtil.majorPart().apply(value).getNumber().longValue(); }
@Override protected Object[] toConvertedColumns(MonetaryAmount value) { return new Object[] { value.getCurrency(), MonetaryUtil.majorPart().apply(value).getNumber().longValue() }; }
@Override protected Object[] toConvertedColumns(MonetaryAmount value) { return new Object[] { value.getCurrency(), MonetaryUtil.majorPart().apply(value).getNumber().longValue() }; }