From a3bd56840daf2b31d26e7aa0fdd2cf31cb79e515 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 1 Apr 2020 18:55:52 +0200 Subject: [PATCH] Continued: - added countryEntryUpdated entity property - added default contructor and one with all required entity properties MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../mxchange/jcountry/model/data/Country.java | 14 ++++ .../jcountry/model/data/CountryData.java | 80 +++++++++++++++++++ 2 files changed, 94 insertions(+) diff --git a/src/org/mxchange/jcountry/model/data/Country.java b/src/org/mxchange/jcountry/model/data/Country.java index 3e09692..5dd02a6 100644 --- a/src/org/mxchange/jcountry/model/data/Country.java +++ b/src/org/mxchange/jcountry/model/data/Country.java @@ -139,6 +139,20 @@ public interface Country extends Comparable, Serializable { */ void setCountryEntryCreated (final Date countryEntryCreated); + /** + * Getter for country entry updated timestamp + *

+ * @return Country entry updated timestamp + */ + Date getCountryEntryUpdated (); + + /** + * Setter for country entry updated timestamp + *

+ * @param countryEntryUpdated Country entry updated timestamp + */ + void setCountryEntryUpdated (final Date countryEntryUpdated); + @Override boolean equals (final Object object); diff --git a/src/org/mxchange/jcountry/model/data/CountryData.java b/src/org/mxchange/jcountry/model/data/CountryData.java index 7e34d0a..bd0b8ed 100644 --- a/src/org/mxchange/jcountry/model/data/CountryData.java +++ b/src/org/mxchange/jcountry/model/data/CountryData.java @@ -16,6 +16,7 @@ */ package org.mxchange.jcountry.model.data; +import java.text.MessageFormat; import java.util.Date; import java.util.Objects; import javax.persistence.Basic; @@ -78,6 +79,13 @@ public class CountryData implements Country { @Column (name = "country_entry_created", nullable = false, updatable = false) private Date countryEntryCreated; + /** + * TImestamp when this entry has been updated + */ + @Temporal (TemporalType.TIMESTAMP) + @Column (name = "country_entry_updated", insertable = false) + private Date countryEntryUpdated; + /** * Dial prefix to be dialed before the area/city number is dialed. In * Germany, this is 0. @@ -117,6 +125,66 @@ public class CountryData implements Country { @Column (name = "country_phone_code", length = 2, nullable = false, updatable = false) private Short countryPhoneCode; + /** + * Default constructor, required for the JPA + */ + public CountryData () { + } + + /** + * Constructor with all required fields + *

+ * @param countryAbroadDialPrefix Abroad dial prefix + * @param countryCode 2-digit country code + * @param countryExternalDialPrefix External dial prefix + * @param countryI18nKey I18n key + * @param countryIsLocalPrefixRequired Whether local prefix is required to + * dial + * @param countryPhoneCode Phone code for country + */ + public CountryData (final String countryAbroadDialPrefix, final String countryCode, final String countryExternalDialPrefix, final String countryI18nKey, final Boolean countryIsLocalPrefixRequired, final Short countryPhoneCode) { + // Invoke default constructor first + this(); + + // Are all parameter set? + if (null == countryAbroadDialPrefix) { + // Throw NPE + throw new NullPointerException("countryAbroadDialPrefix is null"); //NOI18N + } else if (countryAbroadDialPrefix.isEmpty()) { + // Throw IAE + throw new IllegalArgumentException("countryAbroadDialPrefix is empty"); //NOI18N + } else if (null == countryCode) { + // Throw NPE + throw new NullPointerException("countryCode is null"); //NOI18N + } else if (countryCode.isEmpty()) { + // Throw IAE + throw new IllegalArgumentException("countryCode is empty"); //NOI18N + } else if (null == countryI18nKey) { + // Throw NPE + throw new NullPointerException("countryI18nKey is null"); //NOI18N + } else if (countryI18nKey.isEmpty()) { + // Throw IAE + throw new IllegalArgumentException("countryI18nKey is empty"); //NOI18N + } else if (null == countryIsLocalPrefixRequired) { + // Throw NPE + throw new NullPointerException("countryIsLocalPrefixRequired is null"); //NOI18N + } else if (null == countryPhoneCode) { + // Throw NPE + throw new NullPointerException("countryPhoneCode is null"); //NOI18N + } else if (countryPhoneCode < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("countryPhoneCode={0} is not valid, must be at least 1.", countryPhoneCode)); //NOI18N + } + + // Set all fields + this.countryAbroadDialPrefix = countryAbroadDialPrefix; + this.countryCode = countryCode; + this.countryExternalDialPrefix = countryExternalDialPrefix; + this.countryI18nKey = countryI18nKey; + this.countryIsLocalPrefixRequired = countryIsLocalPrefixRequired; + this.countryPhoneCode = countryPhoneCode; + } + @Override public int compareTo (final Country country) { // Check parameter on null-reference and equality to this @@ -207,6 +275,18 @@ public class CountryData implements Country { this.countryEntryCreated = countryEntryCreated; } + @Override + @SuppressWarnings ("ReturnOfDateField") + public Date getCountryEntryUpdated () { + return this.countryEntryUpdated; + } + + @Override + @SuppressWarnings ("AssignmentToDateFieldFromParameter") + public void setCountryEntryUpdated (final Date countryEntryUpdated) { + this.countryEntryUpdated = countryEntryUpdated; + } + @Override public String getCountryExternalDialPrefix () { return this.countryExternalDialPrefix; -- 2.39.5