/** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ private Builder(SwapLegAmount beanToCopy) { this.amount = beanToCopy.getAmount(); this.payReceive = beanToCopy.getPayReceive(); this.type = beanToCopy.getType(); this.currency = beanToCopy.getCurrency(); }
@Override public SwapLegAmount build() { return new SwapLegAmount( amount, payReceive, type, currency); }
public void convertedTo() { SwapLegAmount legAmount = SwapLegAmount.builder() .amount(CurrencyAmount.of(Currency.GBP, 10)) .payReceive(PayReceive.PAY) .type(SwapLegType.FIXED) .currency(Currency.GBP) .build(); SwapLegAmount convertedAmount = legAmount.convertedTo(Currency.USD, FxRate.of(Currency.GBP, Currency.USD, 1.6)); assertThat(convertedAmount.getAmount().getCurrency()).isEqualTo(Currency.USD); assertThat(convertedAmount.getAmount().getAmount()).isEqualTo(16.0); assertThat(convertedAmount.getPayReceive()).isEqualTo(legAmount.getPayReceive()); assertThat(convertedAmount.getType()).isEqualTo(legAmount.getType()); assertThat(convertedAmount.getCurrency()).isEqualTo(legAmount.getCurrency()); }
public void test_of() { SwapPaymentPeriod pp = mock(SwapPaymentPeriod.class); when(pp.getCurrency()).thenReturn(Currency.GBP); ResolvedSwapLeg leg = ResolvedSwapLeg.builder() .type(SwapLegType.FIXED) .payReceive(PayReceive.PAY) .paymentPeriods(pp) .build(); SwapLegAmount legAmount = SwapLegAmount.of(leg, CurrencyAmount.of(Currency.GBP, 10)); SwapLegAmount test = legAmount.convertedTo(Currency.USD, FxRate.of(Currency.GBP, Currency.USD, 1.6)); assertThat(test.getAmount().getCurrency()).isEqualTo(Currency.USD); assertThat(test.getAmount().getAmount()).isEqualTo(16.0); assertThat(test.getPayReceive()).isEqualTo(legAmount.getPayReceive()); assertThat(test.getType()).isEqualTo(legAmount.getType()); assertThat(test.getCurrency()).isEqualTo(legAmount.getCurrency()); }
/** * Obtains an instance from a swap leg and amount. * * @param leg the swap leg * @param amount the amount * @return the swap leg amount */ public static SwapLegAmount of(ResolvedSwapLeg leg, CurrencyAmount amount) { return builder() .amount(amount) .payReceive(leg.getPayReceive()) .type(leg.getType()) .currency(leg.getCurrency()) .build(); }
@Override public SwapLegAmount convertedTo(Currency resultCurrency, FxRateProvider rateProvider) { CurrencyAmount convertedAmount = amount.convertedTo(resultCurrency, rateProvider); return this.toBuilder().amount(convertedAmount).build(); }
public void test_serialization() { SwapLegAmount la = SwapLegAmount.builder() .amount(CURRENCY_AMOUNT) .payReceive(PayReceive.PAY) .type(SwapLegType.FIXED) .currency(Currency.EUR) .build(); assertSerialization(la); }
@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case -1413853096: // amount return ((SwapLegAmount) bean).getAmount(); case -885469925: // payReceive return ((SwapLegAmount) bean).getPayReceive(); case 3575610: // type return ((SwapLegAmount) bean).getType(); case 575402001: // currency return ((SwapLegAmount) bean).getCurrency(); } return super.propertyGet(bean, propertyName, quiet); }
public void coverage() { SwapLegAmount la1 = SwapLegAmount.builder() .amount(CURRENCY_AMOUNT) .payReceive(PayReceive.PAY) .type(SwapLegType.FIXED) .currency(Currency.EUR) .build(); coverImmutableBean(la1); SwapLegAmount la2 = SwapLegAmount.builder() .amount(CurrencyAmount.of(Currency.GBP, 10000)) .payReceive(PayReceive.RECEIVE) .type(SwapLegType.IBOR) .currency(Currency.GBP) .build(); coverBeanEquals(la1, la2); }
/** * Tests the tokens() method when the bean has a single property. The tokens should include the single property * name plus the tokens of the property value. */ public void tokensSingleProperty() { SwapLegAmount amount = SwapLegAmount.builder() .amount(CurrencyAmount.of(Currency.AUD, 7)) .payReceive(PayReceive.PAY) .type(SwapLegType.FIXED) .currency(Currency.AUD) .build(); LegAmounts amounts = LegAmounts.of(amount); BeanTokenEvaluator evaluator = new BeanTokenEvaluator(); Set<String> tokens = evaluator.tokens(amounts); assertThat(tokens).isEqualTo(ImmutableSet.of("amounts", "0", "aud", "pay", "fixed")); }
/** * Tests evaluating a bean with a single property. There are 2 different expected behaviours: * * 1) If the token matches the property, the property value is returned and the token is consumed. This is the same * as the normal bean behaviour. * 2) If the token doesn't match the property it is assumed to match something on the property's value. In this * case the property value is returned and no tokens are consumed. */ public void evaluateSingleProperty() { SwapLegAmount amount = SwapLegAmount.builder() .amount(CurrencyAmount.of(Currency.AUD, 7)) .payReceive(PayReceive.PAY) .type(SwapLegType.FIXED) .currency(Currency.AUD) .build(); LegAmounts amounts = LegAmounts.of(amount); BeanTokenEvaluator evaluator = new BeanTokenEvaluator(); EvaluationResult result1 = evaluator.evaluate(amounts, FUNCTIONS, "amounts", ImmutableList.of("foo", "bar")); assertThat(result1.getResult()).hasValue(ImmutableList.of(amount)); assertThat(result1.getRemainingTokens()).isEqualTo(ImmutableList.of("foo", "bar")); EvaluationResult result2 = evaluator.evaluate(amounts, FUNCTIONS, "baz", ImmutableList.of("foo", "bar")); assertThat(result2.getResult()).hasValue(ImmutableList.of(amount)); assertThat(result2.getRemainingTokens()).isEqualTo(ImmutableList.of("baz", "foo", "bar")); }
public void coverage() { LegAmounts test1 = LegAmounts.of(LEG_AMOUNT_1, LEG_AMOUNT_2); coverImmutableBean(test1); LegAmount swapLeg = SwapLegAmount.builder() .amount(CurrencyAmount.of(Currency.GBP, 1557.445)) .payReceive(PayReceive.PAY) .type(SwapLegType.FIXED) .currency(Currency.EUR) .build(); LegAmounts test2 = LegAmounts.of(swapLeg); coverBeanEquals(test1, test2); }