From 2b573c3b0a15ee476039ce078e40bc73a70a5143 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Mon, 11 Apr 2016 16:25:31 +0200 Subject: [PATCH] Added checked exception if a country is already added with code or i18n key --- .../CountryAlreadyAddedException.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/org/mxchange/jcountry/exceptions/CountryAlreadyAddedException.java diff --git a/src/org/mxchange/jcountry/exceptions/CountryAlreadyAddedException.java b/src/org/mxchange/jcountry/exceptions/CountryAlreadyAddedException.java new file mode 100644 index 0000000..1cb74d7 --- /dev/null +++ b/src/org/mxchange/jcountry/exceptions/CountryAlreadyAddedException.java @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2016 Roland Haeder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.jcountry.exceptions; + +import java.text.MessageFormat; +import org.mxchange.jcountry.data.Country; + +/** + * An exception thrown when a country is already registered. This can be easily + * checked if the country code is already there. + *

+ * @author Roland Haeder + */ +public class CountryAlreadyAddedException extends Exception { + + /** + * Serial number + */ + private static final long serialVersionUID = 186_971_766_917_042L; + + /** + * Constructor with newly country (no id number) + *

+ * @param country Country instance + */ + public CountryAlreadyAddedException (final Country country) { + // Call super constructor + super(MessageFormat.format("Country with code {0} or i18n key {1} has already been added.", country.getCountryCode(), country.getCountryI18nkey())); + } + +} -- 2.39.5