From b9320522c7eaa28b3537d37d079e085d080439be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C5=82osz=20Sieradzki?= Date: Fri, 25 Jul 2014 19:34:49 +0200 Subject: [PATCH] Add missing equals() and hashCode() methods for class that implements Comparable --- src/acr/browser/lightning/HistoryItem.java | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/acr/browser/lightning/HistoryItem.java b/src/acr/browser/lightning/HistoryItem.java index 66aded0..90b30a2 100644 --- a/src/acr/browser/lightning/HistoryItem.java +++ b/src/acr/browser/lightning/HistoryItem.java @@ -101,4 +101,47 @@ public class HistoryItem implements Comparable { public int compareTo(HistoryItem another) { return mTitle.compareTo(another.mTitle); } + + @Override + public boolean equals(Object o) { + + if (this == o) { + return true; + } + if (o == null || ((Object) this).getClass() != o.getClass()) { + return false; + } + + HistoryItem that = (HistoryItem) o; + + if (mId != that.mId) { + return false; + } + if (mImageId != that.mImageId) { + return false; + } + if (mBitmap != null ? !mBitmap.equals(that.mBitmap) : that.mBitmap != null) { + return false; + } + if (!mTitle.equals(that.mTitle)) { + return false; + } + if (!mUrl.equals(that.mUrl)) { + return false; + } + + return true; + } + + @Override + public int hashCode() { + + int result = mId; + result = 31 * result + mUrl.hashCode(); + result = 31 * result + mTitle.hashCode(); + result = 31 * result + (mBitmap != null ? mBitmap.hashCode() : 0); + result = 31 * result + mImageId; + + return result; + } }