Add missing equals() and hashCode() methods for class that implements Comparable<T>
This commit is contained in:
parent
406af6e699
commit
b9320522c7
@ -101,4 +101,47 @@ public class HistoryItem implements Comparable<HistoryItem> {
|
|||||||
public int compareTo(HistoryItem another) {
|
public int compareTo(HistoryItem another) {
|
||||||
return mTitle.compareTo(another.mTitle);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user