From 633cd60572e15d6dc19bd604661b838e7c604d0c Mon Sep 17 00:00:00 2001 From: andrewlalis Date: Thu, 28 Dec 2023 21:44:17 -0500 Subject: [PATCH] Added all currencies to account edit page. --- .../perfin/control/EditAccountController.java | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/andrewlalis/perfin/control/EditAccountController.java b/src/main/java/com/andrewlalis/perfin/control/EditAccountController.java index ad191c5..eff6b4b 100644 --- a/src/main/java/com/andrewlalis/perfin/control/EditAccountController.java +++ b/src/main/java/com/andrewlalis/perfin/control/EditAccountController.java @@ -12,8 +12,8 @@ import javafx.scene.control.*; import javafx.scene.layout.VBox; import java.math.BigDecimal; -import java.util.Currency; -import java.util.Optional; +import java.util.*; +import java.util.stream.Stream; import static com.andrewlalis.perfin.PerfinApp.router; @@ -38,15 +38,18 @@ public class EditAccountController implements RouteSelectionListener { @FXML public void initialize() { - final String[] currencies = { - "USD", - "EUR", - "GBP" - }; - for (String currencyCode : currencies) { - accountCurrencyComboBox.getItems().add(Currency.getInstance(currencyCode)); - } - accountCurrencyComboBox.getSelectionModel().select(Currency.getInstance("USD")); + List priorityCurrencies = Stream.of("USD", "EUR", "GBP", "CAD", "AUD") + .map(Currency::getInstance) + .toList(); + List availableCurrencies = Currency.getAvailableCurrencies().stream() + .filter(c -> !priorityCurrencies.contains(c)) + .sorted(Comparator.comparing(Currency::getCurrencyCode)) + .toList(); + List allCurrencies = new ArrayList<>(); + allCurrencies.addAll(priorityCurrencies); + allCurrencies.addAll(availableCurrencies); + accountCurrencyComboBox.getItems().addAll(allCurrencies); + accountCurrencyComboBox.getSelectionModel().selectFirst(); accountTypeChoiceBox.getItems().add(AccountType.CHECKING); accountTypeChoiceBox.getItems().add(AccountType.SAVINGS);