/*
- * Copyright (C) 2016 - 2020 Free Software Foundation
+ * Copyright (C) 2016 - 2024 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
*/
package org.mxchange.jphone.model.phonenumbers.landline;
+import java.text.MessageFormat;
import java.util.Date;
import java.util.Objects;
import javax.persistence.Basic;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
+import org.mxchange.jcoreutils.comparable.ComparableUtils;
import org.mxchange.jcountry.model.data.Country;
import org.mxchange.jcountry.model.data.CountryData;
@Table (name = "landline_numbers")
@NamedQueries (
{
- @NamedQuery (name = "AllLandLineNumbers", query = "SELECT p FROM landline_numbers AS p ORDER BY p.phoneId ASC"),
- @NamedQuery (name = "SearchLandLineNumberId", query = "SELECT p FROM landline_numbers AS p WHERE p.phoneId = :landLineNumberId")
+ @NamedQuery (name = "AllLandLineNumbers", query = "SELECT p FROM landline_numbers AS p ORDER BY p.phoneId ASC")
}
)
@SuppressWarnings ("PersistenceUnitPresent")
* Timestamp when this entry has been created
*/
@Temporal (TemporalType.TIMESTAMP)
- @Column (name = "landline_entry_updated", updatable = false)
+ @Column (name = "landline_entry_updated", insertable = false)
private Date phoneEntryUpdated;
/**
/**
* Constructor with country instance, area code and number
* <p>
- * @param phoneCountry Country instance
- * @param phoneAreaCode Phone area code
- * @param phoneNumber Phone number
+ * @param landLineCountry An instance of a Country class
+ * @param landLineAreaCode Land-line area code
+ * @param landLineNumber Land-line number
*/
- public LandLineNumber (final Country phoneCountry, final Integer phoneAreaCode, final Long phoneNumber) {
- // Call default constructor
+ public LandLineNumber (final Country landLineCountry, final Integer landLineAreaCode, final Long landLineNumber) {
+ // Invoke default constructor
this();
+ // Are all parameter set?
+ if (null == landLineAreaCode) {
+ // Throw NPE
+ throw new NullPointerException("landLineAreaCode is null"); //NOI18N
+ } else if (landLineAreaCode < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("landLineAreaCode={0} is not valid.", landLineAreaCode)); //NOI18N
+ } else if (null == landLineCountry) {
+ // Throw NPE
+ throw new NullPointerException("landLineCountry is null"); //NOI18N
+ } else if (null == landLineCountry.getCountryId()) {
+ // Throw NPE again
+ throw new NullPointerException("landLineCountry.countryId is null"); //NOI18N
+ } else if (landLineCountry.getCountryId() < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("landLineCountry.countryId={0} is not valid", landLineCountry.getCountryId())); //NOI18N
+ } else if (null == landLineNumber) {
+ // Throw NPE
+ throw new NullPointerException("landLineNumber is null"); //NOI18N
+ } else if (landLineNumber < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("landLineNumber={0} is not valid.", landLineNumber)); //NOI18N
+ }
+
// Set all values
- this.phoneCountry = phoneCountry;
- this.phoneAreaCode = phoneAreaCode;
- this.phoneNumber = phoneNumber;
+ this.phoneCountry = landLineCountry;
+ this.phoneAreaCode = landLineAreaCode;
+ this.phoneNumber = landLineNumber;
+ }
+
+ @Override
+ public int compareTo (final DialableLandLineNumber landLineNumber) {
+ // Is the parameter given?
+ if (null == landLineNumber) {
+ // Throw NPE
+ throw new NullPointerException("Parameter 'landLineNumber' is null"); //NOI18N
+ } else if (Objects.equals(this, landLineNumber)) {
+ // Same object
+ return 0;
+ }
+
+ // Init comparisons
+ final int[] comparators = {
+ // First country
+ this.getPhoneCountry().compareTo(landLineNumber.getPhoneCountry()),
+ // Next area code
+ this.getPhoneAreaCode().compareTo(landLineNumber.getPhoneAreaCode()),
+ // Last number
+ this.getPhoneNumber().compareTo(landLineNumber.getPhoneNumber())
+ };
+
+ // Check all values
+ final int comparison = ComparableUtils.checkAll(comparators);
+
+ // Return value
+ return comparison;
}
@Override
return false;
}
- final DialableLandLineNumber other = (DialableLandLineNumber) object;
+ final DialableLandLineNumber landLineNumber = (DialableLandLineNumber) object;
- if (!Objects.equals(this.getPhoneId(), other.getPhoneId())) {
+ if (!Objects.equals(this.getPhoneId(), landLineNumber.getPhoneId())) {
return false;
- } else if (!Objects.equals(this.getPhoneNumber(), other.getPhoneNumber())) {
+ } else if (!Objects.equals(this.getPhoneNumber(), landLineNumber.getPhoneNumber())) {
return false;
- } else if (!Objects.equals(this.getPhoneAreaCode(), other.getPhoneAreaCode())) {
+ } else if (!Objects.equals(this.getPhoneAreaCode(), landLineNumber.getPhoneAreaCode())) {
return false;
- } else if (!Objects.equals(this.getPhoneCountry(), other.getPhoneCountry())) {
+ } else if (!Objects.equals(this.getPhoneCountry(), landLineNumber.getPhoneCountry())) {
return false;
}