Package esmska.data

Class CountryPrefix


  • public class CountryPrefix
    extends java.lang.Object
    Class containing list of all telephone country prefixes (as defined in List of country calling codes) and some helper methods.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String INTERNATIONAL_CODE
      Country code for "international"
    • Constructor Summary

      Constructors 
      Constructor Description
      CountryPrefix()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String extractCountryCode​(java.lang.String gatewayName)
      Extract country code from gateway name
      static java.lang.String extractCountryPrefix​(java.lang.String number)
      Extract country prefix from phone number.
      static java.lang.String getCountryCode​(java.lang.String countryPrefix)
      Get country code for country with specified telephone country prefix.
      static java.util.ArrayList<java.lang.String> getCountryCodes()
      Get all country codes sorted ascendingly
      static java.lang.String getCountryPrefix​(java.lang.String countryCode)
      Get telephone country prefix for country with country code.
      static boolean isValidCountryPrefix​(java.lang.String prefix)
      Check validity of country prefix
      static java.lang.String stripCountryPrefix​(java.lang.String number, boolean onlyCurrent)
      Strip current country prefix from number if possible
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • INTERNATIONAL_CODE

        public static final java.lang.String INTERNATIONAL_CODE
        Country code for "international"
        See Also:
        Constant Field Values
    • Constructor Detail

      • CountryPrefix

        public CountryPrefix()
    • Method Detail

      • getCountryPrefix

        public static java.lang.String getCountryPrefix​(java.lang.String countryCode)
        Get telephone country prefix for country with country code.
        Parameters:
        countryCode - two letter country code as defined in ISO 3166-1 alpha-2.
        Returns:
        corresponding telephone country prefix or empty string if country wasn't found
      • getCountryCode

        public static java.lang.String getCountryCode​(java.lang.String countryPrefix)
        Get country code for country with specified telephone country prefix.
        Parameters:
        countryPrefix - telephone country prefix as defined in List of country calling codes. May be null or invalid.
        Returns:
        corresponding two letter country code or null if country prefix wasn't found
      • getCountryCodes

        public static java.util.ArrayList<java.lang.String> getCountryCodes()
        Get all country codes sorted ascendingly
      • stripCountryPrefix

        public static java.lang.String stripCountryPrefix​(java.lang.String number,
                                                          boolean onlyCurrent)
        Strip current country prefix from number if possible
        Parameters:
        number - number, can be null
        onlyCurrent - strip only currently set country prefix (in user preferences), do not touch numbers with other prefixes
        Returns:
        number with stripped country prefix from start if possible (valid prefix); otherwise non-modified number
      • extractCountryPrefix

        public static java.lang.String extractCountryPrefix​(java.lang.String number)
        Extract country prefix from phone number.
        Parameters:
        number - Phone number in fully international format. May be null or incomplete.
        Returns:
        Country prefix if valid one is found in the number. Null otherwise.
      • isValidCountryPrefix

        public static boolean isValidCountryPrefix​(java.lang.String prefix)
        Check validity of country prefix
        Returns:
        true if prefix is in form +[0-9]{1,4} and is valid for some existing country, false otherwise
      • extractCountryCode

        public static java.lang.String extractCountryCode​(java.lang.String gatewayName)
        Extract country code from gateway name
        Parameters:
        gatewayName - gateway name; may be invalid or null
        Returns:
        country code CC or INT; or null when gatewayName invalid or null