GithubHelp home page GithubHelp logo

countrycode's Introduction

Country Code Library

The Country Code library provides facilities for converting between different country code standards. This software is currently in a Beta form and is subject to change

Supported Standards

Standards are available in various formats. For example, the ISO 3166-1 alpha2 format for the country Afghanistan is AF, while its alpha3 and numeric formats are AFG and 004, respectively.

There are 3 currently supported standards and their respective available formats (the name and version in parenthesis, respectively, can be used to lookup the standard in the default StandardRegistry):

  • FIPS 10-4 (FIPS, 10-4)
    • alpha2
  • ISO 3166-1 (ISO3166, 1)
    • alpha2
    • alpha3
    • numeric
  • GENC 3.0.0 (GENC, 3.0.0)
    • alpha2
    • alpha3
    • numeric

A country code can be retrieved for a given format with the following:

CountryCode countryCode = new CountryCode();
String alpha2Format = countryCode.getAsFormat("alpha2"); // ex, "AF"

Converting between Country Codes

The converter is used to convert between country code standards. Standards can be retrieved via the StandardRegistry.

  Converter converter = new CountryCodeConvter();
  
  StandardRegistry registry = StandardRegistryImpl.getInstance();
  StandardProvider fipsStandard = registry.lookup("FIPS", "10-4");
  StandardProvider isoStandard = registry.lookup("ISO3166", "1");
  
  // converting from FIPS 10-4 to ISO 3166-1 with alpha2
  Set<CountryCode> convertedCountryCodes = converter.fromAlpha2("AF", fipsStandard.getStandard(), isoStandard.getStandard());
  
  // converting from FIPS 10-4 to ISO 3166-1 with alpha3
  Set<CountryCode> convertedCountryCodes = converter.fromAlpha3("AFG", fipsStandard.getStandard(), isoStandard.getStandard());
  
  // converting from FIPS 10-4 to ISO 3166-1 with numeric
  Set<CountryCode> convertedCountryCodes = converter.fromNumeric("004", fipsStandard.getStandard(), isoStandard.getStandard());

countrycode's People

Contributors

bdeining avatar peterhuffer avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.