]> git.mxchange.org Git - jcountry-core.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Tue, 13 Mar 2018 00:07:59 +0000 (01:07 +0100)
committerRoland Häder <roland@mxchange.org>
Tue, 13 Mar 2018 00:07:59 +0000 (01:07 +0100)
- implemented unfinished Comparable
- moved copyAll() method to Countries.copyCountry() as such "complex" methods
  should not exist in entities

Signed-off-by: Roland Häder <roland@mxchange.org>
src/org/mxchange/jcountry/events/added/AdminAddedCountryEvent.java
src/org/mxchange/jcountry/events/added/ObservableAdminAddedCountryEvent.java
src/org/mxchange/jcountry/exceptions/CountryAlreadyAddedException.java
src/org/mxchange/jcountry/exceptions/CountryNotFoundException.java
src/org/mxchange/jcountry/model/data/Countries.java [new file with mode: 0644]
src/org/mxchange/jcountry/model/data/Country.java
src/org/mxchange/jcountry/model/data/CountryData.java

index 899a5b7e78ac87b98972a20568704cf74e2fb15b..0f05afc96775747b571e866af3b354d4bc37a5ee 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016, 2017 Free Software Foundation
+ * Copyright (C) 2016 - 2018 Free Software Foundation
  *
  * 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
index e356a0912ac21063e5764d8230445d631fd4e026..953ea865f3d2b5ff607111e1e7e95f049ac7c1cf 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016, 2017 Free Software Foundation
+ * Copyright (C) 2016 - 2018 Free Software Foundation
  *
  * 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
index b27ad0d5638d85ba2f635620ac3eb9412ebd3d3a..ee2db1ef1544f7ba097426bd4c7fd612b910883d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016, 2017 Free Software Foundation
+ * Copyright (C) 2016 - 2018 Free Software Foundation
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
index e2808edab387efbb1ab1fd7d3760d0a4daad8d1d..5e106641fbd28bdb80a8f530ee11df404d7a748e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016, 2017 Free Software Foundation
+ * Copyright (C) 2016 - 2018 Free Software Foundation
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
diff --git a/src/org/mxchange/jcountry/model/data/Countries.java b/src/org/mxchange/jcountry/model/data/Countries.java
new file mode 100644 (file)
index 0000000..8fd5d8e
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2018 Roland Häder<roland@mxchange.org>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jcountry.model.data;
+
+import java.io.Serializable;
+import java.util.Objects;
+
+/**
+ * An utilities class for countries
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public class Countries implements Serializable {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 286_956_737_410L;
+
+       /**
+        * Copies data from sourceCountry to targetCountry.
+        * <p>
+        * @param sourceCountry Source Country instance to copy data from
+        * @param targetCountry Target Country instance to copy data to
+        */
+       public static void copyCountry (final Country sourceCountry, final Country targetCountry) {
+               // Parameters should not be null
+               if (null == sourceCountry) {
+                       // Throw NPE
+                       throw new NullPointerException("sourceCountry is null"); //NOI18N
+               } else if (null == targetCountry) {
+                       // Throw NPE
+                       throw new NullPointerException("targetCountry is null"); //NOI18N
+               } else if (Objects.equals(sourceCountry, targetCountry)) {
+                       // Should never be equal
+               }
+
+               // Copy all fields
+               targetCountry.setCountryAbroadDialPrefix(sourceCountry.getCountryAbroadDialPrefix());
+               targetCountry.setCountryCode(sourceCountry.getCountryCode());
+               targetCountry.setCountryEntryCreated(sourceCountry.getCountryEntryCreated());
+               targetCountry.setCountryExternalDialPrefix(sourceCountry.getCountryExternalDialPrefix());
+               targetCountry.setCountryI18nKey(sourceCountry.getCountryI18nKey());
+               targetCountry.setCountryId(sourceCountry.getCountryId());
+               targetCountry.setCountryIsLocalPrefixRequired(sourceCountry.getCountryIsLocalPrefixRequired());
+               targetCountry.setCountryPhoneCode(sourceCountry.getCountryPhoneCode());
+       }
+
+       /**
+        * Utility classes should not have instances
+        */
+       private Countries () {
+       }
+
+}
index 96b157560b215ef92492f106ed43ece75727ef5b..d595527df199b6f0eef413f6a7fd2fe022c882c8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016, 2017 Free Software Foundation
+ * Copyright (C) 2016 - 2018 Free Software Foundation
  *
  * 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
@@ -24,14 +24,7 @@ import java.util.Date;
  * <p>
  * @author Roland Häder<roland@mxchange.org>
  */
-public interface Country extends Serializable {
-
-       /**
-        * Copies all entries from sounce country to this
-        * <p>
-        * @param sourceCountry Source country to copy from
-        */
-       void copyAll (final Country sourceCountry);
+public interface Country extends Comparable<Country>, Serializable {
 
        /**
         * Getter for country code (example: 49 for Germany, 63 for Philippines)
@@ -128,7 +121,7 @@ public interface Country extends Serializable {
         * Setter for whether the local dial prefix is required for local calls
         * <p>
         * @param countryIsLocalPrefixRequired Whether the local dial prefix is
-        * required
+        *                                     required
         */
        void setCountryIsLocalPrefixRequired (final Boolean countryIsLocalPrefixRequired);
 
index cb5763d6aff61c6bcda95700d573564a3a33d52a..f851abb2cdbd8dff6b2a25f9afe7b66a7d458c0a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016, 2017 Free Software Foundation
+ * Copyright (C) 2016 - 2018 Free Software Foundation
  *
  * 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
@@ -117,22 +117,8 @@ public class CountryData implements Country {
        private Short countryPhoneCode;
 
        @Override
-       public void copyAll (final Country sourceCountry) {
-               // Parameter should not be null
-               if (null == sourceCountry) {
-                       // Throw NPE
-                       throw new NullPointerException("sourceCountry is null"); //NOI18N
-               }
-
-               // Copy all
-               this.setCountryAbroadDialPrefix(sourceCountry.getCountryAbroadDialPrefix());
-               this.setCountryCode(sourceCountry.getCountryCode());
-               this.setCountryEntryCreated(sourceCountry.getCountryEntryCreated());
-               this.setCountryExternalDialPrefix(sourceCountry.getCountryExternalDialPrefix());
-               this.setCountryI18nKey(sourceCountry.getCountryI18nKey());
-               this.setCountryId(sourceCountry.getCountryId());
-               this.setCountryIsLocalPrefixRequired(sourceCountry.getCountryIsLocalPrefixRequired());
-               this.setCountryPhoneCode(sourceCountry.getCountryPhoneCode());
+       public int compareTo (final Country country) {
+               throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
 
        @Override
@@ -145,13 +131,20 @@ public class CountryData implements Country {
                        return false;
                }
 
-               final Country other = (Country) object;
+               // @todo Maybe a bit unsafe cast?
+               final Country country = (Country) object;
 
-               if (!Objects.equals(this.getCountryId(), other.getCountryId())) {
+               if (!Objects.equals(this.getCountryId(), country.getCountryId())) {
+                       return false;
+               } else if (!Objects.equals(this.getCountryCode(), country.getCountryCode())) {
+                       return false;
+               } else if (!Objects.equals(this.getCountryAbroadDialPrefix(), country.getCountryAbroadDialPrefix())) {
+                       return false;
+               } else if (!Objects.equals(this.getCountryExternalDialPrefix(), country.getCountryExternalDialPrefix())) {
                        return false;
-               } else if (!Objects.equals(this.getCountryCode(), other.getCountryCode())) {
+               } else if (!Objects.equals(this.getCountryPhoneCode(), country.getCountryPhoneCode())) {
                        return false;
-               } else if (!Objects.equals(this.getCountryI18nKey(), other.getCountryI18nKey())) {
+               } else if (!Objects.equals(this.getCountryI18nKey(), country.getCountryI18nKey())) {
                        return false;
                }
 
@@ -246,6 +239,9 @@ public class CountryData implements Country {
 
                hash = 41 * hash + Objects.hashCode(this.getCountryId());
                hash = 41 * hash + Objects.hashCode(this.getCountryCode());
+               hash = 41 * hash + Objects.hashCode(this.getCountryAbroadDialPrefix());
+               hash = 41 * hash + Objects.hashCode(this.getCountryExternalDialPrefix());
+               hash = 41 * hash + Objects.hashCode(this.getCountryPhoneCode());
                hash = 41 * hash + Objects.hashCode(this.getCountryI18nKey());
 
                return hash;