private static final long serialVersionUID = 18_964_581_681_985_598L;
/**
- * Counstructor with fax number
+ * Constructor with fax number
* <p>
* @param faxNumber Fax number
*/
}
/**
- * Counstructor with landLine number
+ * Constructor with landLine number
* <p>
* @param landLineNumber Land-line number
*/
}
/**
- * Counstructor with mobile number
+ * Constructor with mobile number
* <p>
* @param mobileNumber Mobile number
*/
public PhoneNumberAlreadyLinkedException (final DialableMobileNumber mobileNumber) {
// Call super constructor with message
- super(MessageFormat.format("mobileNumber={0} with phoneId={1} cannot be linked, link target has already mobile number linked.", mobileNumber, mobileNumber.getPhoneId())); //NOI18N
+ super(MessageFormat.format("mobileNumber={0} with phoneId={1} cannot be linked, link target has already mobile number linked.", mobileNumber, mobileNumber.getMobileId())); //NOI18N
}
}
private static final long serialVersionUID = 18_964_581_681_985_599L;
/**
- * Counstructor with fax number
+ * Constructor with fax number
* <p>
* @param faxNumber Fax number
*/
}
/**
- * Counstructor with landLine number
+ * Constructor with landLine number
* <p>
* @param landLineNumber Land-line number
*/
}
/**
- * Counstructor with mobile number
+ * Constructor with mobile number
* <p>
* @param mobileNumber Mobile number
*/
public PhoneNumberNotLinkedException (final DialableMobileNumber mobileNumber) {
// Call super constructor with message
- super(MessageFormat.format("mobileNumber={0} with phoneId={1} is not linked.", mobileNumber, mobileNumber.getPhoneId())); //NOI18N
+ super(MessageFormat.format("mobileNumber={0} with phoneId={1} is not linked.", mobileNumber, mobileNumber.getMobileId())); //NOI18N
}
}
* <p>
* @author Roland Häder<roland@mxchange.org>
*/
-public interface DialableFaxNumber extends DialableNumber {
+public interface DialableFaxNumber extends Comparable<DialableFaxNumber>, DialableNumber {
@Override
boolean equals (final Object object);
*/
package org.mxchange.jphone.model.phonenumbers.fax;
+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.Comparables;
import org.mxchange.jcountry.model.data.Country;
import org.mxchange.jcountry.model.data.CountryData;
@Table (name = "fax_numbers")
@NamedQueries (
{
- @NamedQuery (name = "AllFaxNumbers", query = "SELECT f FROM fax_numbers AS f ORDER BY f.phoneId ASC"),
- @NamedQuery (name = "SearchFaxNumberId", query = "SELECT f FROM fax_numbers AS f WHERE f.phoneId = :faxNumberId")
+ @NamedQuery (name = "AllFaxNumbers", query = "SELECT f FROM fax_numbers AS f ORDER BY f.phoneId ASC")
}
)
@SuppressWarnings ("PersistenceUnitPresent")
* Timestamp when this entry has been created
*/
@Temporal (TemporalType.TIMESTAMP)
- @Column (name = "phone_entry_updated", updatable = false)
+ @Column (name = "fax_entry_updated", insertable = false)
private Date phoneEntryUpdated;
/**
/**
* Constructor with country, area code and number
* <p>
- * @param faxCountry Country instance
+ * @param faxCountry Country instance
* @param faxAreaCode Area code (without leading zeros)
- * @param faxNumber Fax number (without area code and leading zero)
+ * @param faxNumber Fax number (without area code and leading zero)
*/
public FaxNumber (final Country faxCountry, final Integer faxAreaCode, final Long faxNumber) {
- // Call default constructor
+ // Invoke default constructor
this();
+ // Are all parameter set?
+ if (null == faxAreaCode) {
+ // Throw NPE
+ throw new NullPointerException("faxAreaCode is null"); //NOI18N
+ } else if (faxAreaCode < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("faxAreaCode={0} is not valid.", faxAreaCode)); //NOI18N
+ } else if (null == faxCountry) {
+ // Throw NPE
+ throw new NullPointerException("faxCountry is null"); //NOI18N
+ } else if (null == faxCountry.getCountryId()) {
+ // Throw NPE again
+ throw new NullPointerException("faxCountry.countryId is null"); //NOI18N
+ } else if (faxCountry.getCountryId() < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("faxCountry.countryId={0} is not valid", faxCountry.getCountryId())); //NOI18N
+ } else if (null == faxNumber) {
+ // Throw NPE
+ throw new NullPointerException("faxNumber is null"); //NOI18N
+ } else if (faxNumber < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("faxNumber={0} is not valid.", faxNumber)); //NOI18N
+ }
+
// Set all values
this.faxCountry = faxCountry;
this.faxAreaCode = faxAreaCode;
this.phoneNumber = faxNumber;
}
+ @Override
+ public int compareTo (final DialableFaxNumber otherNumber) {
+ // Is the parameter given?
+ if (null == otherNumber) {
+ // Throw NPE
+ throw new NullPointerException("otherNumber is null"); //NOI18N
+ } else if (otherNumber.equals(this)) {
+ // Same object
+ return 0;
+ }
+
+ // Init comparisons
+ final int[] comparators = {
+ // First country
+ this.getPhoneCountry().compareTo(otherNumber.getPhoneCountry()),
+ // Next area code
+ this.getPhoneAreaCode().compareTo(otherNumber.getPhoneAreaCode()),
+ // Last number
+ this.getPhoneNumber().compareTo(otherNumber.getPhoneNumber())
+ };
+
+ // Check all values
+ final int comparison = Comparables.checkAll(comparators);
+
+ // Return value
+ return comparison;
+ }
+
@Override
public boolean equals (final Object object) {
if (null == object) {
return false;
}
- final DialableFaxNumber other = (DialableFaxNumber) object;
+ final DialableFaxNumber dialableFaxNumber = (DialableFaxNumber) object;
- if (!Objects.equals(this.getPhoneNumber(), other.getPhoneNumber())) {
+ if (!Objects.equals(this.getPhoneNumber(), dialableFaxNumber.getPhoneNumber())) {
return false;
- } else if (!Objects.equals(this.getPhoneId(), other.getPhoneId())) {
+ } else if (!Objects.equals(this.getPhoneId(), dialableFaxNumber.getPhoneId())) {
return false;
- } else if (!Objects.equals(this.getPhoneAreaCode(), other.getPhoneAreaCode())) {
+ } else if (!Objects.equals(this.getPhoneAreaCode(), dialableFaxNumber.getPhoneAreaCode())) {
return false;
- } else if (!Objects.equals(this.getPhoneCountry(), other.getPhoneCountry())) {
+ } else if (!Objects.equals(this.getPhoneCountry(), dialableFaxNumber.getPhoneCountry())) {
return false;
}
package org.mxchange.jphone.model.phonenumbers.fax;
import java.io.Serializable;
+import java.util.Objects;
/**
* An utilities class for fax numbers
* @param sourceNumber Source number object
* @param targetNumber Target number object
*/
- public static void copyAll (final DialableFaxNumber sourceNumber, final DialableFaxNumber targetNumber) {
+ public static void copyFaxNumber (final DialableFaxNumber sourceNumber, final DialableFaxNumber targetNumber) {
// Validate instance
if (null == sourceNumber) {
// Throw NPE
targetNumber.setPhoneNumber(sourceNumber.getPhoneNumber());
}
+ /**
+ * Checks if both are the same
+ * <p>
+ * @param faxNumber First fax number
+ * @param otherNumber Second fax number
+ * <p>
+ * @return Whether both are the same
+ */
+ public static boolean isSameFaxNumber (final DialableFaxNumber faxNumber, DialableFaxNumber otherNumber) {
+ // Test object equality first
+ if (Objects.equals(faxNumber, otherNumber)) {
+ // Both the same object (null/null or same object)
+ return true;
+ } else if (((null == faxNumber) && (otherNumber instanceof DialableFaxNumber)) || ((null == otherNumber) && (faxNumber instanceof DialableFaxNumber))) {
+ // One is null the other not
+ return false;
+ }
+ // Now compare deeper
+ final boolean sameCountry = Objects.equals(faxNumber.getPhoneCountry(), otherNumber.getPhoneCountry());
+ final boolean sameAreaCode = Objects.equals(faxNumber.getPhoneAreaCode(), otherNumber.getPhoneAreaCode());
+ final boolean sameNumber = Objects.equals(faxNumber.getPhoneNumber(), otherNumber.getPhoneNumber());
+ // All are the same?
+ return sameCountry && sameAreaCode && sameNumber;
+ }
+
/**
* No constructor for utilities classes
*/
* <p>
* @author Roland Häder<roland@mxchange.org>
*/
-public interface DialableLandLineNumber extends DialableNumber {
+public interface DialableLandLineNumber extends Comparable<DialableLandLineNumber>, DialableNumber {
@Override
boolean equals (final Object object);
*/
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.Comparables;
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 otherNumber) {
+ // Is the parameter given?
+ if (null == otherNumber) {
+ // Throw NPE
+ throw new NullPointerException("otherNumber is null"); //NOI18N
+ } else if (otherNumber.equals(this)) {
+ // Same object
+ return 0;
+ }
+
+ // Init comparisons
+ final int[] comparators = {
+ // First country
+ this.getPhoneCountry().compareTo(otherNumber.getPhoneCountry()),
+ // Next area code
+ this.getPhoneAreaCode().compareTo(otherNumber.getPhoneAreaCode()),
+ // Last number
+ this.getPhoneNumber().compareTo(otherNumber.getPhoneNumber())
+ };
+
+ // Check all values
+ final int comparison = Comparables.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;
}
package org.mxchange.jphone.model.phonenumbers.landline;
import java.io.Serializable;
+import java.util.Objects;
/**
* An utilities class for land-line numbers
* @param sourceNumber Source number object
* @param targetNumber Target number object
*/
- public static void copyAll (final DialableLandLineNumber sourceNumber, final DialableLandLineNumber targetNumber) {
+ public static void copyLandLineNumber (final DialableLandLineNumber sourceNumber, final DialableLandLineNumber targetNumber) {
// Validate instance
if (null == sourceNumber) {
// Throw NPE
targetNumber.setPhoneNumber(sourceNumber.getPhoneNumber());
}
+ /**
+ * Checks if both are the same
+ * <p>
+ * @param landLineNumber First land-line number
+ * @param otherNumber Second land-line number
+ * <p>
+ * @return Whether both are the same
+ */
+ public static boolean isSameLandLineNumber (final DialableLandLineNumber landLineNumber, final DialableLandLineNumber otherNumber) {
+ // Test object equality first
+ if (Objects.equals(landLineNumber, otherNumber)) {
+ // Both the same object (null/null or same object)
+ return true;
+ } else if (((null == landLineNumber) && (otherNumber instanceof DialableLandLineNumber)) || ((null == otherNumber) && (landLineNumber instanceof DialableLandLineNumber))) {
+ // One is null the other not
+ return false;
+ }
+ // Now compare deeper
+ final boolean sameCountry = Objects.equals(landLineNumber.getPhoneCountry(), otherNumber.getPhoneCountry());
+ final boolean sameAreaCode = Objects.equals(landLineNumber.getPhoneAreaCode(), otherNumber.getPhoneAreaCode());
+ final boolean sameNumber = Objects.equals(landLineNumber.getPhoneNumber(), otherNumber.getPhoneNumber());
+ // All are the same?
+ return sameCountry && sameAreaCode && sameNumber;
+ }
+
/**
* No constructor for utilities classes
*/
*/
package org.mxchange.jphone.model.phonenumbers.mobile;
+import java.io.Serializable;
+import java.util.Date;
import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider;
-import org.mxchange.jphone.model.phonenumbers.DialableNumber;
/**
* A POJO for dialable mobile numbers with carriers.
* <p>
* @author Roland Häder<roland@mxchange.org>
*/
-public interface DialableMobileNumber extends DialableNumber {
+public interface DialableMobileNumber extends Comparable<DialableMobileNumber>, Serializable {
/**
* Getter for mobile provider
*/
void setMobileProvider (final MobileProvider mobileProvider);
+ /**
+ * Getter for id number
+ * <p>
+ * @return Id number
+ */
+ Long getMobileId ();
+
+ /**
+ * Setter for id number
+ * <p>
+ * @param mobileId Id number
+ */
+ void setMobileId (final Long mobileId);
+
+ /**
+ * Getter for mobile number without prefix
+ * <p>
+ * @return Mobile number without prefix
+ */
+ Long getMobileNumber ();
+
+ /**
+ * Setter for mobile number without prefix
+ * <p>
+ * @param mobileNumber Mobile number without prefix
+ */
+ void setMobileNumber (final Long mobileNumber);
+
+ /**
+ * Getter for timestamp when this entry has been created
+ * <p>
+ * @return Timestamp when this entry has been created
+ */
+ Date getMobileEntryCreated ();
+
+ /**
+ * Setter for timestamp when this entry has been created
+ * <p>
+ * @param mobileEntryCreated Timestamp when this entry has been created
+ */
+ void setMobileEntryCreated (final Date mobileEntryCreated);
+
+ /**
+ * Getter for timestamp when this entry has been updated
+ * <p>
+ * @return Timestamp when this entry has been updated
+ */
+ Date getMobileEntryUpdated ();
+
+ /**
+ * Setter for timestamp when this entry has been updated
+ * <p>
+ * @param mobileEntryUpdated Timestamp when this entry has been updated
+ */
+ void setMobileEntryUpdated (final Date mobileEntryUpdated);
+
@Override
boolean equals (final Object object);
*/
package org.mxchange.jphone.model.phonenumbers.mobile;
+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.jcountry.model.data.Country;
+import org.mxchange.jcoreutils.Comparables;
import org.mxchange.jphone.model.phonenumbers.mobileprovider.CellphoneProvider;
import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider;
/**
- * A POJO for dialable cellphone numbers
+ * A POJO for dialable mobile numbers
* <p>
* @author Roland Häder<roland@mxchange.org>
*/
@Table (name = "mobile_numbers")
@NamedQueries (
{
- @NamedQuery (name = "AllMobileNumbers", query = "SELECT c FROM mobile_numbers AS c ORDER BY c.phoneId ASC"),
- @NamedQuery (name = "SearchMobileNumberId", query = "SELECT c FROM mobile_numbers AS c WHERE c.phoneId = :mobileNumberId")
+ @NamedQuery (name = "AllMobileNumbers", query = "SELECT m FROM mobile_numbers AS m ORDER BY m.mobileId ASC")
}
)
@SuppressWarnings ("PersistenceUnitPresent")
@Transient
private static final long serialVersionUID = 13_859_879_482_106L;
- /**
- * Connection to table "mobile_provider" (for dial prefix and more data)
- */
- @JoinColumn (name = "mobile_provider_id", nullable = false)
- @OneToOne (targetEntity = CellphoneProvider.class, cascade = CascadeType.REFRESH, optional = false)
- private MobileProvider mobileProvider;
-
/**
* Timestamp when this entry has been created
*/
@Basic (optional = false)
@Temporal (TemporalType.TIMESTAMP)
@Column (name = "mobile_entry_created", nullable = false, updatable = false)
- private Date phoneEntryCreated;
+ private Date mobileEntryCreated;
/**
* Timestamp when this entry has been created
*/
@Temporal (TemporalType.TIMESTAMP)
- @Column (name = "mobile_entry_updated", updatable = false)
- private Date phoneEntryUpdated;
+ @Column (name = "mobile_entry_updated", insertable = false)
+ private Date mobileEntryUpdated;
/**
* Id number
@Id
@GeneratedValue (strategy = GenerationType.IDENTITY)
@Column (name = "mobile_id", nullable = false, updatable = false)
- private Long phoneId;
+ private Long mobileId;
/**
* Number without prefix to dial
*/
@Basic (optional = false)
@Column (name = "mobile_number", nullable = false)
- private Long phoneNumber;
+ private Long mobileNumber;
+
+ /**
+ * Connection to table "mobile_provider" (for dial prefix and more data)
+ */
+ @JoinColumn (name = "mobile_provider_id", nullable = false)
+ @OneToOne (targetEntity = CellphoneProvider.class, cascade = CascadeType.REFRESH, optional = false)
+ private MobileProvider mobileProvider;
/**
* Default constructor
}
/**
- * Constructor with cellphone provider and number
+ * Constructor with mobile provider and number
* <p>
- * @param mobileProvider Mobile provider
- * @param mobileNumber Mobile number
+ * @param mobileProvider An instance of a MobileProvider class
+ * @param mobileNumber Mobile calling number
*/
public MobileNumber (final MobileProvider mobileProvider, final Long mobileNumber) {
- // Call default constructor
+ // Invoke default constructor
this();
+ // Are all parameter set?
+ if (null == mobileNumber) {
+ // Throw NPE
+ throw new NullPointerException("mobileNumber is null"); //NOI18N
+ } else if (mobileNumber < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("mobileNumber={0} is not valid.", mobileNumber)); //NOI18N
+ } else if (null == mobileProvider) {
+ // Throw NPE
+ throw new NullPointerException("mobileProvider is null"); //NOI18N
+ } else if (mobileProvider.getProviderId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("mobileProvider.providerId is null"); //NOI18N
+ } else if (mobileProvider.getProviderId() < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("mobileProvider.providerId={0} is not valid", mobileProvider.getProviderId())); //NOI18N
+ }
+
// Set all values
this.mobileProvider = mobileProvider;
- this.phoneNumber = mobileNumber;
+ this.mobileNumber = mobileNumber;
+ }
+
+ @Override
+ public int compareTo (final DialableMobileNumber otherNumber) {
+ // Is the parameter given?
+ if (null == otherNumber) {
+ // Throw NPE
+ throw new NullPointerException("otherNumber is null"); //NOI18N
+ } else if (otherNumber.equals(this)) {
+ // Same object
+ return 0;
+ }
+
+ // Init comparisons
+ final int[] comparators = {
+ // First compare provider
+ this.getMobileProvider().compareTo(otherNumber.getMobileProvider()),
+ // Last number
+ this.getMobileNumber().compareTo(otherNumber.getMobileNumber())
+ };
+
+ // Check all values
+ final int comparison = Comparables.checkAll(comparators);
+
+ // Return value
+ return comparison;
}
@Override
return false;
}
- final DialableMobileNumber other = (DialableMobileNumber) object;
+ final DialableMobileNumber dialableMobileNumber = (DialableMobileNumber) object;
- if (!Objects.equals(this.getPhoneId(), other.getPhoneId())) {
+ if (!Objects.equals(this.getMobileId(), dialableMobileNumber.getMobileId())) {
return false;
- } else if (!Objects.equals(this.getMobileProvider(), other.getMobileProvider())) {
+ } else if (!Objects.equals(this.getMobileProvider(), dialableMobileNumber.getMobileProvider())) {
return false;
- } else if (!Objects.equals(this.getPhoneNumber(), other.getPhoneNumber())) {
+ } else if (!Objects.equals(this.getMobileNumber(), dialableMobileNumber.getMobileNumber())) {
return false;
}
}
@Override
- public MobileProvider getMobileProvider () {
- return this.mobileProvider;
- }
-
- @Override
- public void setMobileProvider (final MobileProvider mobileProvider) {
- this.mobileProvider = mobileProvider;
- }
-
- @Override
- @Deprecated
- public Integer getPhoneAreaCode () {
- throw new UnsupportedOperationException("Mobile numbers don't have area codes. Please fix your code."); //NOI18N
- }
-
- @Override
- @Deprecated
- public void setPhoneAreaCode (final Integer phoneAreaCode) {
- throw new UnsupportedOperationException("Mobile numbers don't have area codes. Please fix your code."); //NOI18N
- }
-
- @Override
- @Deprecated
- public Country getPhoneCountry () {
- throw new UnsupportedOperationException("The country code is provided by MobileProvider."); //To change body of generated methods, choose Tools | Templates.
+ @SuppressWarnings ("ReturnOfDateField")
+ public Date getMobileEntryCreated () {
+ return this.mobileEntryCreated;
}
@Override
- @Deprecated
- public void setPhoneCountry (final Country country) {
- throw new UnsupportedOperationException("The country code is provided by MobileProvider."); //To change body of generated methods, choose Tools | Templates.
+ @SuppressWarnings ("AssignmentToDateFieldFromParameter")
+ public void setMobileEntryCreated (final Date mobileEntryCreated) {
+ this.mobileEntryCreated = mobileEntryCreated;
}
@Override
@SuppressWarnings ("ReturnOfDateField")
- public Date getPhoneEntryCreated () {
- return this.phoneEntryCreated;
+ public Date getMobileEntryUpdated () {
+ return this.mobileEntryUpdated;
}
@Override
@SuppressWarnings ("AssignmentToDateFieldFromParameter")
- public void setPhoneEntryCreated (final Date phoneEntryCreated) {
- this.phoneEntryCreated = phoneEntryCreated;
+ public void setMobileEntryUpdated (final Date mobileEntryUpdated) {
+ this.mobileEntryUpdated = mobileEntryUpdated;
}
@Override
- @SuppressWarnings ("ReturnOfDateField")
- public Date getPhoneEntryUpdated () {
- return this.phoneEntryUpdated;
+ public Long getMobileId () {
+ return this.mobileId;
}
@Override
- @SuppressWarnings ("AssignmentToDateFieldFromParameter")
- public void setPhoneEntryUpdated (final Date phoneEntryUpdated) {
- this.phoneEntryUpdated = phoneEntryUpdated;
+ public void setMobileId (final Long mobileId) {
+ this.mobileId = mobileId;
}
@Override
- public Long getPhoneId () {
- return this.phoneId;
+ public Long getMobileNumber () {
+ return this.mobileNumber;
}
@Override
- public void setPhoneId (final Long phoneId) {
- this.phoneId = phoneId;
+ public void setMobileNumber (final Long mobileNumber) {
+ this.mobileNumber = mobileNumber;
}
@Override
- public Long getPhoneNumber () {
- return this.phoneNumber;
+ public MobileProvider getMobileProvider () {
+ return this.mobileProvider;
}
@Override
- public void setPhoneNumber (final Long phoneNumber) {
- this.phoneNumber = phoneNumber;
+ public void setMobileProvider (final MobileProvider mobileProvider) {
+ this.mobileProvider = mobileProvider;
}
@Override
public int hashCode () {
int hash = 5;
- hash = 97 * hash + Objects.hashCode(this.getPhoneId());
+ hash = 97 * hash + Objects.hashCode(this.getMobileId());
hash = 97 * hash + Objects.hashCode(this.getMobileProvider());
- hash = 97 * hash + Objects.hashCode(this.getPhoneNumber());
+ hash = 97 * hash + Objects.hashCode(this.getMobileNumber());
return hash;
}
package org.mxchange.jphone.model.phonenumbers.mobile;
import java.io.Serializable;
+import java.util.Objects;
/**
* An utilities class for mobile numbers
* @param sourceNumber Source number object
* @param targetNumber Target number object
*/
- public static void copyAll (final DialableMobileNumber sourceNumber, final DialableMobileNumber targetNumber) {
+ public static void copyMobileNumber (final DialableMobileNumber sourceNumber, final DialableMobileNumber targetNumber) {
// Validate instance
if (null == sourceNumber) {
// Throw NPE
// Copy all fields
targetNumber.setMobileProvider(sourceNumber.getMobileProvider());
- targetNumber.setPhoneEntryCreated(sourceNumber.getPhoneEntryCreated());
- targetNumber.setPhoneId(sourceNumber.getPhoneId());
- targetNumber.setPhoneNumber(sourceNumber.getPhoneNumber());
+ targetNumber.setMobileEntryCreated(sourceNumber.getMobileEntryCreated());
+ targetNumber.setMobileId(sourceNumber.getMobileId());
+ targetNumber.setMobileNumber(sourceNumber.getMobileNumber());
+ }
+
+ /**
+ * Checks if both are the same
+ * <p>
+ * @param mobileNumber Mobile number 1
+ * @param otherNumber Mobile number 2
+ * <p>
+ * @return Whether both are the same number
+ */
+ public static boolean isSameMobileNumber (final DialableMobileNumber mobileNumber, final DialableMobileNumber otherNumber) {
+ // Test object equality first
+ if (Objects.equals(mobileNumber, otherNumber)) {
+ // Both the same object (null/null or same object)
+ return true;
+ } else if (((null == mobileNumber) && (otherNumber instanceof DialableMobileNumber)) || ((null == otherNumber) && (mobileNumber instanceof DialableMobileNumber))) {
+ // One is null the other not
+ return false;
+ }
+ // Now compare deeper
+ final boolean sameProvider = Objects.equals(mobileNumber.getMobileProvider(), otherNumber.getMobileProvider());
+ final boolean sameNumber = Objects.equals(mobileNumber.getMobileNumber(), otherNumber.getMobileNumber());
+ // All are the same?
+ return sameProvider && sameNumber;
}
/**
*/
package org.mxchange.jphone.model.phonenumbers.mobileprovider;
+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.apache.commons.lang3.StringUtils;
+import org.mxchange.jcoreutils.Comparables;
import org.mxchange.jcountry.model.data.Country;
import org.mxchange.jcountry.model.data.CountryData;
/**
- * A POJO for cellphone providers
+ * A POJO for mobile providers
* <p>
* @author Roland Häder<roland@mxchange.org>
*/
* <p>
* @param providerDialPrefix Dial prefix
* @param providerName Name
- * @param providerCountry Country
+ * @param providerCountry An instance of a Country class
* @param providerMailPattern Pattern for email
*/
public CellphoneProvider (final Long providerDialPrefix, final String providerName, final Country providerCountry, final String providerMailPattern) {
- // Call default constructor
+ // Invoke default constructor
this();
+ // Are all parameter set?
+ if (null == providerDialPrefix) {
+ // Throw NPE
+ throw new NullPointerException("providerDialPrefix is null"); //NOI18N
+ } else if (providerDialPrefix < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("providerDialPrefix={0} is not valid.", providerDialPrefix)); //NOI18N
+ } else if (null == providerName) {
+ // Throw NPE
+ throw new NullPointerException("providerName is null"); //NOI18N
+ } else if (providerName.isEmpty()) {
+ // Throw IAE
+ throw new IllegalArgumentException("providerName is empty"); //NOI18N
+ } else if (null == providerCountry) {
+ // Throw NPE
+ throw new NullPointerException("providerCountry is null"); //NOI18N
+ } else if (null == providerCountry.getCountryId()) {
+ // Throw NPE again
+ throw new NullPointerException("providerCountry.countryId is null"); //NOI18N
+ } else if (providerCountry.getCountryId() < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("providerCountry.countryId={0} is not valid", providerCountry.getCountryId())); //NOI18N
+ } else if (null == providerMailPattern) {
+ // Throw NPE
+ throw new NullPointerException("providerMailPattern is null"); //NOI18N
+ } else if (providerMailPattern.isEmpty()) {
+ // Throw IAE
+ throw new IllegalArgumentException("providerMailPattern is empty"); //NOI18N
+ }
+
// Set all values
this.providerDialPrefix = providerDialPrefix;
this.providerName = providerName;
this.providerMailPattern = providerMailPattern;
}
+ @Override
+ public int compareTo (final MobileProvider otherProvider) {
+ // Is the parameter given?
+ if (null == otherProvider) {
+ // Throw NPE
+ throw new NullPointerException("otherProvider is null"); //NOI18N
+ } else if (otherProvider.equals(this)) {
+ // Same object
+ return 0;
+ }
+
+ // Init comparisons
+ final int[] comparators = {
+ // First provider
+ this.getProviderCountry().compareTo(otherProvider.getProviderCountry()),
+ // Next is name
+ StringUtils.compare(this.getProviderName(), otherProvider.getProviderName()),
+ // Last is dial prefix
+ this.getProviderDialPrefix().compareTo(otherProvider.getProviderDialPrefix())
+ };
+
+ // Check all values
+ final int comparison = Comparables.checkAll(comparators);
+
+ // Return value
+ return comparison;
+ }
+
@Override
public boolean equals (final Object object) {
if (null == object) {
return false;
}
- final MobileProvider other = (MobileProvider) object;
+ final MobileProvider mobileProvider = (MobileProvider) object;
- if (!Objects.equals(this.getProviderDialPrefix(), other.getProviderDialPrefix())) {
+ if (!Objects.equals(this.getProviderDialPrefix(), mobileProvider.getProviderDialPrefix())) {
return false;
- } else if (!Objects.equals(this.getProviderName(), other.getProviderName())) {
+ } else if (!Objects.equals(this.getProviderName(), mobileProvider.getProviderName())) {
return false;
- } else if (!Objects.equals(this.getProviderCountry(), other.getProviderCountry())) {
+ } else if (!Objects.equals(this.getProviderCountry(), mobileProvider.getProviderCountry())) {
return false;
}
return true;
}
- @Override
- public int hashCode () {
- int hash = 7;
- hash = 19 * hash + Objects.hashCode(this.getProviderDialPrefix());
- hash = 19 * hash + Objects.hashCode(this.getProviderName());
- hash = 19 * hash + Objects.hashCode(this.getProviderCountry());
- return hash;
- }
-
@Override
public Country getProviderCountry () {
return this.providerCountry;
this.providerId = providerId;
}
+ @Override
+ public String getProviderMailPattern () {
+ return this.providerMailPattern;
+ }
+
+ @Override
+ public void setProviderMailPattern (final String providerMailPattern) {
+ this.providerMailPattern = providerMailPattern;
+ }
+
@Override
public String getProviderName () {
return this.providerName;
}
@Override
- public String getProviderMailPattern () {
- return this.providerMailPattern;
- }
+ public int hashCode () {
+ int hash = 7;
- @Override
- public void setProviderMailPattern (final String providerMailPattern) {
- this.providerMailPattern = providerMailPattern;
+ hash = 19 * hash + Objects.hashCode(this.getProviderDialPrefix());
+ hash = 19 * hash + Objects.hashCode(this.getProviderName());
+ hash = 19 * hash + Objects.hashCode(this.getProviderCountry());
+
+ return hash;
}
}
* <p>
* @author Roland Häder<roland@mxchange.org>
*/
-public interface MobileProvider extends Serializable {
+public interface MobileProvider extends Comparable<MobileProvider>, Serializable {
/**
* Getter for id number
* @param sourceMobileProvider Source mobile provider
* @param targetMobileProvider Target mobile provider
*/
- public static void copyAll (final MobileProvider sourceMobileProvider, final MobileProvider targetMobileProvider) {
+ public static void copyMobileProvider (final MobileProvider sourceMobileProvider, final MobileProvider targetMobileProvider) {
// Parameter should not be null
if (null == sourceMobileProvider) {
// Throw NPE
+++ /dev/null
-/*
- * Copyright (C) 2016 - 2020 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
- * 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.jphone.utils;
-
-import java.io.Serializable;
-import java.util.Objects;
-import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
-import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
-import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
-
-/**
- *
- * @author Roland Häder<roland@mxchange.org>
- */
-public class PhoneUtils implements Serializable {
-
- /**
- * Serial number
- */
- private static final long serialVersionUID = 183_598_328_176_450L;
-
- /**
- * Checks if both are the same
- * <p>
- * @param faxNumber First fax number
- * @param otherNumber Second fax number
- * <p>
- * @return Whether both are the same
- */
- public static boolean isSameFaxNumber (final DialableFaxNumber faxNumber, DialableFaxNumber otherNumber) {
- // Test object equality first
- if (Objects.equals(faxNumber, otherNumber)) {
- // Both the same object (null/null or same object)
- return true;
- } else if (((null == faxNumber) && (otherNumber instanceof DialableFaxNumber)) || ((null == otherNumber) && (faxNumber instanceof DialableFaxNumber))) {
- // One is null the other not
- return false;
- }
-
- // Now compare deeper
- @SuppressWarnings ("null")
- boolean sameCountry = Objects.equals(faxNumber.getPhoneCountry(), otherNumber.getPhoneCountry());
- boolean sameAreaCode = Objects.equals(faxNumber.getPhoneAreaCode(), otherNumber.getPhoneAreaCode());
- boolean sameNumber = Objects.equals(faxNumber.getPhoneNumber(), otherNumber.getPhoneNumber());
-
- // All are the same?
- return (sameCountry && sameAreaCode && sameNumber);
- }
-
- /**
- * Checks if both are the same
- * <p>
- * @param landLineNumber First land-line number
- * @param otherNumber Second land-line number
- * <p>
- * @return Whether both are the same
- */
- public static boolean isSameLandLineNumber (final DialableLandLineNumber landLineNumber, final DialableLandLineNumber otherNumber) {
- // Test object equality first
- if (Objects.equals(landLineNumber, otherNumber)) {
- // Both the same object (null/null or same object)
- return true;
- } else if (((null == landLineNumber) && (otherNumber instanceof DialableLandLineNumber)) || ((null == otherNumber) && (landLineNumber instanceof DialableLandLineNumber))) {
- // One is null the other not
- return false;
- }
-
- // Now compare deeper
- @SuppressWarnings ("null")
- boolean sameCountry = Objects.equals(landLineNumber.getPhoneCountry(), otherNumber.getPhoneCountry());
- boolean sameAreaCode = Objects.equals(landLineNumber.getPhoneAreaCode(), otherNumber.getPhoneAreaCode());
- boolean sameNumber = Objects.equals(landLineNumber.getPhoneNumber(), otherNumber.getPhoneNumber());
-
- // All are the same?
- return (sameCountry && sameAreaCode && sameNumber);
- }
-
- /**
- * Checks if both are the same
- * <p>
- * @param mobileNumber Mobile number 1
- * @param otherNumber Mobile number 2
- * <p>
- * @return Whether both are the same number
- */
- public static boolean isSameMobileNumber (final DialableMobileNumber mobileNumber, final DialableMobileNumber otherNumber) {
- // Test object equality first
- if (Objects.equals(mobileNumber, otherNumber)) {
- // Both the same object (null/null or same object)
- return true;
- } else if (((null == mobileNumber) && (otherNumber instanceof DialableMobileNumber)) || ((null == otherNumber) && (mobileNumber instanceof DialableMobileNumber))) {
- // One is null the other not
- return false;
- }
-
- // Now compare deeper
- @SuppressWarnings ("null")
- boolean sameProvider = Objects.equals(mobileNumber.getMobileProvider(), otherNumber.getMobileProvider());
- boolean sameNumber = Objects.equals(mobileNumber.getPhoneNumber(), otherNumber.getPhoneNumber());
-
- // All are the same?
- return (sameProvider && sameNumber);
- }
-
- /**
- * Private constructor for utility classes
- */
- private PhoneUtils () {
- }
-
-}