refactor non-fiat iso codes

This commit is contained in:
woodser 2023-05-23 17:39:26 -04:00
parent da0f4f4652
commit 1c172edb32

View file

@ -103,8 +103,7 @@ public class CurrencyUtil {
List<TraditionalCurrency> currencies = CountryUtil.getAllCountries().stream() List<TraditionalCurrency> currencies = CountryUtil.getAllCountries().stream()
.map(country -> getCurrencyByCountryCode(country.code)) .map(country -> getCurrencyByCountryCode(country.code))
.collect(Collectors.toList()); .collect(Collectors.toList());
currencies.add(new TraditionalCurrency(Currency.getInstance("XAG"))); // add silver for (String isoCode : nonFiatIsoCodes) currencies.add(new TraditionalCurrency(Currency.getInstance(isoCode)));
currencies.add(new TraditionalCurrency(Currency.getInstance("XAU"))); // add gold
return currencies.stream().sorted(TradeCurrency::compareTo) return currencies.stream().sorted(TradeCurrency::compareTo)
.distinct() .distinct()
.collect(Collectors.toMap(TradeCurrency::getCode, Function.identity(), (x, y) -> x, LinkedHashMap::new)); .collect(Collectors.toMap(TradeCurrency::getCode, Function.identity(), (x, y) -> x, LinkedHashMap::new));
@ -126,12 +125,13 @@ public class CurrencyUtil {
public static List<TraditionalCurrency> getMainTraditionalCurrencies() { public static List<TraditionalCurrency> getMainTraditionalCurrencies() {
List<TraditionalCurrency> list = getMainFiatCurrencies(); List<TraditionalCurrency> list = getMainFiatCurrencies();
list.add(new TraditionalCurrency("XAG")); for (String isoCode : nonFiatIsoCodes) list.add(new TraditionalCurrency(isoCode));
list.add(new TraditionalCurrency("XAU"));
postProcessTraditionalCurrenciesList(list); postProcessTraditionalCurrenciesList(list);
return list; return list;
} }
private static List<String> nonFiatIsoCodes = Arrays.asList("XAG", "XAU");
private static void postProcessTraditionalCurrenciesList(List<TraditionalCurrency> list) { private static void postProcessTraditionalCurrenciesList(List<TraditionalCurrency> list) {
list.sort(TradeCurrency::compareTo); list.sort(TradeCurrency::compareTo);