<commit_before>/*
 * This file is part of Bisq.
 *
 * Bisq is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or (at
 * your option) any later version.
 *
 * Bisq is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
 * License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with Bisq. If not, see <http://www.gnu.org/licenses/>.
 */

package io.bisq.common.locale;

import io.bisq.common.GlobalSettings;
import lombok.extern.slf4j.Slf4j;

import java.util.*;
import java.util.stream.Collectors;

@Slf4j
public class CurrencyUtil {
    private static String baseCurrencyCode = "BTC";

    public static void setBaseCurrencyCode(String baseCurrencyCode) {
        CurrencyUtil.baseCurrencyCode = baseCurrencyCode;
    }

    private static List<FiatCurrency> allSortedFiatCurrencies;

    private static List<FiatCurrency> createAllSortedFiatCurrenciesList() {
        Set<FiatCurrency> set = CountryUtil.getAllCountries().stream()
                .map(country -> getCurrencyByCountryCode(country.code))
                .collect(Collectors.toSet());
        List<FiatCurrency> list = new ArrayList<>(set);
        list.sort(TradeCurrency::compareTo);
        return list;
    }

    public static List<FiatCurrency> getAllSortedFiatCurrencies() {
        if (Objects.isNull(allSortedFiatCurrencies)) {
            allSortedFiatCurrencies = createAllSortedFiatCurrenciesList();
        }
        return allSortedFiatCurrencies;
    }


    public static List<FiatCurrency> getMainFiatCurrencies() {
        TradeCurrency defaultTradeCurrency = getDefaultTradeCurrency();
        List<FiatCurrency> list = new ArrayList<>();
        // Top traded currencies
        list.add(new FiatCurrency("USD"));
        list.add(new FiatCurrency("EUR"));
        list.add(new FiatCurrency("GBP"));
        list.add(new FiatCurrency("CAD"));
        list.add(new FiatCurrency("AUD"));
        list.add(new FiatCurrency("RUB"));
        list.add(new FiatCurrency("INR"));

        list.sort(TradeCurrency::compareTo);

        FiatCurrency defaultFiatCurrency = defaultTradeCurrency instanceof FiatCurrency ? (FiatCurrency) defaultTradeCurrency : null;
        if (defaultFiatCurrency != null && list.contains(defaultFiatCurrency)) {
            //noinspection SuspiciousMethodCalls
            list.remove(defaultTradeCurrency);
            list.add(0, defaultFiatCurrency);
        }
        return list;
    }

    private static List<CryptoCurrency> allSortedCryptoCurrencies;

    public static List<CryptoCurrency> getAllSortedCryptoCurrencies() {
        if (allSortedCryptoCurrencies == null)
            allSortedCryptoCurrencies = createAllSortedCryptoCurrenciesList();
        return allSortedCryptoCurrencies;
    }

    // Don't make a PR for adding a coin but follow the steps described here:
    // https://forum.bisq.network/t/how-to-add-your-favorite-altcoin/
    public static List<CryptoCurrency> createAllSortedCryptoCurrenciesList() {
        final List<CryptoCurrency> result = new ArrayList<>();

        // result.add(new CryptoCurrency("BSQ", "Bisq Token"));
        if (!baseCurrencyCode.equals("BTC"))
            result.add(new CryptoCurrency("BTC", "Bitcoin"));
        result.add(new CryptoCurrency("BURST", "Burstcoin"));
        result.add(new CryptoCurrency("GBYTE", "Byte"));
        result.add(new CryptoCurrency("XCP", "Counterparty"));
        result.add(new CryptoCurrency("XCN", "Cryptonite"));
        result.add(new CryptoCurrency("DNET", "DarkNet"));
        if (!baseCurrencyCode.equals("DASH"))
            result.add(new CryptoCurrency("DASH", "Dash"));
        result.add(new CryptoCurrency("DCT", "DECENT"));
        result.add(new CryptoCurrency("DCR", "Decred"));
        if (!baseCurrencyCode.equals("DOGE"))
            result.add(new CryptoCurrency("DOGE", "Dogecoin"));
        result.add(new CryptoCurrency("DMC", "DynamicCoin"));
        result.add(new CryptoCurrency("ELLA", "Ellaism"));
        result.add(new CryptoCurrency("ESP", "Espers"));
        result.add(new CryptoCurrency("ETH", "Ether"));
        result.add(new CryptoCurrency("ETC", "Ether Classic"));
        result.add(new CryptoCurrency("IOP", "Internet Of People"));
        result.add(new CryptoCurrency("INXT", "Internext", true));
        result.add(new CryptoCurrency("GRC", "Gridcoin"));
        result.add(new CryptoCurrency("LBC", "LBRY Credits"));
        result.add(new CryptoCurrency("LSK", "Lisk"));
        if (!baseCurrencyCode.equals("LTC"))
            result.add(new CryptoCurrency("LTC", "Litecoin"));
        result.add(new CryptoCurrency("MAID", "MaidSafeCoin"));
        result.add(new CryptoCurrency("XMR", "Monero"));
        result.add(new CryptoCurrency("MT", "Mycelium Token", true));
        result.add(new CryptoCurrency("NAV", "Nav Coin"));
        result.add(new CryptoCurrency("NMC", "Namecoin"));
        result.add(new CryptoCurrency("NBT", "NuBits"));
        result.add(new CryptoCurrency("NXT", "Nxt"));
        result.add(new CryptoCurrency("888", "OctoCoin"));
        result.add(new CryptoCurrency("PART", "Particl"));
        result.add(new CryptoCurrency("PASC", "Pascal Coin", true));
        result.add(new CryptoCurrency("PEPECASH", "Pepe Cash"));
        result.add(new CryptoCurrency("PIVX", "PIVX"));
        result.add(new CryptoCurrency("POST", "PostCoin"));
        result.add(new CryptoCurrency("PNC", "Pranacoin"));
        result.add(new CryptoCurrency("RDD", "ReddCoin"));
        result.add(new CryptoCurrency("SFSC", "Safe FileSystem Coin"));
        result.add(new CryptoCurrency("SC", "Siacoin"));
        result.add(new CryptoCurrency("SF", "Siafund"));
        result.add(new CryptoCurrency("SIB", "Sibcoin"));
        result.add(new CryptoCurrency("STEEM", "STEEM"));
        result.add(new CryptoCurrency("TRC", "Terracoin"));

        result.add(new CryptoCurrency("UNO", "Unobtanium"));
        result.add(new CryptoCurrency("WAC", "WACoins"));
        result.add(new CryptoCurrency("XZC", "Zcoin"));
        result.add(new CryptoCurrency("ZEC", "Zcash"));
        result.add(new CryptoCurrency("ZEN", "ZenCash"));

        result.sort(TradeCurrency::compareTo);

        // Util for printing all altcoins for adding to FAQ page<commit_msg>Update CurrencyUtil.java<commit_after>/*
 * This file is part of Bisq.
 *
 * Bisq is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or (at
 * your option) any later version.
 *
 * Bisq is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
 * License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with Bisq. If not, see <http://www.gnu.org/licenses/>.
 */

package io.bisq.common.locale;

import io.bisq.common.GlobalSettings;
import lombok.extern.slf4j.Slf4j;

import java.util.*;
import java.util.stream.Collectors;

@Slf4j
public class CurrencyUtil {
    private static String baseCurrencyCode = "BTC";

    public static void setBaseCurrencyCode(String baseCurrencyCode) {
        CurrencyUtil.baseCurrencyCode = baseCurrencyCode;
    }

    private static List<FiatCurrency> allSortedFiatCurrencies;

    private static List<FiatCurrency> createAllSortedFiatCurrenciesList() {
        Set<FiatCurrency> set = CountryUtil.getAllCountries().stream()
                .map(country -> getCurrencyByCountryCode(country.code))
                .collect(Collectors.toSet());
        List<FiatCurrency> list = new ArrayList<>(set);
        list.sort(TradeCurrency::compareTo);
        return list;
    }

    public static List<FiatCurrency> getAllSortedFiatCurrencies() {
        if (Objects.isNull(allSortedFiatCurrencies)) {
            allSortedFiatCurrencies = createAllSortedFiatCurrenciesList();
        }
        return allSortedFiatCurrencies;
    }


    public static List<FiatCurrency> getMainFiatCurrencies() {
        TradeCurrency defaultTradeCurrency = getDefaultTradeCurrency();
        List<FiatCurrency> list = new ArrayList<>();
        // Top traded currencies
        list.add(new FiatCurrency("USD"));
        list.add(new FiatCurrency("EUR"));
        list.add(new FiatCurrency("GBP"));
        list.add(new FiatCurrency("CAD"));
        list.add(new FiatCurrency("AUD"));
        list.add(new FiatCurrency("RUB"));
        list.add(new FiatCurrency("INR"));

        list.sort(TradeCurrency::compareTo);

        FiatCurrency defaultFiatCurrency = defaultTradeCurrency instanceof FiatCurrency ? (FiatCurrency) defaultTradeCurrency : null;
        if (defaultFiatCurrency != null && list.contains(defaultFiatCurrency)) {
            //noinspection SuspiciousMethodCalls
            list.remove(defaultTradeCurrency);
            list.add(0, defaultFiatCurrency);
        }
        return list;
    }

    private static List<CryptoCurrency> allSortedCryptoCurrencies;

    public static List<CryptoCurrency> getAllSortedCryptoCurrencies() {
        if (allSortedCryptoCurrencies == null)
            allSortedCryptoCurrencies = createAllSortedCryptoCurrenciesList();
        return allSortedCryptoCurrencies;
    }

    // Don't make a PR for adding a coin but follow the steps described here:
    // https://forum.bisq.network/t/how-to-add-your-favorite-altcoin/
    public static List<CryptoCurrency> createAllSortedCryptoCurrenciesList() {
        final List<CryptoCurrency> result = new ArrayList<>();

        // result.add(new CryptoCurrency("BSQ", "Bisq Token"));
        if (!baseCurrencyCode.equals("BTC"))
            result.add(new CryptoCurrency("BTC", "Bitcoin"));
        result.add(new CryptoCurrency("BURST", "Burstcoin"));
        result.add(new CryptoCurrency("GBYTE", "Byte"));
        result.add(new CryptoCurrency("XCP", "Counterparty"));
        result.add(new CryptoCurrency("XCN", "Cryptonite"));
        result.add(new CryptoCurrency("DNET", "DarkNet"));
        if (!baseCurrencyCode.equals("DASH"))
            result.add(new CryptoCurrency("DASH", "Dash"));
        result.add(new CryptoCurrency("DCT", "DECENT"));
        result.add(new CryptoCurrency("DCR", "Decred"));
        if (!baseCurrencyCode.equals("DOGE"))
            result.add(new CryptoCurrency("DOGE", "Dogecoin"));
        result.add(new CryptoCurrency("DMC", "DynamicCoin"));
        result.add(new CryptoCurrency("ELLA", "Ellaism"));
        result.add(new CryptoCurrency("ESP", "Espers"));
        result.add(new CryptoCurrency("ETH", "Ether"));
        result.add(new CryptoCurrency("ETC", "Ether Classic"));
        result.add(new CryptoCurrency("IOP", "Internet Of People"));
        result.add(new CryptoCurrency("INXT", "Internext", true));
        result.add(new CryptoCurrency("GRC", "Gridcoin"));
        result.add(new CryptoCurrency("LBC", "LBRY Credits"));
        result.add(new CryptoCurrency("LSK", "Lisk"));
        if (!baseCurrencyCode.equals("LTC"))
            result.add(new CryptoCurrency("LTC", "Litecoin"));
        result.add(new CryptoCurrency("MAID", "MaidSafeCoin"));
        result.add(new CryptoCurrency("MDC", "Madcoin"));
        result.add(new CryptoCurrency("XMR", "Monero"));
        result.add(new CryptoCurrency("MT", "Mycelium Token", true));
        result.add(new CryptoCurrency("NAV", "Nav Coin"));
        result.add(new CryptoCurrency("NMC", "Namecoin"));
        result.add(new CryptoCurrency("NBT", "NuBits"));
        result.add(new CryptoCurrency("NXT", "Nxt"));
        result.add(new CryptoCurrency("888", "OctoCoin"));
        result.add(new CryptoCurrency("PART", "Particl"));
        result.add(new CryptoCurrency("PASC", "Pascal Coin", true));
        result.add(new CryptoCurrency("PEPECASH", "Pepe Cash"));
        result.add(new CryptoCurrency("PIVX", "PIVX"));
        result.add(new CryptoCurrency("POST", "PostCoin"));
        result.add(new CryptoCurrency("PNC", "Pranacoin"));
        result.add(new CryptoCurrency("RDD", "ReddCoin"));
        result.add(new CryptoCurrency("SFSC", "Safe FileSystem Coin"));
        result.add(new CryptoCurrency("SC", "Siacoin"));
        result.add(new CryptoCurrency("SF", "Siafund"));
        result.add(new CryptoCurrency("SIB", "Sibcoin"));
        result.add(new CryptoCurrency("STEEM", "STEEM"));
        result.add(new CryptoCurrency("TRC", "Terracoin"));

        result.add(new CryptoCurrency("UNO", "Unobtanium"));
        result.add(new CryptoCurrency("WAC", "WACoins"));
        result.add(new CryptoCurrency("XZC", "Zcoin"));
        result.add(new CryptoCurrency("ZEC", "Zcash"));
        result.add(new CryptoCurrency("ZEN", "ZenCash"));

        result.sort(TradeCurrency::compareTo);

        // Util for printing all altcoins for adding to FAQ page
{'fraction_non_alphanumeric': 0.13380761371376673, 'fraction_numerical': 0.0012109286308938168, 'mean_word_length': 3.529996571820363, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 35, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4439615', 'n_tokens_mistral': 3960, 'n_tokens_neox': 4034, 'n_words': 857}