*/
package org.mxchange.jcontactsbusiness.model.headquarters;
+import java.text.MessageFormat;
import java.util.Date;
import java.util.List;
import java.util.Objects;
@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
*/
/**
* 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<OpeningTime> headquartersOpeningTimes;
@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) {
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;
}
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;
--- /dev/null
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jcontactsbusiness.model.headquarters;
+
+import java.io.Serializable;
+import java.util.Objects;
+
+/**
+ * An utilities class for headquarters
+ *
+ * @author Roland Häder<roland@mxchange.org>
+ */
+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.
+ * <p>
+ * @param headquarters1 Headquarters 1
+ * @param headquarters2 Headquarters 2
+ * <p>
+ * @return Whether both branch office addresses are the same
+ * <p>
+ * @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
+ }
+
+}