From: Roland Häder Date: Sun, 10 Sep 2017 14:36:02 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=2d7d43e1205af5f93372afb1ff38ee5a08e6988b;p=jcountry-core.git Continued: - moved model-related classes (entities, of course) to 'model' package Signed-off-by: Roland Häder --- diff --git a/src/org/mxchange/jcountry/data/Country.java b/src/org/mxchange/jcountry/data/Country.java deleted file mode 100644 index 20ead58..0000000 --- a/src/org/mxchange/jcountry/data/Country.java +++ /dev/null @@ -1,155 +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.data; - -import java.io.Serializable; -import java.util.Calendar; - -/** - * A POJI for country data such as dial prefixes - *

- * @author Roland Häder - */ -public interface Country extends Serializable { - - /** - * Copies all entries from sounce country to this - *

- * @param sourceCountry Source country to copy from - */ - void copyAll (final Country sourceCountry); - - /** - * Getter for country code (example: 49 for Germany, 63 for Philippines) - *

- * @return Dial number without prefix - */ - Short getCountryPhoneCode (); - - /** - * Setter for country code (example: 49 for Germany, 63 for Philippines) - *

- * @param countryPhoneCode Country code - */ - void setCountryPhoneCode (final Short countryPhoneCode); - - /** - * Getter for id number - *

- * @return Id number - */ - Long getCountryId (); - - /** - * Setter for id number - *

- * @param countryId Id number - */ - void setCountryId (final Long countryId); - - /** - * Getter for 2-characters country code - *

- * @return Country code - */ - String getCountryCode (); - - /** - * Setter for 2-characters country code - *

- * @param countryCode Country code - */ - void setCountryCode (final String countryCode); - - /** - * Getter for local dial prefix - *

- * @return Local dial prefix - */ - String getCountryExternalDialPrefix (); - - /** - * Setter for local dial prefix - *

- * @param countryExternalDialPrefix Local dial prefix - */ - void setCountryExternalDialPrefix (final String countryExternalDialPrefix); - - /** - * Getter for abroad dial prefix - *

- * @return Abroad dial prefix - */ - String getCountryAbroadDialPrefix (); - - /** - * Setter for abroad dial prefix - *

- * @param countryAbroadDialPrefix Abroad dial prefix - */ - void setCountryAbroadDialPrefix (final String countryAbroadDialPrefix); - - /** - * Getter for i18n key for country name - *

- * @return i18n key for country name - */ - String getCountryI18nKey (); - - /** - * Setter for i18n key for country name - *

- * @param countryI18nKey i18n key for country name - */ - void setCountryI18nKey (final String countryI18nKey); - - /** - * Getter for whether the local dial prefix is required for local calls - *

- * @return Whether the local dial prefix is required - */ - Boolean getCountryIsLocalPrefixRequired (); - - /** - * Setter for whether the local dial prefix is required for local calls - *

- * @param countryIsLocalPrefixRequired Whether the local dial prefix is - * required - */ - void setCountryIsLocalPrefixRequired (final Boolean countryIsLocalPrefixRequired); - - /** - * Getter for country entry created timestamp - *

- * @return Country entry created timestamp - */ - Calendar getCountryEntryCreated (); - - /** - * Setter for country entry created timestamp - *

- * @param countryEntryCreated Country entry created timestamp - */ - void setCountryEntryCreated (final Calendar countryEntryCreated); - - @Override - boolean equals (final Object object); - - @Override - int hashCode (); - -} diff --git a/src/org/mxchange/jcountry/data/CountryData.java b/src/org/mxchange/jcountry/data/CountryData.java deleted file mode 100644 index 37dbb11..0000000 --- a/src/org/mxchange/jcountry/data/CountryData.java +++ /dev/null @@ -1,254 +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.data; - -import java.util.Calendar; -import java.util.Objects; -import javax.persistence.Basic; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; -import javax.persistence.Transient; - -/** - * A POJO for country data - *

- * @author Roland Häder - */ -@Entity (name = "country_data") -@Table (name = "country_data") -@NamedQueries ( - { - @NamedQuery (name = "AllCountries", query = "SELECT c FROM country_data AS c ORDER BY c.countryId ASC"), - @NamedQuery (name = "SearchCountryByCodeI18nKey", query = "SELECT c FROM country_data AS c WHERE c.countryCode = :code OR c.countryI18nKey = :key") - } -) -@SuppressWarnings ("PersistenceUnitPresent") -public class CountryData implements Country { - - /** - * Serial number - */ - @Transient - private static final long serialVersionUID = 14_853_982_718_509L; - - /** - * Dial prefix to be dialed before an abroad number is being dialed. In - * Germany this is "+" or 00. - */ - @Basic (optional = false) - @Column (name = "country_abroad_dial_prefix", length = 10) - private String countryAbroadDialPrefix; - - /** - * 2-characters country code, all upper-case (example: DE for Germany, PH - * for Philippines) - */ - @Basic (optional = false) - @Column (name = "country_code", length = 2, nullable = false, unique = true) - private String countryCode; - - /** - * TImestamp when this entry has been created - */ - @Basic (optional = false) - @Temporal (TemporalType.TIMESTAMP) - @Column (name = "country_entry_created", nullable = false, updatable = false) - private Calendar countryEntryCreated; - - /** - * Dial prefix to be dialed before the area/city number is dialed. In - * Germany, this is 0. - */ - @Basic (optional = false) - @Column (name = "country_external_dial_prefix", length = 10) - private String countryExternalDialPrefix; - - /** - * Key to i18n key (to have translated country names) - */ - @Basic (optional = false) - @Column (name = "country_i18n_key", length = 100, nullable = false) - private String countryI18nKey; - - /** - * Id number - */ - @Id - @GeneratedValue (strategy = GenerationType.IDENTITY) - @Column (name = "country_id", nullable = false, updatable = false) - private Long countryId; - - /** - * Is the local dialing prefix required or optional for calling numbers in - * same area? - */ - @Basic (optional = false) - @Column (name = "country_is_local_prefix_required", nullable = false) - private Boolean countryIsLocalPrefixRequired; - - /** - * 2-digit country's phone code (example: 49 for Germany, 63 for - * Philippines) - */ - @Basic (optional = false) - @Column (name = "country_phone_code", length = 2, nullable = false, updatable = false) - 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()); - } - - @Override - public boolean equals (final Object object) { - if (this == object) { - return true; - } else if (null == object) { - return false; - } else if (this.getClass() != object.getClass()) { - return false; - } - - final Country other = (Country) object; - - if (!Objects.equals(this.getCountryId(), other.getCountryId())) { - return false; - } else if (!Objects.equals(this.getCountryCode(), other.getCountryCode())) { - return false; - } else if (!Objects.equals(this.getCountryI18nKey(), other.getCountryI18nKey())) { - return false; - } - - return true; - } - - @Override - public String getCountryAbroadDialPrefix () { - return this.countryAbroadDialPrefix; - } - - @Override - public void setCountryAbroadDialPrefix (final String countryAbroadDialPrefix) { - this.countryAbroadDialPrefix = countryAbroadDialPrefix; - } - - @Override - public String getCountryCode () { - return this.countryCode; - } - - @Override - public void setCountryCode (final String countryCode) { - this.countryCode = countryCode; - } - - @Override - @SuppressWarnings ("ReturnOfDateField") - public Calendar getCountryEntryCreated () { - return this.countryEntryCreated; - } - - @Override - @SuppressWarnings ("AssignmentToDateFieldFromParameter") - public void setCountryEntryCreated (final Calendar countryEntryCreated) { - this.countryEntryCreated = countryEntryCreated; - } - - @Override - public String getCountryExternalDialPrefix () { - return this.countryExternalDialPrefix; - } - - @Override - public void setCountryExternalDialPrefix (final String countryExternalDialPrefix) { - this.countryExternalDialPrefix = countryExternalDialPrefix; - } - - @Override - public String getCountryI18nKey () { - return this.countryI18nKey; - } - - @Override - public void setCountryI18nKey (final String countryI18nKey) { - this.countryI18nKey = countryI18nKey; - } - - @Override - public Long getCountryId () { - return this.countryId; - } - - @Override - public void setCountryId (final Long countryId) { - this.countryId = countryId; - } - - @Override - public Boolean getCountryIsLocalPrefixRequired () { - return this.countryIsLocalPrefixRequired; - } - - @Override - public void setCountryIsLocalPrefixRequired (final Boolean countryIsLocalPrefixRequired) { - this.countryIsLocalPrefixRequired = countryIsLocalPrefixRequired; - } - - @Override - public Short getCountryPhoneCode () { - return this.countryPhoneCode; - } - - @Override - public void setCountryPhoneCode (final Short countryPhoneCode) { - this.countryPhoneCode = countryPhoneCode; - } - - @Override - public int hashCode () { - int hash = 7; - - hash = 41 * hash + Objects.hashCode(this.getCountryId()); - hash = 41 * hash + Objects.hashCode(this.getCountryCode()); - hash = 41 * hash + Objects.hashCode(this.getCountryI18nKey()); - - return hash; - } - -} diff --git a/src/org/mxchange/jcountry/events/AdminAddedCountryEvent.java b/src/org/mxchange/jcountry/events/AdminAddedCountryEvent.java index f79cc29..21c71db 100644 --- a/src/org/mxchange/jcountry/events/AdminAddedCountryEvent.java +++ b/src/org/mxchange/jcountry/events/AdminAddedCountryEvent.java @@ -17,7 +17,7 @@ package org.mxchange.jcountry.events; import java.text.MessageFormat; -import org.mxchange.jcountry.data.Country; +import org.mxchange.jcountry.model.data.Country; /** * An addedCountry triggered when the administrator adds a new country diff --git a/src/org/mxchange/jcountry/events/ObservableAdminAddedCountryEvent.java b/src/org/mxchange/jcountry/events/ObservableAdminAddedCountryEvent.java index 06dff0c..ac8142d 100644 --- a/src/org/mxchange/jcountry/events/ObservableAdminAddedCountryEvent.java +++ b/src/org/mxchange/jcountry/events/ObservableAdminAddedCountryEvent.java @@ -17,7 +17,7 @@ package org.mxchange.jcountry.events; import java.io.Serializable; -import org.mxchange.jcountry.data.Country; +import org.mxchange.jcountry.model.data.Country; /** * An interface for a country being added by the administrator. diff --git a/src/org/mxchange/jcountry/exceptions/CountryAlreadyAddedException.java b/src/org/mxchange/jcountry/exceptions/CountryAlreadyAddedException.java index 77a6387..435cd69 100644 --- a/src/org/mxchange/jcountry/exceptions/CountryAlreadyAddedException.java +++ b/src/org/mxchange/jcountry/exceptions/CountryAlreadyAddedException.java @@ -17,7 +17,7 @@ package org.mxchange.jcountry.exceptions; import java.text.MessageFormat; -import org.mxchange.jcountry.data.Country; +import org.mxchange.jcountry.model.data.Country; /** * An exception thrown when a country is already registered. This can be easily diff --git a/src/org/mxchange/jcountry/model/data/Country.java b/src/org/mxchange/jcountry/model/data/Country.java new file mode 100644 index 0000000..ce47c79 --- /dev/null +++ b/src/org/mxchange/jcountry/model/data/Country.java @@ -0,0 +1,155 @@ +/* + * 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.model.data; + +import java.io.Serializable; +import java.util.Calendar; + +/** + * A POJI for country data such as dial prefixes + *

+ * @author Roland Häder + */ +public interface Country extends Serializable { + + /** + * Copies all entries from sounce country to this + *

+ * @param sourceCountry Source country to copy from + */ + void copyAll (final Country sourceCountry); + + /** + * Getter for country code (example: 49 for Germany, 63 for Philippines) + *

+ * @return Dial number without prefix + */ + Short getCountryPhoneCode (); + + /** + * Setter for country code (example: 49 for Germany, 63 for Philippines) + *

+ * @param countryPhoneCode Country code + */ + void setCountryPhoneCode (final Short countryPhoneCode); + + /** + * Getter for id number + *

+ * @return Id number + */ + Long getCountryId (); + + /** + * Setter for id number + *

+ * @param countryId Id number + */ + void setCountryId (final Long countryId); + + /** + * Getter for 2-characters country code + *

+ * @return Country code + */ + String getCountryCode (); + + /** + * Setter for 2-characters country code + *

+ * @param countryCode Country code + */ + void setCountryCode (final String countryCode); + + /** + * Getter for local dial prefix + *

+ * @return Local dial prefix + */ + String getCountryExternalDialPrefix (); + + /** + * Setter for local dial prefix + *

+ * @param countryExternalDialPrefix Local dial prefix + */ + void setCountryExternalDialPrefix (final String countryExternalDialPrefix); + + /** + * Getter for abroad dial prefix + *

+ * @return Abroad dial prefix + */ + String getCountryAbroadDialPrefix (); + + /** + * Setter for abroad dial prefix + *

+ * @param countryAbroadDialPrefix Abroad dial prefix + */ + void setCountryAbroadDialPrefix (final String countryAbroadDialPrefix); + + /** + * Getter for i18n key for country name + *

+ * @return i18n key for country name + */ + String getCountryI18nKey (); + + /** + * Setter for i18n key for country name + *

+ * @param countryI18nKey i18n key for country name + */ + void setCountryI18nKey (final String countryI18nKey); + + /** + * Getter for whether the local dial prefix is required for local calls + *

+ * @return Whether the local dial prefix is required + */ + Boolean getCountryIsLocalPrefixRequired (); + + /** + * Setter for whether the local dial prefix is required for local calls + *

+ * @param countryIsLocalPrefixRequired Whether the local dial prefix is + * required + */ + void setCountryIsLocalPrefixRequired (final Boolean countryIsLocalPrefixRequired); + + /** + * Getter for country entry created timestamp + *

+ * @return Country entry created timestamp + */ + Calendar getCountryEntryCreated (); + + /** + * Setter for country entry created timestamp + *

+ * @param countryEntryCreated Country entry created timestamp + */ + void setCountryEntryCreated (final Calendar countryEntryCreated); + + @Override + boolean equals (final Object object); + + @Override + int hashCode (); + +} diff --git a/src/org/mxchange/jcountry/model/data/CountryData.java b/src/org/mxchange/jcountry/model/data/CountryData.java new file mode 100644 index 0000000..668f158 --- /dev/null +++ b/src/org/mxchange/jcountry/model/data/CountryData.java @@ -0,0 +1,254 @@ +/* + * 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.model.data; + +import java.util.Calendar; +import java.util.Objects; +import javax.persistence.Basic; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import javax.persistence.Transient; + +/** + * A POJO for country data + *

+ * @author Roland Häder + */ +@Entity (name = "country_data") +@Table (name = "country_data") +@NamedQueries ( + { + @NamedQuery (name = "AllCountries", query = "SELECT c FROM country_data AS c ORDER BY c.countryId ASC"), + @NamedQuery (name = "SearchCountryByCodeI18nKey", query = "SELECT c FROM country_data AS c WHERE c.countryCode = :code OR c.countryI18nKey = :key") + } +) +@SuppressWarnings ("PersistenceUnitPresent") +public class CountryData implements Country { + + /** + * Serial number + */ + @Transient + private static final long serialVersionUID = 14_853_982_718_509L; + + /** + * Dial prefix to be dialed before an abroad number is being dialed. In + * Germany this is "+" or 00. + */ + @Basic (optional = false) + @Column (name = "country_abroad_dial_prefix", length = 10) + private String countryAbroadDialPrefix; + + /** + * 2-characters country code, all upper-case (example: DE for Germany, PH + * for Philippines) + */ + @Basic (optional = false) + @Column (name = "country_code", length = 2, nullable = false, unique = true) + private String countryCode; + + /** + * TImestamp when this entry has been created + */ + @Basic (optional = false) + @Temporal (TemporalType.TIMESTAMP) + @Column (name = "country_entry_created", nullable = false, updatable = false) + private Calendar countryEntryCreated; + + /** + * Dial prefix to be dialed before the area/city number is dialed. In + * Germany, this is 0. + */ + @Basic (optional = false) + @Column (name = "country_external_dial_prefix", length = 10) + private String countryExternalDialPrefix; + + /** + * Key to i18n key (to have translated country names) + */ + @Basic (optional = false) + @Column (name = "country_i18n_key", length = 100, nullable = false) + private String countryI18nKey; + + /** + * Id number + */ + @Id + @GeneratedValue (strategy = GenerationType.IDENTITY) + @Column (name = "country_id", nullable = false, updatable = false) + private Long countryId; + + /** + * Is the local dialing prefix required or optional for calling numbers in + * same area? + */ + @Basic (optional = false) + @Column (name = "country_is_local_prefix_required", nullable = false) + private Boolean countryIsLocalPrefixRequired; + + /** + * 2-digit country's phone code (example: 49 for Germany, 63 for + * Philippines) + */ + @Basic (optional = false) + @Column (name = "country_phone_code", length = 2, nullable = false, updatable = false) + 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()); + } + + @Override + public boolean equals (final Object object) { + if (this == object) { + return true; + } else if (null == object) { + return false; + } else if (this.getClass() != object.getClass()) { + return false; + } + + final Country other = (Country) object; + + if (!Objects.equals(this.getCountryId(), other.getCountryId())) { + return false; + } else if (!Objects.equals(this.getCountryCode(), other.getCountryCode())) { + return false; + } else if (!Objects.equals(this.getCountryI18nKey(), other.getCountryI18nKey())) { + return false; + } + + return true; + } + + @Override + public String getCountryAbroadDialPrefix () { + return this.countryAbroadDialPrefix; + } + + @Override + public void setCountryAbroadDialPrefix (final String countryAbroadDialPrefix) { + this.countryAbroadDialPrefix = countryAbroadDialPrefix; + } + + @Override + public String getCountryCode () { + return this.countryCode; + } + + @Override + public void setCountryCode (final String countryCode) { + this.countryCode = countryCode; + } + + @Override + @SuppressWarnings ("ReturnOfDateField") + public Calendar getCountryEntryCreated () { + return this.countryEntryCreated; + } + + @Override + @SuppressWarnings ("AssignmentToDateFieldFromParameter") + public void setCountryEntryCreated (final Calendar countryEntryCreated) { + this.countryEntryCreated = countryEntryCreated; + } + + @Override + public String getCountryExternalDialPrefix () { + return this.countryExternalDialPrefix; + } + + @Override + public void setCountryExternalDialPrefix (final String countryExternalDialPrefix) { + this.countryExternalDialPrefix = countryExternalDialPrefix; + } + + @Override + public String getCountryI18nKey () { + return this.countryI18nKey; + } + + @Override + public void setCountryI18nKey (final String countryI18nKey) { + this.countryI18nKey = countryI18nKey; + } + + @Override + public Long getCountryId () { + return this.countryId; + } + + @Override + public void setCountryId (final Long countryId) { + this.countryId = countryId; + } + + @Override + public Boolean getCountryIsLocalPrefixRequired () { + return this.countryIsLocalPrefixRequired; + } + + @Override + public void setCountryIsLocalPrefixRequired (final Boolean countryIsLocalPrefixRequired) { + this.countryIsLocalPrefixRequired = countryIsLocalPrefixRequired; + } + + @Override + public Short getCountryPhoneCode () { + return this.countryPhoneCode; + } + + @Override + public void setCountryPhoneCode (final Short countryPhoneCode) { + this.countryPhoneCode = countryPhoneCode; + } + + @Override + public int hashCode () { + int hash = 7; + + hash = 41 * hash + Objects.hashCode(this.getCountryId()); + hash = 41 * hash + Objects.hashCode(this.getCountryCode()); + hash = 41 * hash + Objects.hashCode(this.getCountryI18nKey()); + + return hash; + } + +}