From 96d731dfc7e265cd0333499d70f6a13c3515e81c Mon Sep 17 00:00:00 2001 From: Eric Xu Date: Sat, 22 May 2021 00:06:59 -0400 Subject: [PATCH 01/10] Refactor equals method --- .../main/java/org/schabi/newpipe/settings/tabs/Tab.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) 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..faa5aeba9 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,11 @@ public abstract class Tab { @Override public boolean equals(final Object obj) { - if (obj == this) { - return true; + if (!(obj instanceof Tab)) { + return false; } - - return obj instanceof Tab && obj.getClass() == this.getClass() - && ((Tab) obj).getTabId() == this.getTabId(); + final Tab other = (Tab) obj; + return getTabId() == other.getTabId(); } /*////////////////////////////////////////////////////////////////////////// From 01aab25889aa0daabf3c476bcda0e1b12ee6dfd6 Mon Sep 17 00:00:00 2001 From: Eric Xu Date: Sat, 22 May 2021 00:07:56 -0400 Subject: [PATCH 02/10] Add Tab.hashCode() to go with equals --- app/src/main/java/org/schabi/newpipe/settings/tabs/Tab.java | 5 +++++ 1 file changed, 5 insertions(+) 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 faa5aeba9..ef683c033 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 @@ -119,6 +119,11 @@ public abstract class Tab { return getTabId() == other.getTabId(); } + @Override + public int hashCode() { + return Objects.hashCode(getTabId()); + } + /*////////////////////////////////////////////////////////////////////////// // JSON Handling //////////////////////////////////////////////////////////////////////////*/ From 1cac3895dccfe848bdbc1170dfd49873c4287e5f Mon Sep 17 00:00:00 2001 From: Eric Xu Date: Sat, 22 May 2021 00:13:17 -0400 Subject: [PATCH 03/10] Refactor KioskTab.equals --- .../main/java/org/schabi/newpipe/settings/tabs/Tab.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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 ef683c033..ae5cd5e9c 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 @@ -362,8 +362,13 @@ 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); } public int getKioskServiceId() { From d2b03afcf44a2e33720666afdad0b97cd7817b70 Mon Sep 17 00:00:00 2001 From: Eric Xu Date: Sat, 22 May 2021 00:13:49 -0400 Subject: [PATCH 04/10] Add KioskTab.hashCode() matching equals --- app/src/main/java/org/schabi/newpipe/settings/tabs/Tab.java | 5 +++++ 1 file changed, 5 insertions(+) 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 ae5cd5e9c..60d18747b 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 @@ -371,6 +371,11 @@ public abstract class Tab { && kioskId.equals(other.kioskId); } + @Override + public int hashCode() { + return Objects.hash(getTabId(), kioskServiceId, kioskId); + } + public int getKioskServiceId() { return kioskServiceId; } From 14bbaccb9f8fbe7f7f5716319078f547cfc28221 Mon Sep 17 00:00:00 2001 From: Eric Xu Date: Sat, 22 May 2021 00:22:44 -0400 Subject: [PATCH 05/10] Refactor ChannelTab.equals --- .../java/org/schabi/newpipe/settings/tabs/Tab.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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 60d18747b..f2aec4a12 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 @@ -446,9 +446,14 @@ 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); } public int getChannelServiceId() { From 1812249d3787464bed9796b694df7e08caec339a Mon Sep 17 00:00:00 2001 From: Eric Xu Date: Sat, 22 May 2021 00:23:32 -0400 Subject: [PATCH 06/10] Add ChannelTab.hashCode() matching equals --- app/src/main/java/org/schabi/newpipe/settings/tabs/Tab.java | 5 +++++ 1 file changed, 5 insertions(+) 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 f2aec4a12..ded5431a3 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 @@ -456,6 +456,11 @@ public abstract class Tab { && channelName.equals(other.channelName); } + @Override + public int hashCode() { + return Objects.hash(getTabId(), channelServiceId, channelUrl, channelName); + } + public int getChannelServiceId() { return channelServiceId; } From 2fc26bc154829e2f0848e7021fe850803f8f7d69 Mon Sep 17 00:00:00 2001 From: Eric Xu Date: Sat, 22 May 2021 00:34:19 -0400 Subject: [PATCH 07/10] Refactor PlaylistTab.equals --- .../org/schabi/newpipe/settings/tabs/Tab.java | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) 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 ded5431a3..7c72706f2 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 @@ -600,15 +600,22 @@ 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; + + if (!(super.equals(obj))) { + // Base objects are different + return false; + } + + return playlistServiceId == other.playlistServiceId // Remote + && playlistId == other.playlistId // Local + && playlistUrl.equals(other.playlistUrl) + && playlistName.equals(other.playlistName) + && playlistType == other.playlistType; } public int getPlaylistServiceId() { From 448989f32f73259aa164eb6319ccdc91bc67b91b Mon Sep 17 00:00:00 2001 From: Eric Xu Date: Sat, 22 May 2021 00:37:39 -0400 Subject: [PATCH 08/10] Add PlaylistTab.hashCode() matching equals --- .../java/org/schabi/newpipe/settings/tabs/Tab.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 7c72706f2..2e84c1e11 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 @@ -618,6 +618,18 @@ public abstract class Tab { && playlistType == other.playlistType; } + @Override + public int hashCode() { + return Objects.hash( + getTabId(), + playlistServiceId, + playlistId, + playlistUrl, + playlistName, + playlistType + ); + } + public int getPlaylistServiceId() { return playlistServiceId; } From 543440e38d83f79fa9e94ebf24bf6aea953ec300 Mon Sep 17 00:00:00 2001 From: Stypox Date: Tue, 8 Jun 2021 14:44:54 +0200 Subject: [PATCH 09/10] Update app/src/main/java/org/schabi/newpipe/settings/tabs/Tab.java --- app/src/main/java/org/schabi/newpipe/settings/tabs/Tab.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 2e84c1e11..2922e8942 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 @@ -611,7 +611,8 @@ public abstract class Tab { return false; } - return playlistServiceId == other.playlistServiceId // Remote + return super.equals(obj) + && playlistServiceId == other.playlistServiceId // Remote && playlistId == other.playlistId // Local && playlistUrl.equals(other.playlistUrl) && playlistName.equals(other.playlistName) From a2fd5ae20cd201b7e6bdfc6cf427d6cb3e0fb19a Mon Sep 17 00:00:00 2001 From: Stypox Date: Tue, 8 Jun 2021 14:45:00 +0200 Subject: [PATCH 10/10] Update app/src/main/java/org/schabi/newpipe/settings/tabs/Tab.java --- app/src/main/java/org/schabi/newpipe/settings/tabs/Tab.java | 5 ----- 1 file changed, 5 deletions(-) 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 2922e8942..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 @@ -606,11 +606,6 @@ public abstract class Tab { final PlaylistTab other = (PlaylistTab) obj; - if (!(super.equals(obj))) { - // Base objects are different - return false; - } - return super.equals(obj) && playlistServiceId == other.playlistServiceId // Remote && playlistId == other.playlistId // Local