From: Roland Haeder Date: Wed, 24 Feb 2016 16:28:59 +0000 (+0100) Subject: added equals()/hashCode() for easier checking X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=2f41e66470201a3057be8757cc53f737d53e2c82;p=jshop-core.git added equals()/hashCode() for easier checking --- 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;