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) { public String getHeader(String name) {
for (Map.Entry<String, List<String>> headerEntry : responseHeaders.entrySet()) { for (Map.Entry<String, List<String>> headerEntry : responseHeaders.entrySet()) {
final String key = headerEntry.getKey(); final String key = headerEntry.getKey();
if (key != null && key.equalsIgnoreCase(name)) { if (key != null && key.equalsIgnoreCase(name) && !headerEntry.getValue().isEmpty()) {
if (headerEntry.getValue().size() > 0) { return headerEntry.getValue().get(0);
return headerEntry.getValue().get(0);
}
} }
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -123,7 +123,7 @@ public class YoutubeService extends StreamingService {
public SearchExtractor getSearchExtractor(SearchQueryHandler query) { public SearchExtractor getSearchExtractor(SearchQueryHandler query) {
final List<String> contentFilters = query.getContentFilters(); 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); return new YoutubeMusicSearchExtractor(this, query);
} else { } else {
return new YoutubeSearchExtractor(this, query); return new YoutubeSearchExtractor(this, query);

View File

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