From: Roland Haeder Date: Wed, 24 Feb 2016 16:34:13 +0000 (+0100) Subject: added equals()/hashCode() for easier checking X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=06a8e12521b8a738b56193c7ab5072f3c2a75271;p=jshop-core.git added equals()/hashCode() for easier checking --- diff --git a/src/org/mxchange/jshopcore/model/product/GenericProduct.java b/src/org/mxchange/jshopcore/model/product/GenericProduct.java index b36637c..8a3fedb 100644 --- a/src/org/mxchange/jshopcore/model/product/GenericProduct.java +++ b/src/org/mxchange/jshopcore/model/product/GenericProduct.java @@ -133,6 +133,33 @@ public class GenericProduct implements Product, Comparable { this.setProductTitle(product.getProductTitle()); } + @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 Product other = (Product) obj; + + if (!Objects.equals(this.getProductTitle(), other.getProductTitle())) { + return false; + } + + return Objects.equals(this.getProductId(), other.getProductId()); + } + + @Override + public int hashCode () { + int hash = 7; + hash = 23 * hash + Objects.hashCode(this.getProductId()); + hash = 23 * hash + Objects.hashCode(this.getProductTitle()); + return hash; + } + @Override public Boolean getProductAvailability () { return this.productAvailability; diff --git a/src/org/mxchange/jshopcore/model/product/Product.java b/src/org/mxchange/jshopcore/model/product/Product.java index d6a2bb5..88d2261 100644 --- a/src/org/mxchange/jshopcore/model/product/Product.java +++ b/src/org/mxchange/jshopcore/model/product/Product.java @@ -102,4 +102,10 @@ public interface Product extends Serializable { * @param productTitle the title to set */ void setProductTitle (final String productTitle); + + @Override + boolean equals (final Object object); + + @Override + int hashCode (); }