]> git.mxchange.org Git - jcontacts-business-core.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Wed, 1 Nov 2017 21:12:33 +0000 (22:12 +0100)
committerRoland Häder <roland@mxchange.org>
Wed, 1 Nov 2017 21:33:27 +0000 (22:33 +0100)
- 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)

Signed-off-by: Roland Häder <roland@mxchange.org>
src/org/mxchange/jcontactsbusiness/model/headquarters/BusinessHeadquarters.java
src/org/mxchange/jcontactsbusiness/model/headquarters/Headquarter.java
src/org/mxchange/jcontactsbusiness/model/headquarters/Headquarters.java [new file with mode: 0644]

index 9fe7e36d63bae7ef915a924ce4f73e93fd3ab4b6..892bf8d8cdaf9d94190d860a159ea401cc86c878 100644 (file)
@@ -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<OpeningTime> 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;
index ee834a11422f6ba31739faded5ac181858a831f9..65613c7f2e178896eb5779caeea9398eb24553b7 100644 (file)
@@ -215,6 +215,20 @@ public interface Headquarter extends Serializable {
         */
        void setHeadquartersOpeningTimes (final List<OpeningTime> branchOpeningTimes);
 
+       /**
+        * Getter for headquarters' email address
+        * <p>
+        * @return Headquarters' email address
+        */
+       String getHeadquartersEmailAddress ();
+
+       /**
+        * Setter for headquarters' email address
+        * <p>
+        * @param headquartersEmailAddress Headquarters' email address
+        */
+       void setHeadquartersEmailAddress (final String headquartersEmailAddress);
+
        /**
         * Getter for timestamp when this entry has been created
         * <p>
diff --git a/src/org/mxchange/jcontactsbusiness/model/headquarters/Headquarters.java b/src/org/mxchange/jcontactsbusiness/model/headquarters/Headquarters.java
new file mode 100644 (file)
index 0000000..77bad86
--- /dev/null
@@ -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 <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
+       }
+
+}