Source:
private static RateCalculation parseFixedRateCalculation(CsvRow row, String leg, double fixedRate, Currency currency) { FixedRateCalculation.Builder builder = FixedRateCalculation.builder(); builder.dayCount(DayCount.of(getValue(row, leg, DAY_COUNT_FIELD))); builder.rate(ValueSchedule.of(fixedRate)); Optional<Double> initialStubRateOpt = findValue(row, leg, INITIAL_STUB_RATE_FIELD) .map(s -> TradeCsvLoader.parseDoublePercent(s)); Optional<Double> initialStubAmountOpt = findValue(row, leg, INITIAL_STUB_AMOUNT_FIELD) .map(s -> TradeCsvLoader.parseDouble(s)); if (initialStubRateOpt.isPresent() && initialStubAmountOpt.isPresent()) { throw new IllegalArgumentException( "Swap leg must not define both '" + INITIAL_STUB_RATE_FIELD + "' and '" + INITIAL_STUB_AMOUNT_FIELD + "'"); } initialStubRateOpt.ifPresent(v -> builder.initialStub( FixedRateStubCalculation.ofFixedRate(v))); initialStubAmountOpt.ifPresent(v -> builder.initialStub( FixedRateStubCalculation.ofKnownAmount(CurrencyAmount.of(currency, v)))); Optional<Double> finalStubRateOpt = findValue(row, leg, FINAL_STUB_RATE_FIELD) .map(s -> TradeCsvLoader.parseDoublePercent(s)); Optional<Double> finalStubAmountOpt = findValue(row, leg, FINAL_STUB_AMOUNT_FIELD) .map(s -> TradeCsvLoader.parseDouble(s)); if (finalStubRateOpt.isPresent() && finalStubAmountOpt.isPresent()) { throw new IllegalArgumentException( "Swap leg must not define both '" + FINAL_STUB_RATE_FIELD + "' and '" + FINAL_STUB_AMOUNT_FIELD + "'"); } finalStubRateOpt.ifPresent(v -> builder.finalStub( FixedRateStubCalculation.ofFixedRate(v))); finalStubAmountOpt.ifPresent(v -> builder.finalStub( FixedRateStubCalculation.ofKnownAmount(CurrencyAmount.of(currency, v)))); return builder.build(); }

Target:
private static RateCalculation parseFixedRateCalculation(CsvRow row, String leg, double fixedRate, Currency currency) { FixedRateCalculation.Builder builder = FixedRateCalculation.builder(); builder.dayCount(DayCount.of(getValue(row, leg, DAY_COUNT_FIELD))); builder.rate(ValueSchedule.of(fixedRate)); Optional<Double> initialStubRateOpt = findValue(row, leg, INITIAL_STUB_RATE_FIELD) .map(s -> TradeCsvLoader.parseDoublePercent(s)); Optional<Double> initialStubAmountOpt = findValue(row, leg, INITIAL_STUB_AMOUNT_FIELD) .map(s -> TradeCsvLoader.parseDouble(s)); if (initialStubRateOpt.isPresent() && initialStubAmountOpt.isPresent()) { throw new IllegalArgumentException( "Swap leg must not define both '" + leg + INITIAL_STUB_RATE_FIELD + "' and '" + leg + INITIAL_STUB_AMOUNT_FIELD + "'"); } initialStubRateOpt.ifPresent(v -> builder.initialStub( FixedRateStubCalculation.ofFixedRate(v))); initialStubAmountOpt.ifPresent(v -> builder.initialStub( FixedRateStubCalculation.ofKnownAmount(CurrencyAmount.of(currency, v)))); Optional<Double> finalStubRateOpt = findValue(row, leg, FINAL_STUB_RATE_FIELD) .map(s -> TradeCsvLoader.parseDoublePercent(s)); Optional<Double> finalStubAmountOpt = findValue(row, leg, FINAL_STUB_AMOUNT_FIELD) .map(s -> TradeCsvLoader.parseDouble(s)); if (finalStubRateOpt.isPresent() && finalStubAmountOpt.isPresent()) { throw new IllegalArgumentException( "Swap leg must not define both '" + leg + FINAL_STUB_RATE_FIELD + "' and '" + leg + FINAL_STUB_AMOUNT_FIELD + "'"); } finalStubRateOpt.ifPresent(v -> builder.finalStub( FixedRateStubCalculation.ofFixedRate(v))); finalStubAmountOpt.ifPresent(v -> builder.finalStub( FixedRateStubCalculation.ofKnownAmount(CurrencyAmount.of(currency, v)))); return builder.build(); }