Class Country

  • All Implemented Interfaces:
    Serializable, Comparable<Country>

    public final class Country
    extends Object
    implements Comparable<Country>, Serializable
    A country or territory.

    This class represents a country or territory that it is useful to identify. Any two letter code may be used, however it is intended to use codes based on ISO-3166-1 alpha-2.

    This class is immutable and thread-safe.

    See Also:
    Serialized Form
    • Field Detail

      • EU

        public static final Country EU
        The region of 'EU' - Europe (special status in ISO-3166).
      • AT

        public static final Country AT
        The country 'AT' - Austria.
      • BE

        public static final Country BE
        The country 'BE' - Belgium.
      • CH

        public static final Country CH
        The country 'CH' - Switzerland.
      • CZ

        public static final Country CZ
        The currency 'CZ' - Czech Republic.
      • DE

        public static final Country DE
        The country 'DE' - Germany.
      • DK

        public static final Country DK
        The country 'DK' - Denmark.
      • ES

        public static final Country ES
        The currency 'ES' - Spain.
      • FI

        public static final Country FI
        The currency 'FI' - Finland.
      • FR

        public static final Country FR
        The currency 'FR' - France.
      • GB

        public static final Country GB
        The country 'GB' - United Kingdom.
      • GR

        public static final Country GR
        The country 'GR' - Greece.
      • HU

        public static final Country HU
        The currency 'HU' = Hungary.
      • IE

        public static final Country IE
        The currency 'IE' - Ireland.
      • IS

        public static final Country IS
        The currency 'IS' - Iceland.
      • IT

        public static final Country IT
        The currency 'IT' - Italy.
      • LU

        public static final Country LU
        The currency 'LU' - Luxembourg.
      • NL

        public static final Country NL
        The currency 'NL' - Netherlands.
      • NO

        public static final Country NO
        The currency 'NO' - Norway.
      • PL

        public static final Country PL
        The currency 'PL' = Poland.
      • PT

        public static final Country PT
        The currency 'PT' - Portugal.
      • SE

        public static final Country SE
        The currency 'SE' - Sweden.
      • SK

        public static final Country SK
        The currency 'SK' - Slovakia.
      • TR

        public static final Country TR
        The country 'TR' - Turkey.
      • AR

        public static final Country AR
        The country 'AR' - Argentina.
      • BR

        public static final Country BR
        The country 'BR' - Brazil.
      • CA

        public static final Country CA
        The country 'CA' - Canada.
      • CL

        public static final Country CL
        The country 'CL' - Chile.
      • MX

        public static final Country MX
        The country 'MX' - Mexico.
      • US

        public static final Country US
        The country 'US' - United States.
      • AU

        public static final Country AU
        The country 'AU' - Australia.
      • CN

        public static final Country CN
        The country 'CN' - China.
      • EG

        public static final Country EG
        The currency 'EG' - Egypt.
      • HK

        public static final Country HK
        The currency 'HK' - Hong Kong.
      • ID

        public static final Country ID
        The country 'ID' - Indonesia.
      • IL

        public static final Country IL
        The country 'IL' - Israel.
      • IN

        public static final Country IN
        The country 'IN' - India.
      • JP

        public static final Country JP
        The country 'JP' - Japan.
      • KR

        public static final Country KR
        The country 'KR' - South Korea.
      • MY

        public static final Country MY
        The country 'MY' - Malaysia.
      • NZ

        public static final Country NZ
        The country 'NZ' - New Zealand.
      • RU

        public static final Country RU
        The currency 'RU' = Russia.
      • SA

        public static final Country SA
        The country 'SA' - Saudi Arabia.
      • SG

        public static final Country SG
        The country 'SG' - Singapore.
      • TH

        public static final Country TH
        The country 'TH' - Thailand.
      • ZA

        public static final Country ZA
        The country 'ZA' - South Africa.
    • Method Detail

      • getAvailableCountries

        public static Set<Country> getAvailableCountries()
        Obtains the set of available countries.

        This contains all the countries that have been defined at the point that the method is called.

        Returns:
        an immutable set containing all registered countries
      • of

        public static Country of​(String countryCode)
        Obtains an instance from the specified ISO-3166-1 alpha-2 two letter country code dynamically creating a country if necessary.

        A country is uniquely identified by ISO-3166-1 alpha-2 two letter code. This method creates the country if it is not known.

        Parameters:
        countryCode - the two letter country code, ASCII and upper case
        Returns:
        the singleton instance
        Throws:
        IllegalArgumentException - if the country code is invalid
      • parse

        public static Country parse​(String countryCode)
        Parses a string to obtain a Country.

        The parse is identical to of(String) except that it will convert letters to upper case first.

        Parameters:
        countryCode - the two letter country code, ASCII
        Returns:
        the singleton instance
        Throws:
        IllegalArgumentException - if the country code is invalid
      • getCode

        public String getCode()
        Gets the two letter ISO code.
        Returns:
        the two letter ISO code
      • compareTo

        public int compareTo​(Country other)
        Compares this country to another.

        The comparison sorts alphabetically by the two letter country code.

        Specified by:
        compareTo in interface Comparable<Country>
        Parameters:
        other - the other country
        Returns:
        negative if less, zero if equal, positive if greater
      • equals

        public boolean equals​(Object obj)
        Checks if this country equals another country.

        The comparison checks the two letter country code.

        Overrides:
        equals in class Object
        Parameters:
        obj - the other country, null returns false
        Returns:
        true if equal
      • hashCode

        public int hashCode()
        Returns a suitable hash code for the country.
        Overrides:
        hashCode in class Object
        Returns:
        the hash code
      • toString

        public String toString()
        Returns a string representation of the country, which is the two letter code.
        Overrides:
        toString in class Object
        Returns:
        the two letter country code