/*
- * Copyright (C) 2016 - 2018 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.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.comparable.ComparableUtils;
+import org.mxchange.jcoreutils.number.SafeNumberUtils;
import org.mxchange.jcountry.model.data.Country;
import org.mxchange.jcountry.model.data.CountryData;
+import org.mxchange.jcountry.model.utils.CountryUtils;
/**
- * A POJO for cellphone providers
+ * A POJO for mobile providers
* <p>
* @author Roland Häder<roland@mxchange.org>
*/
@Column (name = "provider_entry_created", nullable = false, updatable = false)
private Date providerEntryCreated;
+ /**
+ * Timestamp when this entry has been created
+ */
+ @Temporal (TemporalType.TIMESTAMP)
+ @Column (name = "provider_entry_updated", insertable = false)
+ private Date providerEntryUpdated;
+
/**
* Id number
*/
* <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 provider) {
+ // Is the parameter given?
+ if (null == provider) {
+ // Throw NPE
+ throw new NullPointerException("Parameter 'provider' is null"); //NOI18N
+ } else if (Objects.equals(this, provider)) {
+ // Same object
+ return 0;
+ }
+
+ // Init comparisons
+ final int[] comparators = {
+ // First provider country
+ CountryUtils.compare(this.getProviderCountry(), provider.getProviderCountry()),
+ // ... provider name
+ StringUtils.compare(this.getProviderName(), provider.getProviderName()),
+ // ... dial prefix
+ SafeNumberUtils.compare(this.getProviderDialPrefix(), provider.getProviderDialPrefix()),
+ // ... mail pattern
+ StringUtils.compare(this.getProviderMailPattern(), provider.getProviderMailPattern())
+ };
+
+ // Check all values
+ final int comparison = ComparableUtils.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.getProviderId(), mobileProvider.getProviderId())) {
return false;
- } else if (!Objects.equals(this.getProviderCountry(), other.getProviderCountry())) {
+ } else if (!Objects.equals(this.getProviderMailPattern(), mobileProvider.getProviderMailPattern())) {
+ return false;
+ } else if (!Objects.equals(this.getProviderName(), mobileProvider.getProviderName())) {
+ return false;
+ } 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.providerEntryCreated = providerEntryCreated;
}
+ @Override
+ @SuppressWarnings ("ReturnOfDateField")
+ public Date getProviderEntryUpdated () {
+ return this.providerEntryUpdated;
+ }
+
+ @Override
+ @SuppressWarnings ("AssignmentToDateFieldFromParameter")
+ public void setProviderEntryUpdated (final Date providerEntryUpdated) {
+ this.providerEntryUpdated = providerEntryUpdated;
+ }
+
@Override
public Long getProviderId () {
return this.providerId;
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.getProviderId());
+ hash = 19 * hash + Objects.hashCode(this.getProviderMailPattern());
+ hash = 19 * hash + Objects.hashCode(this.getProviderName());
+ hash = 19 * hash + Objects.hashCode(this.getProviderCountry());
+
+ return hash;
}
}