Skip to content

Commit

Permalink
Refactor for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
donfiguerres committed Jun 3, 2023
1 parent ef4ee59 commit 4e19417
Showing 1 changed file with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public ExchangeRateService(DataDownloader downloader) throws Exception {
* @return exchange rates
*/
public ExchangeRate getRatesForDate(LocalDate date) {
// Return exchange rate data for the given date
return exchangeRates.get(date);
}

Expand Down Expand Up @@ -114,12 +113,11 @@ public CurrencyAverageRate getAverageRate(LocalDate startDate,
.mapToDouble(BigDecimal::doubleValue)
.average();

BigDecimal averageRate = average.isPresent()
? BigDecimal.valueOf(average.getAsDouble())
.setScale(2, RoundingMode.HALF_UP)
: null;
return averageRate == null
? null
: new CurrencyAverageRate(currency, startDate, endDate, averageRate);
if (!average.isPresent())
return null;

BigDecimal averageRate = BigDecimal.valueOf(average.getAsDouble())
.setScale(2, RoundingMode.HALF_UP);
return new CurrencyAverageRate(currency, startDate, endDate, averageRate);
}
}

0 comments on commit 4e19417

Please sign in to comment.