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.Comparables;
39 import org.mxchange.jcountry.model.data.Country;
40 import org.mxchange.jcountry.model.data.CountryData;
43 * A POJO for mobile providers
45 * @author Roland Häder<roland@mxchange.org>
47 @Entity (name = "mobile_provider")
48 @Table (name = "mobile_provider")
50 @NamedQuery (name = "AllMobileProvider", query = "SELECT p FROM mobile_provider AS p ORDER BY p.providerId ASC")
52 @SuppressWarnings ("PersistenceUnitPresent")
53 public class CellphoneProvider implements MobileProvider {
59 private static final long serialVersionUID = 185_878_567_810_590L;
62 * Country instance ('s dial data)
64 @JoinColumn (name = "provider_country_id", nullable = false)
65 @OneToOne (targetEntity = CountryData.class, cascade = CascadeType.REFRESH, optional = false)
66 private Country providerCountry;
69 * Provider dial prefix (example: 0177 for German E+)
71 @Basic (optional = false)
72 @Column (name = "provider_dial_prefix", length = 10, nullable = false)
73 private Long providerDialPrefix;
76 * Timestamp when this entry has been created
78 @Basic (optional = false)
79 @Temporal (TemporalType.TIMESTAMP)
80 @Column (name = "provider_entry_created", nullable = false, updatable = false)
81 private Date providerEntryCreated;
84 * Timestamp when this entry has been created
86 @Temporal (TemporalType.TIMESTAMP)
87 @Column (name = "provider_entry_updated", insertable = false)
88 private Date providerEntryUpdated;
94 @GeneratedValue (strategy = GenerationType.IDENTITY)
95 @Column (name = "provider_id", nullable = false, updatable = false)
96 private Long providerId;
99 * Pattern for mail gateway
101 @Column (name = "provider_mail_pattern", length = 30)
102 private String providerMailPattern;
105 * Name of the provider
107 @Basic (optional = false)
108 @Column (name = "provider_name", length = 30, nullable = false)
109 private String providerName;
112 * Default constructor
114 public CellphoneProvider () {
118 * Constructor with all required data
120 * @param providerDialPrefix Dial prefix
121 * @param providerName Name
122 * @param providerCountry An instance of a Country class
123 * @param providerMailPattern Pattern for email
125 public CellphoneProvider (final Long providerDialPrefix, final String providerName, final Country providerCountry, final String providerMailPattern) {
126 // Invoke default constructor
129 // Are all parameter set?
130 if (null == providerDialPrefix) {
132 throw new NullPointerException("providerDialPrefix is null"); //NOI18N
133 } else if (providerDialPrefix < 1) {
135 throw new IllegalArgumentException(MessageFormat.format("providerDialPrefix={0} is not valid.", providerDialPrefix)); //NOI18N
136 } else if (null == providerName) {
138 throw new NullPointerException("providerName is null"); //NOI18N
139 } else if (providerName.isEmpty()) {
141 throw new IllegalArgumentException("providerName is empty"); //NOI18N
142 } else if (null == providerCountry) {
144 throw new NullPointerException("providerCountry is null"); //NOI18N
145 } else if (null == providerCountry.getCountryId()) {
147 throw new NullPointerException("providerCountry.countryId is null"); //NOI18N
148 } else if (providerCountry.getCountryId() < 1) {
150 throw new IllegalArgumentException(MessageFormat.format("providerCountry.countryId={0} is not valid", providerCountry.getCountryId())); //NOI18N
151 } else if (null == providerMailPattern) {
153 throw new NullPointerException("providerMailPattern is null"); //NOI18N
154 } else if (providerMailPattern.isEmpty()) {
156 throw new IllegalArgumentException("providerMailPattern is empty"); //NOI18N
160 this.providerDialPrefix = providerDialPrefix;
161 this.providerName = providerName;
162 this.providerCountry = providerCountry;
163 this.providerMailPattern = providerMailPattern;
167 public int compareTo (final MobileProvider otherProvider) {
168 // Is the parameter given?
169 if (null == otherProvider) {
171 throw new NullPointerException("otherProvider is null"); //NOI18N
172 } else if (otherProvider.equals(this)) {
178 final int[] comparators = {
180 this.getProviderCountry().compareTo(otherProvider.getProviderCountry()),
182 StringUtils.compare(this.getProviderName(), otherProvider.getProviderName()),
183 // Last is dial prefix
184 this.getProviderDialPrefix().compareTo(otherProvider.getProviderDialPrefix())
188 final int comparison = Comparables.checkAll(comparators);
195 public boolean equals (final Object object) {
196 if (null == object) {
198 } else if (this.getClass() != object.getClass()) {
202 final MobileProvider mobileProvider = (MobileProvider) object;
204 if (!Objects.equals(this.getProviderDialPrefix(), mobileProvider.getProviderDialPrefix())) {
206 } else if (!Objects.equals(this.getProviderName(), mobileProvider.getProviderName())) {
208 } else if (!Objects.equals(this.getProviderCountry(), mobileProvider.getProviderCountry())) {
216 public Country getProviderCountry () {
217 return this.providerCountry;
221 public void setProviderCountry (final Country providerCountry) {
222 this.providerCountry = providerCountry;
226 public Long getProviderDialPrefix () {
227 return this.providerDialPrefix;
231 public void setProviderDialPrefix (final Long providerDialPrefix) {
232 this.providerDialPrefix = providerDialPrefix;
236 @SuppressWarnings ("ReturnOfDateField")
237 public Date getProviderEntryCreated () {
238 return this.providerEntryCreated;
242 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
243 public void setProviderEntryCreated (final Date providerEntryCreated) {
244 this.providerEntryCreated = providerEntryCreated;
248 @SuppressWarnings ("ReturnOfDateField")
249 public Date getProviderEntryUpdated () {
250 return this.providerEntryUpdated;
254 @SuppressWarnings ("AssignmentToDateFieldFromParameter")
255 public void setProviderEntryUpdated (final Date providerEntryUpdated) {
256 this.providerEntryUpdated = providerEntryUpdated;
260 public Long getProviderId () {
261 return this.providerId;
265 public void setProviderId (final Long providerId) {
266 this.providerId = providerId;
270 public String getProviderMailPattern () {
271 return this.providerMailPattern;
275 public void setProviderMailPattern (final String providerMailPattern) {
276 this.providerMailPattern = providerMailPattern;
280 public String getProviderName () {
281 return this.providerName;
285 public void setProviderName (final String providerName) {
286 this.providerName = providerName;
290 public int hashCode () {
293 hash = 19 * hash + Objects.hashCode(this.getProviderDialPrefix());
294 hash = 19 * hash + Objects.hashCode(this.getProviderName());
295 hash = 19 * hash + Objects.hashCode(this.getProviderCountry());