]> git.mxchange.org Git - jcountry-core.git/blob - src/org/mxchange/jcountry/model/data/Countries.java
825ec111732607ebacc8111c3891b27169486d19
[jcountry-core.git] / src / org / mxchange / jcountry / model / data / Countries.java
1 /*
2  * Copyright (C) 2022 Free Software Foundation
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 package org.mxchange.jcountry.model.data;
18
19 import java.io.Serializable;
20 import java.util.Objects;
21
22 /**
23  * An utilities class for countries
24  * <p>
25  * @author Roland Häder<roland@mxchange.org>
26  */
27 public class Countries implements Serializable {
28
29         /**
30          * Serial number
31          */
32         private static final long serialVersionUID = 286_956_737_410L;
33
34         /**
35          * Copies data from sourceCountry to targetCountry.
36          * <p>
37          * @param sourceCountry Source Country instance to copy data from
38          * @param targetCountry Target Country instance to copy data to
39          * <p>
40          * @throws NullPointerException If sourceCountry or targetCountry is null
41          * @throws IllegalArgumentException If both Country instances are equal
42          */
43         public static void copyCountryData (final Country sourceCountry, final Country targetCountry) {
44                 // Parameters should not be null
45                 if (null == sourceCountry) {
46                         // Throw NPE
47                         throw new NullPointerException("sourceCountry is null"); //NOI18N
48                 } else if (null == targetCountry) {
49                         // Throw NPE
50                         throw new NullPointerException("targetCountry is null"); //NOI18N
51                 } else if (Objects.equals(sourceCountry, targetCountry)) {
52                         /*
53                          * Source and target country should never be equal, please check the
54                          * condition before invoking this method.
55                          */
56                         throw new IllegalArgumentException("Both sourceCountry and targetCountry are equal.");
57                 }
58
59                 // Copy all fields
60                 targetCountry.setCountryAbroadDialPrefix(sourceCountry.getCountryAbroadDialPrefix());
61                 targetCountry.setCountryCode(sourceCountry.getCountryCode());
62                 targetCountry.setCountryExternalDialPrefix(sourceCountry.getCountryExternalDialPrefix());
63                 targetCountry.setCountryI18nKey(sourceCountry.getCountryI18nKey());
64                 targetCountry.setCountryId(sourceCountry.getCountryId());
65                 targetCountry.setCountryIsLocalPrefixRequired(sourceCountry.getCountryIsLocalPrefixRequired());
66                 targetCountry.setCountryPhoneCode(sourceCountry.getCountryPhoneCode());
67         }
68
69         /**
70          * Utility classes should not have instances
71          */
72         private Countries () {
73         }
74
75 }