From 47b97401f78fcbedc2cb7bb308cd048fe00cac51 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 1 Nov 2017 22:12:33 +0100 Subject: [PATCH] Continued: - added default constructor (required for EJB container) - added constructor with all required fields - added email address for headquarters - added utils class for headquarters - renamed branch_id to headquarters_id (copy-paste mistake) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../headquarters/BusinessHeadquarters.java | 91 ++++++++++++++++-- .../model/headquarters/Headquarter.java | 14 +++ .../model/headquarters/Headquarters.java | 93 +++++++++++++++++++ 3 files changed, 188 insertions(+), 10 deletions(-) create mode 100644 src/org/mxchange/jcontactsbusiness/model/headquarters/Headquarters.java diff --git a/src/org/mxchange/jcontactsbusiness/model/headquarters/BusinessHeadquarters.java b/src/org/mxchange/jcontactsbusiness/model/headquarters/BusinessHeadquarters.java index 9fe7e36..892bf8d 100644 --- a/src/org/mxchange/jcontactsbusiness/model/headquarters/BusinessHeadquarters.java +++ b/src/org/mxchange/jcontactsbusiness/model/headquarters/BusinessHeadquarters.java @@ -16,6 +16,7 @@ */ package org.mxchange.jcontactsbusiness.model.headquarters; +import java.text.MessageFormat; import java.util.Date; import java.util.List; import java.util.Objects; @@ -92,6 +93,12 @@ public class BusinessHeadquarters implements Headquarter { @Column (name = "headquarters_entry_created", nullable = false, updatable = false) private Date headquartersCreated; + /** + * Email address of headquarters + */ + @Column( name = "headquarters_email_address") + private String headquartersEmailAddress; + /** * Headquarter' fax number */ @@ -124,7 +131,7 @@ public class BusinessHeadquarters implements Headquarter { /** * Opening times for this branch office */ - @JoinTable (name = "headquarters_opening_times", joinColumns =@JoinColumn (name = "headquarters_opening_id", referencedColumnName = "branch_id"), inverseJoinColumns = @JoinColumn (name = "opening_headquarters_id", referencedColumnName = "opening_times_id")) + @JoinTable (name = "headquarters_opening_times", joinColumns =@JoinColumn (name = "headquarters_opening_id", referencedColumnName = "headquarters_id"), inverseJoinColumns = @JoinColumn (name = "opening_headquarters_id", referencedColumnName = "opening_times_id")) @ManyToMany (targetEntity = BusinessOpeningTime.class, cascade = CascadeType.ALL) private List headquartersOpeningTimes; @@ -161,6 +168,60 @@ public class BusinessHeadquarters implements Headquarter { @Column (name = "headquarters_zip_code", length = 6, nullable = false) private Integer headquartersZipCode; + /** + * Default constructor + */ + public BusinessHeadquarters () { + } + + public BusinessHeadquarters (final String headquartersCity, final Country headquartersCountry, final String headquartersStreet, final Integer headquartersZipCode, final Short headquartersHouseNumber) { + // Call other constructor first + this(); + + // Validate parameters + if (null == headquartersCity) { + // Throw NPE + throw new NullPointerException("headquartersCity is null"); + } else if (headquartersCity.isEmpty()) { + // Throw IAE + throw new IllegalArgumentException("headquartersCity is empty"); + } else if (null == headquartersCountry) { + // Throw NPE + throw new NullPointerException("headquartersCountry is null"); + } else if (headquartersCountry.getCountryId() == null) { + // Throw NPE again + throw new NullPointerException("headquartersCountry.countryId is null"); + } else if (headquartersCountry.getCountryId() < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("headquartersCountry.countryId={0} is not valid.", headquartersCountry.getCountryId())); + } else if (null == headquartersHouseNumber) { + // Throw NPE + throw new NullPointerException("headquartersHouseNumber is null"); + } else if (headquartersHouseNumber <1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("headquartersHouseNumber={0} is invalid.", headquartersHouseNumber)); + } else if (null == headquartersStreet) { + // Throw NPE + throw new NullPointerException("headquartersStreet is null"); + } else if (headquartersStreet.isEmpty()) { + // Throw IAE + throw new IllegalArgumentException("headquartersStreet is empty"); + } else if (null == headquartersZipCode) { + // Throw NPE + throw new NullPointerException("headquartersZipCode is null"); + } else if (headquartersZipCode <1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("headquartersZipCode={0} is invalid.", headquartersZipCode)); + } + + // Set all fields + this.headquartersCity = headquartersCity; + this.headquartersCountry = headquartersCountry; + this.headquartersHouseNumber = headquartersHouseNumber; + this.headquartersStreet = headquartersStreet; + this.headquartersZipCode = headquartersZipCode; + } + @Override public boolean equals (final Object object) { if (null == object) { @@ -169,23 +230,23 @@ public class BusinessHeadquarters implements Headquarter { return false; } - final Headquarter other = (Headquarter) object; + final Headquarter headquarter = (Headquarter) object; - if (!Objects.equals(this.getHeadquartersId(), other.getHeadquartersId())) { + if (!Objects.equals(this.getHeadquartersId(), headquarter.getHeadquartersId())) { return false; - } else if (!Objects.equals(this.getHeadquartersCity(), other.getHeadquartersCity())) { + } else if (!Objects.equals(this.getHeadquartersCity(), headquarter.getHeadquartersCity())) { return false; - } else if (!Objects.equals(this.getHeadquartersCountry(), other.getHeadquartersCountry())) { + } else if (!Objects.equals(this.getHeadquartersCountry(), headquarter.getHeadquartersCountry())) { return false; - } else if (!Objects.equals(this.getHeadquartersHouseNumber(), other.getHeadquartersHouseNumber())) { + } else if (!Objects.equals(this.getHeadquartersHouseNumber(), headquarter.getHeadquartersHouseNumber())) { return false; - } else if (!Objects.equals(this.getHeadquartersStore(), other.getHeadquartersStore())) { + } else if (!Objects.equals(this.getHeadquartersStore(), headquarter.getHeadquartersStore())) { return false; - } else if (!Objects.equals(this.getHeadquartersStreet(), other.getHeadquartersStreet())) { + } else if (!Objects.equals(this.getHeadquartersStreet(), headquarter.getHeadquartersStreet())) { return false; - } else if (!Objects.equals(this.getHeadquartersSuiteNumber(), other.getHeadquartersSuiteNumber())) { + } else if (!Objects.equals(this.getHeadquartersSuiteNumber(), headquarter.getHeadquartersSuiteNumber())) { return false; - } else if (!Objects.equals(this.getHeadquartersZipCode(), other.getHeadquartersZipCode())) { + } else if (!Objects.equals(this.getHeadquartersZipCode(), headquarter.getHeadquartersZipCode())) { return false; } @@ -234,6 +295,16 @@ public class BusinessHeadquarters implements Headquarter { this.headquartersCreated = headquartersCreated; } + @Override + public String getHeadquartersEmailAddress () { + return this.headquartersEmailAddress; + } + + @Override + public void setHeadquartersEmailAddress (final String headquartersEmailAddress) { + this.headquartersEmailAddress = headquartersEmailAddress; + } + @Override public DialableFaxNumber getHeadquartersFaxNumber () { return this.headquartersFaxNumber; diff --git a/src/org/mxchange/jcontactsbusiness/model/headquarters/Headquarter.java b/src/org/mxchange/jcontactsbusiness/model/headquarters/Headquarter.java index ee834a1..65613c7 100644 --- a/src/org/mxchange/jcontactsbusiness/model/headquarters/Headquarter.java +++ b/src/org/mxchange/jcontactsbusiness/model/headquarters/Headquarter.java @@ -215,6 +215,20 @@ public interface Headquarter extends Serializable { */ void setHeadquartersOpeningTimes (final List branchOpeningTimes); + /** + * Getter for headquarters' email address + *

+ * @return Headquarters' email address + */ + String getHeadquartersEmailAddress (); + + /** + * Setter for headquarters' email address + *

+ * @param headquartersEmailAddress Headquarters' email address + */ + void setHeadquartersEmailAddress (final String headquartersEmailAddress); + /** * Getter for timestamp when this entry has been created *

diff --git a/src/org/mxchange/jcontactsbusiness/model/headquarters/Headquarters.java b/src/org/mxchange/jcontactsbusiness/model/headquarters/Headquarters.java new file mode 100644 index 0000000..77bad86 --- /dev/null +++ b/src/org/mxchange/jcontactsbusiness/model/headquarters/Headquarters.java @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2017 Roland Häder + * + * 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 . + */ +package org.mxchange.jcontactsbusiness.model.headquarters; + +import java.io.Serializable; +import java.util.Objects; + +/** + * An utilities class for headquarters + * + * @author Roland Häder + */ +public class Headquarters implements Serializable { + + /** + * Serial number + */ + private static final long serialVersionUID = 69_537_867_224_651L; + + /** + * Checks if both headquarters have same address. This method will throw + * an {@code NullPointerException} if one of the instances is null. + *

+ * @param headquarters1 Headquarters 1 + * @param headquarters2 Headquarters 2 + *

+ * @return Whether both branch office addresses are the same + *

+ * @throws NullPointerException If one of the instances is null + */ + public static boolean isSameAddress (final Headquarter headquarters1, final Headquarter headquarters2) { + // Check that both parameters are not null + if (null == headquarters1) { + // Throw NPE + throw new NullPointerException("headquarters1 is null"); //NOI18N + } else if (null == headquarters2) { + // Throw NPE + throw new NullPointerException("headquarters2 is null"); //NOI18N + } + + // Default is the same + boolean isSameAddress = true; + + // Compare both addresses + if (!Objects.equals(headquarters1.getHeadquartersCountry(), headquarters2.getHeadquartersCountry())) { + // Not the same + isSameAddress = false; + } else if (!Objects.equals(headquarters1.getHeadquartersCity(), headquarters2.getHeadquartersCity())) { + // Not the same + isSameAddress = false; + } else if (!Objects.equals(headquarters1.getHeadquartersZipCode(), headquarters2.getHeadquartersZipCode())) { + // Not the same + isSameAddress = false; + } else if (!Objects.equals(headquarters1.getHeadquartersStreet(), headquarters2.getHeadquartersStreet())) { + // Not the same + isSameAddress = false; + } else if (!Objects.equals(headquarters1.getHeadquartersHouseNumber(), headquarters2.getHeadquartersHouseNumber())) { + // Not the same + isSameAddress = false; + } else if (!Objects.equals(headquarters1.getHeadquartersStore(), headquarters2.getHeadquartersStore())) { + // Not the same + isSameAddress = false; + } else if (!Objects.equals(headquarters1.getHeadquartersSuiteNumber(), headquarters2.getHeadquartersSuiteNumber())) { + // Not the same + isSameAddress = false; + } + + // Return flag + return isSameAddress; + } + + /** + * Private default constructor + */ + private Headquarters () { + // Utilities don't have instances + } + +} -- 2.39.5