/*
- * 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
/*
- * 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
/*
- * 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
/*
- * 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
--- /dev/null
+/*
+ * 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 () {
+ }
+
+}
/*
- * 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
* <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)
* 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);
/*
- * 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
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
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;
}
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;