]> git.mxchange.org Git - jcustomer-core.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Sun, 22 Jan 2023 00:15:35 +0000 (01:15 +0100)
committerRoland Häder <roland@mxchange.org>
Sun, 22 Jan 2023 00:26:16 +0000 (01:26 +0100)
- also compare account status so you can sort a list of customers by it
- constructors, and they are private anyway, of enumerations should not throw
  exceptions and they cannot be unit-tested, too
- check all parameters, like instances not being null and throw proper
  exceptions

src/org/mxchange/jcustomercore/events/customer/created/CreatedCustomerEvent.java
src/org/mxchange/jcustomercore/events/customer/update/AdminUpdatedCustomerDataEvent.java
src/org/mxchange/jcustomercore/model/customer/ContactCustomer.java
src/org/mxchange/jcustomercore/model/customer/status/CustomerAccountStatus.java

index 8d6b5dc4b0485dc2deab0e94485dce3f1611c5fb..20e832048ed9fa7dd177c5f1e37540a4c2889e89 100644 (file)
  */
 package org.mxchange.jcustomercore.events.customer.created;
 
+import java.text.MessageFormat;
 import org.mxchange.jcustomercore.model.customer.Customer;
 
 /**
  * An interface for observable events being fired when a customer instance has
- * been successfully created. This may happen when a customer profile was called.
+ * been successfully created. This may happen when a customer profile was
+ * called.
  * <p>
  * @author Roland Häder<roland@mxchange.org>
  */
@@ -42,6 +44,33 @@ public class CreatedCustomerEvent implements ObservableCreatedCustomerEvent {
         * @param createdCustomer Customer instance being created by helper
         */
        public CreatedCustomerEvent (final Customer createdCustomer) {
+               // The instance should be valid
+               if (null == createdCustomer) {
+                       // Throw NPE
+                       throw new NullPointerException("createdCustomer is null"); //NOI18N
+               } else if (createdCustomer.getCustomerId() == null) {
+                       // Throw NPE, again ...
+                       throw new NullPointerException("createdCustomer.customerId is null"); //NOI18N
+               } else if (createdCustomer.getCustomerId() < 1) {
+                       // Not valid
+                       throw new IllegalArgumentException(MessageFormat.format("createdCustomer.customerId={0} is not valid", createdCustomer.getCustomerId())); //NOI18N
+               } else if (createdCustomer.getCustomerNumber() == null) {
+                       // Throw NPE, again ...
+                       throw new NullPointerException("createdCustomer.customerNumber is null"); //NOI18N
+               } else if (createdCustomer.getCustomerNumber() == null) {
+                       // Empty customer number
+                       throw new IllegalArgumentException("createdCustomer.customerNumber is empty"); //NOI18N
+               } else if (createdCustomer.getCustomerContact() == null) {
+                       // Throw again ...
+                       throw new NullPointerException("createdCustomer.customerContact is null"); //NOI18N
+               } else if (createdCustomer.getCustomerContact().getContactId() == null) {
+                       // ... and again ...
+                       throw new NullPointerException("createdCustomer.customerContact.contactId is null"); //NOI18N
+               } else if (createdCustomer.getCustomerContact().getContactId() < 1) {
+                       // Not valid
+                       throw new IllegalArgumentException(MessageFormat.format("createdCustomer.customerContact.contactId={0} is not valid", createdCustomer.getCustomerContact().getContactId())); //NOI18N
+               }
+
                // Set customer instance
                this.createdCustomer = createdCustomer;
        }
index d2dd4b1f92c8defca835f77f2a2e5dbba2e99e35..9d48410f0c0f55398852ea73d5e26bdbe7f04e91 100644 (file)
@@ -42,16 +42,31 @@ public class AdminUpdatedCustomerDataEvent implements ObservableAdminUpdatedCust
         * @param updatedCustomer Updated customer instance
         */
        public AdminUpdatedCustomerDataEvent (final Customer updatedCustomer) {
-               // Is the customer instance valid?
+               // The instance should be valid
                if (null == updatedCustomer) {
                        // Throw NPE
                        throw new NullPointerException("updatedCustomer is null"); //NOI18N
                } else if (updatedCustomer.getCustomerId() == null) {
-                       // Throw NPE again
+                       // Throw NPE, again ...
                        throw new NullPointerException("updatedCustomer.customerId is null"); //NOI18N
                } else if (updatedCustomer.getCustomerId() < 1) {
-                       // Invalid id number
-                       throw new IllegalArgumentException(MessageFormat.format("updatedCustomer.customerId={0} is invalid.", updatedCustomer.getCustomerId())); //NOI18N
+                       // Not valid
+                       throw new IllegalArgumentException(MessageFormat.format("updatedCustomer.customerId={0} is not valid", updatedCustomer.getCustomerId())); //NOI18N
+               } else if (updatedCustomer.getCustomerNumber() == null) {
+                       // Throw NPE, again ...
+                       throw new NullPointerException("updatedCustomer.customerNumber is null"); //NOI18N
+               } else if (updatedCustomer.getCustomerNumber() == null) {
+                       // Empty customer number
+                       throw new IllegalArgumentException("updatedCustomer.customerNumber is empty"); //NOI18N
+               } else if (updatedCustomer.getCustomerContact() == null) {
+                       // Throw again ...
+                       throw new NullPointerException("updatedCustomer.customerContact is null"); //NOI18N
+               } else if (updatedCustomer.getCustomerContact().getContactId() == null) {
+                       // ... and again ...
+                       throw new NullPointerException("updatedCustomer.customerContact.contactId is null"); //NOI18N
+               } else if (updatedCustomer.getCustomerContact().getContactId() < 1) {
+                       // Not valid
+                       throw new IllegalArgumentException(MessageFormat.format("updatedCustomer.customerContact.contactId={0} is not valid", updatedCustomer.getCustomerContact().getContactId())); //NOI18N
                }
 
                // Set it here
index efbac01ee8da38da70942e2306a3008484ea0ecf..593fe47e8d933dedbf22097aa3fffb955dbed38c 100644 (file)
@@ -41,6 +41,7 @@ import org.mxchange.jcontacts.model.contact.Contact;
 import org.mxchange.jcontacts.model.contact.UserContact;
 import org.mxchange.jcontacts.model.utils.ContactUtils;
 import org.mxchange.jcoreutils.comparable.ComparableUtils;
+import org.mxchange.jcoreutils.enums.EnumUtils;
 import org.mxchange.jcustomercore.model.customer.status.CustomerAccountStatus;
 
 /**
@@ -181,8 +182,10 @@ public class ContactCustomer implements Customer {
                        ContactUtils.compare(this.getCustomerContact(), customer.getCustomerContact()),
                        // ... then customer number
                        StringUtils.compare(this.getCustomerNumber(), customer.getCustomerNumber()),
-                       // ... last is confirmation key
-                       StringUtils.compare(this.getCustomerConfirmKey(), customer.getCustomerConfirmKey())
+                       // ... next is confirmation key
+                       StringUtils.compare(this.getCustomerConfirmKey(), customer.getCustomerConfirmKey()),
+                       // ... next account status
+                       EnumUtils.compare(this.getCustomerAccountStatus(), customer.getCustomerAccountStatus())
                };
 
                // Check all values
index 220a205e4c0c8b7927f805f712d7c26469a8debf..8b401ef5589e8b48d9c00ffaac8110efe0e4fd65 100644 (file)
@@ -57,21 +57,6 @@ public enum CustomerAccountStatus implements Serializable {
         * @param styleClass CSS style class
         */
        private CustomerAccountStatus (final String messageKey, final String styleClass) {
-               // Validate parameter
-               if (null == messageKey) {
-                       // Throw NPE
-                       throw new NullPointerException("messageKey is null"); //NOI18N
-               } else if (messageKey.isEmpty()) {
-                       // Throw IAE
-                       throw new IllegalArgumentException("messageKey is empty"); //NOI18N
-               } else if (null == styleClass) {
-                       // Throw NPE
-                       throw new NullPointerException("styleClass is null"); //NOI18N
-               } else if (styleClass.isEmpty()) {
-                       // Throw IAE
-                       throw new IllegalArgumentException("styleClass is empty"); //NOI18N
-               }
-
                // Set it here
                this.messageKey = messageKey;
                this.styleClass = styleClass;