2 * Copyright (C) 2016 - 2022 Free Software Foundation
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.jphone.model.phonenumbers.mobileprovider;
19 import java.text.MessageFormat;
20 import java.util.Date;
21 import java.util.Objects;
22 import javax.persistence.Basic;
23 import javax.persistence.CascadeType;
24 import javax.persistence.Column;
25 import javax.persistence.Entity;
26 import javax.persistence.GeneratedValue;
27 import javax.persistence.GenerationType;
28 import javax.persistence.Id;
29 import javax.persistence.JoinColumn;
30 import javax.persistence.NamedQueries;
31 import javax.persistence.NamedQuery;
32 import javax.persistence.OneToOne;
33 import javax.persistence.Table;
34 import javax.persistence.Temporal;
35 import javax.persistence.TemporalType;
36 import javax.persistence.Transient;
37 import org.apache.commons.lang3.StringUtils;
38 import org.mxchange.jcoreutils.comparable.ComparableUtils;
39 import org.mxchange.jcoreutils.number.SafeNumberUtils;
40 import org.mxchange.jcountry.model.data.Country;
41 import org.mxchange.jcountry.model.data.CountryData;
42 import org.mxchange.jcountry.model.utils.CountryUtils;
45 * A POJO for mobile providers
47 * @author Roland Häder<roland@mxchange.org>
49 @Entity (name = "mobile_provider")
50 @Table (name = "mobile_provider")
52 @NamedQuery (name = "AllMobileProvider", query = "SELECT p FROM mobile_provider AS p ORDER BY p.providerId ASC")
54 @SuppressWarnings ("PersistenceUnitPresent")
55 public class CellphoneProvider implements MobileProvider {
61 private static final long serialVersionUID = 185_878_567_810_590L;
64 * Country instance ('s dial data)
66 @JoinColumn (name = "provider_country_id", nullable = false)
67 @OneToOne (targetEntity = CountryData.class, cascade = CascadeType.REFRESH, optional = false)
68 private Country providerCountry;
71 * Provider dial prefix (example: 0177 for German E+)
73 @Basic (optional = false)
74 @Column (name = "provider_dial_prefix", length = 10, nullable = false)
75 private Long providerDialPrefix;
78 * Timestamp when this entry has been created
80 @Basic (optional = false)
81 @Temporal (TemporalType.TIMESTAMP)
82 @Column (name = "provider_entry_created", nullable = false, updatable = false)
83 private Date providerEntryCreated;
86 * Timestamp when this entry has been created
88 @Temporal (TemporalType.TIMESTAMP)
89 @Column (name = "provider_entry_updated", insertable = false)
90 private Date providerEntryUpdated;
96 @GeneratedValue (strategy = GenerationType.IDENTITY)
97 @Column (name = "provider_id", nullable = false, updatable = false)
98 private Long providerId;
101 * Pattern for mail gateway
103 @Column (name = "provider_mail_pattern", length = 30)
104 private String providerMailPattern;
107 * Name of the provider
109 @Basic (optional = false)
110 @Column (name = "provider_name", length = 30, nullable = false)
111 private String providerName;
114 * Default constructor
116 public CellphoneProvider () {
120 * Constructor with all required data
122 * @param providerDialPrefix Dial prefix
123 * @param providerName Name
124 * @param providerCountry An instance of a Country class
125 * @param providerMailPattern Pattern for email
127 public CellphoneProvider (final Long providerDialPrefix, final String providerName, final Country providerCountry, final String providerMailPattern) {
128 // Invoke default constructor
131 // Are all parameter set?
132 if (null == providerDialPrefix) {
134 throw new NullPointerException("providerDialPrefix is null"); //NOI18N
135 } else if (providerDialPrefix < 1) {
137 throw new IllegalArgumentException(MessageFormat.format("providerDialPrefix={0} is not valid.", providerDialPrefix)); //NOI18N
138 } else if (null == providerName) {
140 throw new NullPointerException("providerName is null"); //NOI18N
141 } else if (providerName.isEmpty()) {
143 throw new IllegalArgumentException("providerName is empty"); //NOI18N
144 } else if (null == providerCountry) {
146 throw new NullPointerException("providerCountry is null"); //NOI18N
147 } else if (null == providerCountry.getCountryId()) {
149 throw new NullPointerException("providerCountry.countryId is null"); //NOI18N
150 } else if (providerCountry.getCountryId() < 1) {
152 throw new IllegalArgumentException(MessageFormat.format("providerCountry.countryId={0} is not valid", providerCountry.getCountryId())); //NOI18N
153 } else if (null == providerMailPattern) {
155 throw new NullPointerException("providerMailPattern is null"); //NOI18N
156 } else if (providerMailPattern.isEmpty()) {
158 throw new IllegalArgumentException("providerMailPattern is empty"); //NOI18N
162 this.providerDialPrefix = providerDialPrefix;
163 this.providerName = providerName;
164 this.providerCountry = providerCountry;
165 this.providerMailPattern = providerMailPattern;
169 public int compareTo (final MobileProvider provider) {
170 // Is the parameter given?
171 if (null == provider) {
173 throw new NullPointerException("Parameter 'provider' is null"); //NOI18N
174 } else if (Objects.equals(this, provider)) {
180 final int[] comparators = {
181 // First provider country
182 CountryUtils.compare(this.getProviderCountry(), provider.getProviderCountry()),
184 StringUtils.compare(this.getProviderName(), provider.getProviderName()),
186 SafeNumberUtils.compare(this.getProviderDialPrefix(), provider.getProviderDialPrefix()),
188 StringUtils.compare(this.getProviderMailPattern(), provider.getProviderMailPattern())
192 final int comparison = ComparableUtils.checkAll(comparators);
199 public boolean equals (final Object object) {
200 if (null == object) {
202 } else if (this.getClass() != object.getClass()) {
206 final MobileProvider mobileProvider = (MobileProvider) object;
208 if (!Objects.equals(this.getProviderDialPrefix(), mobileProvider.getProviderDialPrefix())) {
210 } else if (!Objects.equals(this.getProviderName(), mobileProvider.getProviderName())) {
212 } else if (!Objects.equals(this.getProviderCountry(), mobileProvider.getProviderCountry())) {
220 public Country getProviderCountry () {
221 return this.providerCountry;
225 public void setProviderCountry (final Country providerCountry) {
226 this.providerCountry = providerCountry;
230 public Long getProviderDialPrefix () {
231 return this.providerDialPrefix;
235 public void setProviderDialPrefix (final Long providerDialPrefix) {
236 this.providerDialPrefix = providerDialPrefix;
240 @SuppressWarnings ("ReturnOfDateField")
241 public Date getProviderEntryCreated () {
242 return this.providerEntryCreated;
246 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
247 public void setProviderEntryCreated (final Date providerEntryCreated) {
248 this.providerEntryCreated = providerEntryCreated;
252 @SuppressWarnings ("ReturnOfDateField")
253 public Date getProviderEntryUpdated () {
254 return this.providerEntryUpdated;
258 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
259 public void setProviderEntryUpdated (final Date providerEntryUpdated) {
260 this.providerEntryUpdated = providerEntryUpdated;
264 public Long getProviderId () {
265 return this.providerId;
269 public void setProviderId (final Long providerId) {
270 this.providerId = providerId;
274 public String getProviderMailPattern () {
275 return this.providerMailPattern;
279 public void setProviderMailPattern (final String providerMailPattern) {
280 this.providerMailPattern = providerMailPattern;
284 public String getProviderName () {
285 return this.providerName;
289 public void setProviderName (final String providerName) {
290 this.providerName = providerName;
294 public int hashCode () {
297 hash = 19 * hash + Objects.hashCode(this.getProviderDialPrefix());
298 hash = 19 * hash + Objects.hashCode(this.getProviderName());
299 hash = 19 * hash + Objects.hashCode(this.getProviderCountry());