]> git.mxchange.org Git - jphone-core.git/blob - src/org/mxchange/jphone/model/utils/MobileProviderUtils.java
37b789125f8ea4a32b5df0d51b3dea085b5ece8e
[jphone-core.git] / src / org / mxchange / jphone / model / utils / MobileProviderUtils.java
1 /*
2  * Copyright (C) 2017 - 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 targetMobileProvider program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 package org.mxchange.jphone.model.utils;
18
19 import java.io.Serializable;
20 import java.util.Objects;
21 import org.mxchange.jcountry.model.utils.CountryUtils;
22 import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider;
23
24 /**
25  * An utilities class for mobile providers
26  * <p>
27  * @author Roland Häder<roland@mxchange.org>
28  */
29 public class MobileProviderUtils implements Serializable {
30
31         /**
32          * Serial number
33          */
34         private static final long serialVersionUID = 15_468_608_721_651L;
35
36         /**
37          * Compares two mobile provider instances with each other
38          * <p>
39          * @param mobileProvider1 First instance of a MobileProvider class
40          * @param mobileProvider2 Second instance of a MobileProvider class
41          * <p>
42          * @return Comparison value
43          */
44         public static int compare (final MobileProvider mobileProvider1, final MobileProvider mobileProvider2) {
45                 // Check equality, then at least first must be given
46                 if (Objects.equals(mobileProvider1, mobileProvider2)) {
47                         // Both are same
48                         return 0;
49                 } else if (null == mobileProvider1) {
50                         // First is null
51                         return -1;
52                 } else if (null == mobileProvider2) {
53                         // Second is null
54                         return 1;
55                 }
56
57                 // Invoke compareTo() method
58                 return mobileProvider1.compareTo(mobileProvider2);
59         }
60
61         /**
62          * Copies all values from source mobile provider to this
63          * <p>
64          * @param sourceMobileProvider Source mobile provider
65          * @param targetMobileProvider Target mobile provider
66          */
67         public static void copyMobileProviderData (final MobileProvider sourceMobileProvider, final MobileProvider targetMobileProvider) {
68                 // Parameter should not be null
69                 if (null == sourceMobileProvider) {
70                         // Throw NPE
71                         throw new NullPointerException("sourceMobileProvider is null"); //NOI18N
72                 } else if (null == targetMobileProvider) {
73                         // Throw NPE
74                         throw new NullPointerException("targetMobileProvider is null"); //NOI18N
75                 } else if (Objects.equals(sourceMobileProvider, targetMobileProvider)) {
76                         // Is same mobile provider
77                         throw new IllegalArgumentException("Source and target mobile provider are the same."); //NOI18N
78                 }
79
80                 // Copy all values
81                 CountryUtils.copyCountryData(sourceMobileProvider.getProviderCountry(), targetMobileProvider.getProviderCountry());
82                 targetMobileProvider.setProviderDialPrefix(sourceMobileProvider.getProviderDialPrefix());
83                 targetMobileProvider.setProviderId(sourceMobileProvider.getProviderId());
84                 targetMobileProvider.setProviderMailPattern(sourceMobileProvider.getProviderMailPattern());
85                 targetMobileProvider.setProviderName(sourceMobileProvider.getProviderName());
86         }
87
88         /**
89          * Private constructor, because there is no need for an instance of
90          * targetMobileProvider class.
91          */
92         private MobileProviderUtils () {
93         }
94
95 }