From 57474e2dab44f568243019d96d6edd4b2f6e6439 Mon Sep 17 00:00:00 2001 From: Eric Xu Date: Fri, 21 May 2021 00:33:11 -0400 Subject: [PATCH] Refactor and optimize equals MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove multiple casts of obj - Simply use object equals on the streams because PlayQueueItem’s equals already compares urls --- .../schabi/newpipe/player/playqueue/PlayQueue.java | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/playqueue/PlayQueue.java b/app/src/main/java/org/schabi/newpipe/player/playqueue/PlayQueue.java index 6131d8565..7cfc9fba1 100644 --- a/app/src/main/java/org/schabi/newpipe/player/playqueue/PlayQueue.java +++ b/app/src/main/java/org/schabi/newpipe/player/playqueue/PlayQueue.java @@ -500,22 +500,14 @@ public abstract class PlayQueue implements Serializable { * we don't have to do anything with new queue. * This method also gives a chance to track history of items in a queue in * VideoDetailFragment without duplicating items from two identical queues - * */ + */ @Override public boolean equals(@Nullable final Object obj) { - if (!(obj instanceof PlayQueue) - || getStreams().size() != ((PlayQueue) obj).getStreams().size()) { + if (!(obj instanceof PlayQueue)) { return false; } - final PlayQueue other = (PlayQueue) obj; - for (int i = 0; i < getStreams().size(); i++) { - if (!getItem(i).getUrl().equals(other.getItem(i).getUrl())) { - return false; - } - } - - return true; + return streams.equals(other.streams); } public boolean isDisposed() {