001/* 002 * oauth2-oidc-sdk 003 * 004 * Copyright 2012-2016, Connect2id Ltd and contributors. 005 * 006 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use 007 * this file except in compliance with the License. You may obtain a copy of the 008 * License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software distributed 013 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 014 * CONDITIONS OF ANY KIND, either express or implied. See the License for the 015 * specific language governing permissions and limitations under the License. 016 */ 017 018package com.nimbusds.openid.connect.sdk.assurance.claims; 019 020 021import net.jcip.annotations.Immutable; 022 023import com.nimbusds.oauth2.sdk.ParseException; 024 025 026/** 027 * ISO 3166-1 alpha-2 (two-letter) country code. 028 */ 029@Immutable 030public final class ISO3166_1Alpha2CountryCode extends CountryCode { 031 032 033 private static final long serialVersionUID = -7659886425656766569L; 034 035 036 /** 037 * Creates a new ISO 3166-1 alpha-2 country code. Normalises the code 038 * to upper case. 039 * 040 * @param value The country code value, must be two-letter. 041 */ 042 public ISO3166_1Alpha2CountryCode(final String value) { 043 super(value.toUpperCase()); 044 if (value.length() != 2) { 045 throw new IllegalArgumentException("The ISO 3166-1 alpha-2 country code must be two letters"); 046 } 047 } 048 049 050 @Override 051 public boolean equals(final Object object) { 052 053 return object instanceof ISO3166_1Alpha2CountryCode && 054 this.toString().equals(object.toString()); 055 } 056 057 058 /** 059 * Parses an ISO 3166-1 alpha-2 (two-letter) country code. 060 * 061 * @param s The string to parse. Must not be {@code null}. 062 * 063 * @return The ISO 3166-1 alpha-2 (two-letter) country code. 064 * 065 * @throws ParseException If parsing failed. 066 */ 067 public static ISO3166_1Alpha2CountryCode parse(final String s) 068 throws ParseException { 069 070 try { 071 return new ISO3166_1Alpha2CountryCode(s); 072 } catch (IllegalArgumentException e) { 073 throw new ParseException(e.getMessage()); 074 } 075 } 076}