From b0b0a75c87f7febb421842482a58175a8dd85233 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Thu, 25 Jun 2020 17:34:08 +0530 Subject: [PATCH] Use Collection.removeIf() instead of using Iterator.remove() to remove elements conditionally. --- .../fragments/list/channel/ChannelFragment.java | 8 +++----- .../fragments/list/search/SearchFragment.java | 14 +++----------- .../us/shandian/giga/service/DownloadManager.java | 10 +++------- 3 files changed, 9 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java index 8902834e4..58e28df49 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java @@ -50,7 +50,6 @@ import org.schabi.newpipe.util.ShareUtils; import org.schabi.newpipe.util.ThemeHelper; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import java.util.concurrent.TimeUnit; @@ -495,13 +494,12 @@ public class ChannelFragment extends BaseListInfoFragment // handling ContentNotSupportedException not to show the error but an appropriate string // so that crashes won't be sent uselessly and the user will understand what happened - for (Iterator it = errors.iterator(); it.hasNext();) { - final Throwable throwable = it.next(); + errors.removeIf(throwable -> { if (throwable instanceof ContentNotSupportedException) { showContentNotSupported(); - it.remove(); } - } + return throwable instanceof ContentNotSupportedException; + }); if (!errors.isEmpty()) { showSnackBarError(errors, UserAction.REQUESTED_CHANNEL, diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java index c402565fd..1e54176d4 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java @@ -61,7 +61,6 @@ import org.schabi.newpipe.util.ServiceHelper; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Queue; @@ -758,16 +757,9 @@ public class SearchFragment extends BaseListFragment iterator = networkResult.iterator(); - while (iterator.hasNext() && localResult.size() > 0) { - final SuggestionItem next = iterator.next(); - for (final SuggestionItem item : localResult) { - if (item.query.equals(next.query)) { - iterator.remove(); - break; - } - } - } + networkResult.removeIf(networkItem -> + localResult.stream().anyMatch(localItem -> + localItem.query.equals(networkItem.query))); if (networkResult.size() > 0) { result.addAll(networkResult); diff --git a/app/src/main/java/us/shandian/giga/service/DownloadManager.java b/app/src/main/java/us/shandian/giga/service/DownloadManager.java index 4c73fbfea..dc4d5701b 100644 --- a/app/src/main/java/us/shandian/giga/service/DownloadManager.java +++ b/app/src/main/java/us/shandian/giga/service/DownloadManager.java @@ -13,7 +13,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; -import java.util.Iterator; +import java.util.List; import us.shandian.giga.get.DownloadMission; import us.shandian.giga.get.FinishedMission; @@ -564,14 +564,10 @@ public class DownloadManager { synchronized (DownloadManager.this) { ArrayList pending = new ArrayList<>(mMissionsPending); ArrayList finished = new ArrayList<>(mMissionsFinished); - ArrayList remove = new ArrayList<>(hidden); + List remove = new ArrayList<>(hidden); // hide missions (if required) - Iterator iterator = remove.iterator(); - while (iterator.hasNext()) { - Mission mission = iterator.next(); - if (pending.remove(mission) || finished.remove(mission)) iterator.remove(); - } + remove.removeIf(mission -> pending.remove(mission) || finished.remove(mission)); int fakeTotal = pending.size(); if (fakeTotal > 0) fakeTotal++;