From: Roland Häder Date: Sun, 15 Oct 2017 21:09:58 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=4663aa495cf990daaf8affd56ebf56a12dc24b40;p=jcountry-core.git Continued: - moved event to own package - added exception for not-found country data Signed-off-by: Roland Häder --- diff --git a/src/org/mxchange/jcountry/events/AdminAddedCountryEvent.java b/src/org/mxchange/jcountry/events/AdminAddedCountryEvent.java deleted file mode 100644 index 21c71db..0000000 --- a/src/org/mxchange/jcountry/events/AdminAddedCountryEvent.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (C) 2016, 2017 Roland Häder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.jcountry.events; - -import java.text.MessageFormat; -import org.mxchange.jcountry.model.data.Country; - -/** - * An addedCountry triggered when the administrator adds a new country - *

- * @author Roland Häder - */ -public class AdminAddedCountryEvent implements ObservableAdminAddedCountryEvent { - - /** - * Serial number - */ - private static final long serialVersionUID = 13_856_941_875_871_769L; - - /** - * Added country - */ - private final Country addedCountry; - - /** - * Constructor with added country - *

- * @param addedCountry Added country - */ - public AdminAddedCountryEvent (final Country addedCountry) { - // Is all valid? - if (null == addedCountry) { - // Throw NPE - throw new NullPointerException("addedCountry is null"); //NOI18N - } else if (addedCountry.getCountryId() == null) { - // And again ... - throw new NullPointerException("addedCountry.countryId is null"); //NOI18N - } else if (addedCountry.getCountryId() < 1) { - // Id is invalid - throw new IllegalArgumentException(MessageFormat.format("addedCountry.countryId={0} is not valid.", addedCountry.getCountryId())); //NOI18N - } - - // Set country - this.addedCountry = addedCountry; - } - - @Override - public Country getAddedCountry () { - return this.addedCountry; - } - -} diff --git a/src/org/mxchange/jcountry/events/ObservableAdminAddedCountryEvent.java b/src/org/mxchange/jcountry/events/ObservableAdminAddedCountryEvent.java deleted file mode 100644 index ac8142d..0000000 --- a/src/org/mxchange/jcountry/events/ObservableAdminAddedCountryEvent.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2016, 2017 Roland Häder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.jcountry.events; - -import java.io.Serializable; -import org.mxchange.jcountry.model.data.Country; - -/** - * An interface for a country being added by the administrator. - *

- * @author Roland Häder - */ -public interface ObservableAdminAddedCountryEvent extends Serializable { - - /** - * Getter for added country - *

- * @return Added country - */ - Country getAddedCountry (); - -} diff --git a/src/org/mxchange/jcountry/events/added/AdminAddedCountryEvent.java b/src/org/mxchange/jcountry/events/added/AdminAddedCountryEvent.java new file mode 100644 index 0000000..d14df9c --- /dev/null +++ b/src/org/mxchange/jcountry/events/added/AdminAddedCountryEvent.java @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2016, 2017 Roland Häder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.jcountry.events.added; + +import java.text.MessageFormat; +import org.mxchange.jcountry.model.data.Country; + +/** + * An addedCountry triggered when the administrator adds a new country + *

+ * @author Roland Häder + */ +public class AdminAddedCountryEvent implements ObservableAdminAddedCountryEvent { + + /** + * Serial number + */ + private static final long serialVersionUID = 13_856_941_875_871_769L; + + /** + * Added country + */ + private final Country addedCountry; + + /** + * Constructor with added country + *

+ * @param addedCountry Added country + */ + public AdminAddedCountryEvent (final Country addedCountry) { + // Is all valid? + if (null == addedCountry) { + // Throw NPE + throw new NullPointerException("addedCountry is null"); //NOI18N + } else if (addedCountry.getCountryId() == null) { + // And again ... + throw new NullPointerException("addedCountry.countryId is null"); //NOI18N + } else if (addedCountry.getCountryId() < 1) { + // Id is invalid + throw new IllegalArgumentException(MessageFormat.format("addedCountry.countryId={0} is not valid.", addedCountry.getCountryId())); //NOI18N + } + + // Set country + this.addedCountry = addedCountry; + } + + @Override + public Country getAddedCountry () { + return this.addedCountry; + } + +} diff --git a/src/org/mxchange/jcountry/events/added/ObservableAdminAddedCountryEvent.java b/src/org/mxchange/jcountry/events/added/ObservableAdminAddedCountryEvent.java new file mode 100644 index 0000000..64fd7a1 --- /dev/null +++ b/src/org/mxchange/jcountry/events/added/ObservableAdminAddedCountryEvent.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2016, 2017 Roland Häder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.jcountry.events.added; + +import java.io.Serializable; +import org.mxchange.jcountry.model.data.Country; + +/** + * An interface for a country being added by the administrator. + *

+ * @author Roland Häder + */ +public interface ObservableAdminAddedCountryEvent extends Serializable { + + /** + * Getter for added country + *

+ * @return Added country + */ + Country getAddedCountry (); + +} diff --git a/src/org/mxchange/jcountry/exceptions/CountryNotFoundException.java b/src/org/mxchange/jcountry/exceptions/CountryNotFoundException.java new file mode 100644 index 0000000..1da0c6a --- /dev/null +++ b/src/org/mxchange/jcountry/exceptions/CountryNotFoundException.java @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2016, 2017 Roland Häder + * + * 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; + +/** + * An exception thrown when a country was not found. + *

+ * @author Roland Häder + */ +public class CountryNotFoundException extends Exception { + + /** + * Serial number + */ + private static final long serialVersionUID = 186_971_766_917_043L; + + /** + * Constructor with primary key + *

+ * @param countryId Primary key + */ + public CountryNotFoundException (final Long countryId) { + // Call super constructor + super(MessageFormat.format("Country with with id {0} was not found.", countryId)); + } + +}