Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Currencies not being loaded because of validation #33

Closed
serhuz opened this issue Jun 29, 2021 · 3 comments
Closed

Currencies not being loaded because of validation #33

serhuz opened this issue Jun 29, 2021 · 3 comments

Comments

@serhuz
Copy link

serhuz commented Jun 29, 2021

There's a logic that checks whether the given currency is valid

private boolean isValid(final Currency currency) {
    return currency != null && currency.getSymbol() != null && currency.getName() != null
        && currency.getCode() != null;
  }

Yet, there are currencies which have no symbol defined, like Hong Kong Dollar

{
    "country": "HK",
    "name": "Hong Kong dollar",
    "code": "HKD"
 }

This effectively excludes such currencies from being added to currencyMap field.

private void loadCurrencies(Context context) {
    final String currencyArray = AssetsReader.readFromAssets(context,
        R.raw.com_blongho_country_data_currencies);
    Gson gson = new Gson();
    final Currency[] currencies = gson.fromJson(currencyArray, Currency[].class);
    for (final Currency currency : currencies) {
      if (isValid(currency)) {
        currencyMap.put(currency.getCountry().toLowerCase(), currency);
      }
    }
  }

Would it make sense to mark the symbol field as @Nullable and remove isValid() check?

@github-actions
Copy link

Your first issue in worldCountryData. The team will take a look at it as soon as possible

@github-actions
Copy link

Staled issue

@blongho
Copy link
Owner

blongho commented Jun 6, 2022

Thanks for this eye-opener. This issue has been resolved

@blongho blongho closed this as completed Jun 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants