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

org.jmrtd.lds.ICAOCountry Maven / Gradle / Ivy

There is a newer version: 0.7.42
Show newest version
/*
 * JMRTD - A Java API for accessing machine readable travel documents.
 *
 * Copyright (C) 2006 - 2013  The JMRTD team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 *
 * $Id: ICAOCountry.java 1555 2014-10-12 08:19:39Z martijno $
 */

package org.jmrtd.lds;

import net.sf.scuba.data.Country;

/**
 * Special ICAO countries not covered in {@link net.sf.scuba.data.ISOCountry}.
 * Contributed by Aleksandar Kamburov (wise_guybg).
 * 
 * @author Aleksandar Kamburov (wise_guybg)
 * 
 * @version $Revision: 1555 $
 */
public class ICAOCountry extends Country {
	
	public static final ICAOCountry
	DE = new ICAOCountry("DE", "D<<", "Germany", "German"),
	GBD = new ICAOCountry("GB","GBD","British Dependent territories citizen"),
	GBN = new ICAOCountry("GB","GBN","British National (Overseas)"),
	GBO = new ICAOCountry("GB","GBO","British Overseas citizen"),
	GBP = new ICAOCountry("GB","GBP","British Protected person"),
	GBS = new ICAOCountry("GB","GBS","British Subject"),
	UNO = new ICAOCountry("UN","UNO","United Nations Organization"),
	UNA = new ICAOCountry("UN","UNA","United Nations Agency"),
	UNK = new ICAOCountry("UN","UNK","United Nations Interim Administration Mission in Kosovo"),
	XOM = new ICAOCountry("XO","XOM","Sovereign Military Order of Malta"),
	XCC = new ICAOCountry("XC","XCC","Carribean Community"),
	XPO = new ICAOCountry("XP", "XPO", "Interpol"),
	XXA = new ICAOCountry("XX","XXA","Stateless person", "Stateless"),
	XXB = new ICAOCountry("XX","XXB","Refugee", "Refugee"),
	XXC = new ICAOCountry("XX","XXC","Refugee (other)", "Refugee (other)"),
	XXX = new ICAOCountry("XX","XXX","Unspecified", "Unspecified");

	private static ICAOCountry[] VALUES = {
		DE,
		GBD, GBN, GBO, GBP, GBS,
		UNO, UNA, UNK,
		XOM, XCC, XXA, XXB, XXC, XXX
	};
	
	private String name;
	private String nationality;
	private String alpha2Code;
	private String alpha3Code;
	
	/**
	 * Gets an ICAO country instance.
	 * 
	 * @param alpha3Code a three-digit ICAO country code
	 * 
	 * @return an ICAO country
	 */
	public static Country getInstance(String alpha3Code) {
		for (ICAOCountry country: VALUES) {
			if (country.alpha3Code.equals(alpha3Code)) { return country; }
		}
		try {
			return Country.getInstance(alpha3Code);
		} catch (Exception e) {
			/* NOTE: ignore this exception if it's not a legal 3 digit code. */
		}
		throw new IllegalArgumentException("Illegal ICAO country alpha 3 code " + alpha3Code);
	}
	
	/**
	 * Prevent caller from creating instance.
	 */
	private ICAOCountry() {
	}

	private ICAOCountry(String alpha2Code, String alpha3Code, String name) {
		this(alpha2Code, alpha3Code, name, name);
	}
	
	private ICAOCountry(String alpha2Code, String alpha3Code, String name, String nationality) {
		this.alpha2Code = alpha2Code;
		this.alpha3Code = alpha3Code;
		this.name = name;
		this.nationality = nationality;
	}

	public int valueOf() {
		return -1;
	}

	/**
	 * Gets the full name of the country.
	 * 
	 * @return a country name
	 */
	public String getName() {
		return name;
	}

	/**
	 * Gets the adjectival form corresponding to the country.
	 * 
	 * @return the nationality
	 */
	public String getNationality() {
		return nationality;
	}

	/**
	 * Gets the two-digit country code.
	 * 
	 * @return a two-digit country code
	 */
	public String toAlpha2Code() {
		return alpha2Code;
	}

	/**
	 * Gets the three-digit country code.
	 * 
	 * @return a three-digit country code
	 */
	public String toAlpha3Code() {
		return alpha3Code;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy