All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dev.robocode.tankroyale.botapi.util.CountryCodeUtil Maven / Gradle / Ivy

There is a newer version: 0.26.1
Show newest version
package dev.robocode.tankroyale.botapi.util;

import com.neovisionaries.i18n.CountryCode;

import java.util.Locale;

/**
 * Country code utility class.
 */
public final class CountryCodeUtil {

    // Hides constructor
    private CountryCodeUtil() {
    }

    public static String getLocalCountryCode() {
        var countryCode = CountryCode.getByLocale(Locale.getDefault()).getAlpha2();
        if ("UNDEFINED".equalsIgnoreCase(countryCode)) {
            return null;
        }
        return countryCode;
    }

    public static CountryCode toCountryCode(String code) {
        if (code == null || code.trim().length() != 2) {
            return null;
        }
        return CountryCode.getByCodeIgnoreCase(code.trim());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy