Hi team,
I have a resolved interest rate swap trade.
I would like to remove the first floating payment period on leg 2 and keep the remaining payments.
Looks like the remove method is deprecated:
resolvedswap.getProduct().getLegs().get(1).getPaymentPeriods().remove(0)
What’s the best way to do this?
Thank you
Yoichi
stephen
2
As the beans are immutable, you have to make a copy with the value changed, something like:
var leg1 = resolvedswap.getProduct().getLegs().get(0);
var leg2 = resolvedswap.getProduct().getLegs().get(1);
resolvedSwap = resolvedSwap.toBuilder()
.product(resolvedSwap.getProduct().toBuilder()
.legs(
leg1,
leg2.toBuilder()
.paymentPeriods(leg2.getPaymentPeriods().subList(1, leg2.getPaymentPeriods().size()))
.build())
.build();
.build();
(this might not compile as I wrote it in the forum, but is the general approach to editing a tree of immutable beans)
1 Like