Use Collection.removeIf() instead of using Iterator.remove() to remove elements conditionally.
This commit is contained in:
parent
abcacf8c74
commit
b0b0a75c87
|
@ -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<ChannelInfo>
|
|||
|
||||
// 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<Throwable> 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,
|
||||
|
|
|
@ -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<SearchInfo, ListExtractor.I
|
|||
}
|
||||
|
||||
// Remove duplicates
|
||||
final Iterator<SuggestionItem> 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);
|
||||
|
|
|
@ -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<Mission> pending = new ArrayList<>(mMissionsPending);
|
||||
ArrayList<Mission> finished = new ArrayList<>(mMissionsFinished);
|
||||
ArrayList<Mission> remove = new ArrayList<>(hidden);
|
||||
List<Mission> remove = new ArrayList<>(hidden);
|
||||
|
||||
// hide missions (if required)
|
||||
Iterator<Mission> 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++;
|
||||
|
|
Loading…
Reference in New Issue