From 2f41e66470201a3057be8757cc53f737d53e2c82 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Wed, 24 Feb 2016 17:28:59 +0100 Subject: [PATCH] added equals()/hashCode() for easier checking --- .../jshopcore/model/customer/Customer.java | 6 ++++ .../model/customer/ShopCustomer.java | 31 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/org/mxchange/jshopcore/model/customer/Customer.java b/src/org/mxchange/jshopcore/model/customer/Customer.java index 9ac6ae6..d2bd2b3 100644 --- a/src/org/mxchange/jshopcore/model/customer/Customer.java +++ b/src/org/mxchange/jshopcore/model/customer/Customer.java @@ -146,4 +146,10 @@ public interface Customer extends Serializable { * @param customerStatus Account status */ void setCustomerAccountStatus (final CustomerAccountStatus customerStatus); + + @Override + boolean equals (final Object object); + + @Override + int hashCode (); } diff --git a/src/org/mxchange/jshopcore/model/customer/ShopCustomer.java b/src/org/mxchange/jshopcore/model/customer/ShopCustomer.java index 3eb53cc..4fe55ce 100644 --- a/src/org/mxchange/jshopcore/model/customer/ShopCustomer.java +++ b/src/org/mxchange/jshopcore/model/customer/ShopCustomer.java @@ -17,6 +17,7 @@ package org.mxchange.jshopcore.model.customer; import java.util.Calendar; +import java.util.Objects; import javax.persistence.Basic; import javax.persistence.CascadeType; import javax.persistence.Column; @@ -130,6 +131,36 @@ public class ShopCustomer implements Customer, Comparable { this.setCustomerLocked(customer.getCustomerLocked()); } + @Override + public boolean equals (final Object obj) { + if (this == obj) { + return true; + } else if (obj == null) { + return false; + } else if (this.getClass() != obj.getClass()) { + return false; + } + + final Customer other = (Customer) obj; + + if (!Objects.equals(this.getCustomerNumber(), other.getCustomerNumber())) { + return false; + } else if (!Objects.equals(this.getContact(), other.getContact())) { + return false; + } + + return Objects.equals(this.getContact(), other.getContact()); + } + + @Override + public int hashCode () { + int hash = 3; + hash = 17 * hash + Objects.hashCode(this.getContact()); + hash = 17 * hash + Objects.hashCode(this.getCustomerId()); + hash = 17 * hash + Objects.hashCode(this.getCustomerNumber()); + return hash; + } + @Override public Contact getContact () { return this.contact; -- 2.39.5