Use List.isEmpty()

This commit is contained in:
TobiGr 2021-03-14 00:43:57 +01:00
parent af2183855a
commit e4c40ae6d1
9 changed files with 11 additions and 13 deletions

View File

@ -69,10 +69,8 @@ public class Response {
public String getHeader(String name) {
for (Map.Entry<String, List<String>> headerEntry : responseHeaders.entrySet()) {
final String key = headerEntry.getKey();
if (key != null && key.equalsIgnoreCase(name)) {
if (headerEntry.getValue().size() > 0) {
return headerEntry.getValue().get(0);
}
if (key != null && key.equalsIgnoreCase(name) && !headerEntry.getValue().isEmpty()) {
return headerEntry.getValue().get(0);
}
}

View File

@ -106,7 +106,7 @@ public class PlaylistInfo extends ListInfo<StreamInfoItem> {
info.addError(e);
}
// do not fail if everything but the uploader infos could be collected
if (uploaderParsingErrors.size() > 0 &&
if (!uploaderParsingErrors.isEmpty() &&
(!info.getErrors().isEmpty() || uploaderParsingErrors.size() < 3)) {
info.addAllErrors(uploaderParsingErrors);
}

View File

@ -87,7 +87,7 @@ public class BandcampSearchExtractor extends SearchExtractor {
// Count pages
final Elements pageLists = d.getElementsByClass("pagelist");
if (pageLists.size() == 0)
if (pageLists.isEmpty())
return new InfoItemsPage<>(collector, null);
final Elements pages = pageLists.first().getElementsByTag("li");
@ -96,7 +96,7 @@ public class BandcampSearchExtractor extends SearchExtractor {
int currentPage = -1;
for (int i = 0; i < pages.size(); i++) {
final Element pageElement = pages.get(i);
if (pageElement.getElementsByTag("span").size() > 0) {
if (!pageElement.getElementsByTag("span").isEmpty()) {
currentPage = i + 1;
break;
}

View File

@ -63,7 +63,7 @@ public class PeertubeService extends StreamingService {
public SearchExtractor getSearchExtractor(SearchQueryHandler queryHandler) {
final List<String> contentFilters = queryHandler.getContentFilters();
boolean external = false;
if (contentFilters.size() > 0 && contentFilters.get(0).startsWith("sepia_")) {
if (!contentFilters.isEmpty() && contentFilters.get(0).startsWith("sepia_")) {
external = true;
}
return new PeertubeSearchExtractor(this, queryHandler, external);

View File

@ -24,7 +24,7 @@ public class PeertubeSearchQueryHandlerFactory extends SearchQueryHandlerFactory
@Override
public String getUrl(String searchString, List<String> contentFilters, String sortFilter) throws ParsingException {
String baseUrl;
if (contentFilters.size() > 0 && contentFilters.get(0).startsWith("sepia_")) {
if (!contentFilters.isEmpty() && contentFilters.get(0).startsWith("sepia_")) {
baseUrl = SEPIA_BASE_URL;
} else {
baseUrl = ServiceList.PeerTube.getBaseUrl();

View File

@ -89,7 +89,7 @@ public class SoundcloudParsingHelper {
SoundcloudStreamExtractor e = (SoundcloudStreamExtractor) SoundCloud
.getStreamExtractor("https://soundcloud.com/liluzivert/do-what-i-want-produced-by-maaly-raw-don-cannon");
e.fetchPage();
return e.getAudioStreams().size() >= 1;
return !e.getAudioStreams().isEmpty();
} catch (Exception ignored) {
// No need to throw an exception here. If something went wrong, the client_id is wrong
return false;

View File

@ -83,7 +83,7 @@ public class SoundcloudSearchExtractor extends SearchExtractor {
throw new ParsingException("Could not parse json response", e);
}
if (searchCollection.size() == 0) {
if (searchCollection.isEmpty()) {
throw new SearchExtractor.NothingFoundException("Nothing found");
}
}

View File

@ -123,7 +123,7 @@ public class YoutubeService extends StreamingService {
public SearchExtractor getSearchExtractor(SearchQueryHandler query) {
final List<String> contentFilters = query.getContentFilters();
if (contentFilters.size() > 0 && contentFilters.get(0).startsWith("music_")) {
if (!contentFilters.isEmpty() && contentFilters.get(0).startsWith("music_")) {
return new YoutubeMusicSearchExtractor(this, query);
} else {
return new YoutubeSearchExtractor(this, query);

View File

@ -32,7 +32,7 @@ public class YoutubeSearchQueryHandlerFactory extends SearchQueryHandlerFactory
@Override
public String getUrl(String searchString, List<String> contentFilters, String sortFilter) throws ParsingException {
try {
if (contentFilters.size() > 0) {
if (!contentFilters.isEmpty()) {
switch (contentFilters.get(0)) {
case ALL:
default: