diff --git a/app/src/main/java/org/schabi/newpipe/settings/tabs/Tab.java b/app/src/main/java/org/schabi/newpipe/settings/tabs/Tab.java index b289009ce..a148255b3 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/tabs/Tab.java +++ b/app/src/main/java/org/schabi/newpipe/settings/tabs/Tab.java @@ -112,12 +112,16 @@ public abstract class Tab { @Override public boolean equals(final Object obj) { - if (obj == this) { - return true; + if (!(obj instanceof Tab)) { + return false; } + final Tab other = (Tab) obj; + return getTabId() == other.getTabId(); + } - return obj instanceof Tab && obj.getClass() == this.getClass() - && ((Tab) obj).getTabId() == this.getTabId(); + @Override + public int hashCode() { + return Objects.hashCode(getTabId()); } /*////////////////////////////////////////////////////////////////////////// @@ -358,8 +362,18 @@ public abstract class Tab { @Override public boolean equals(final Object obj) { - return super.equals(obj) && kioskServiceId == ((KioskTab) obj).kioskServiceId - && Objects.equals(kioskId, ((KioskTab) obj).kioskId); + if (!(obj instanceof KioskTab)) { + return false; + } + final KioskTab other = (KioskTab) obj; + return super.equals(obj) + && kioskServiceId == other.kioskServiceId + && kioskId.equals(other.kioskId); + } + + @Override + public int hashCode() { + return Objects.hash(getTabId(), kioskServiceId, kioskId); } public int getKioskServiceId() { @@ -432,9 +446,19 @@ public abstract class Tab { @Override public boolean equals(final Object obj) { - return super.equals(obj) && channelServiceId == ((ChannelTab) obj).channelServiceId - && Objects.equals(channelUrl, ((ChannelTab) obj).channelUrl) - && Objects.equals(channelName, ((ChannelTab) obj).channelName); + if (!(obj instanceof ChannelTab)) { + return false; + } + final ChannelTab other = (ChannelTab) obj; + return super.equals(obj) + && channelServiceId == other.channelServiceId + && channelUrl.equals(other.channelName) + && channelName.equals(other.channelName); + } + + @Override + public int hashCode() { + return Objects.hash(getTabId(), channelServiceId, channelUrl, channelName); } public int getChannelServiceId() { @@ -576,15 +600,30 @@ public abstract class Tab { @Override public boolean equals(final Object obj) { - if (!(super.equals(obj) - && Objects.equals(playlistType, ((PlaylistTab) obj).playlistType) - && Objects.equals(playlistName, ((PlaylistTab) obj).playlistName))) { - return false; // base objects are different + if (!(obj instanceof PlaylistTab)) { + return false; } - return (playlistId == ((PlaylistTab) obj).playlistId) // local - || (playlistServiceId == ((PlaylistTab) obj).playlistServiceId // remote - && Objects.equals(playlistUrl, ((PlaylistTab) obj).playlistUrl)); + final PlaylistTab other = (PlaylistTab) obj; + + return super.equals(obj) + && playlistServiceId == other.playlistServiceId // Remote + && playlistId == other.playlistId // Local + && playlistUrl.equals(other.playlistUrl) + && playlistName.equals(other.playlistName) + && playlistType == other.playlistType; + } + + @Override + public int hashCode() { + return Objects.hash( + getTabId(), + playlistServiceId, + playlistId, + playlistUrl, + playlistName, + playlistType + ); } public int getPlaylistServiceId() {