From b8f64595a24cbd41f5d19f8e72e2c959f6787606 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Mon, 19 Oct 2020 16:52:21 +0530 Subject: [PATCH 1/3] Use Objects' static equals() and hashCode() methods. --- .../newpipe/extractor/localization/Localization.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/localization/Localization.java b/extractor/src/main/java/org/schabi/newpipe/extractor/localization/Localization.java index 02b890870..a3af889ac 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/localization/Localization.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/localization/Localization.java @@ -7,6 +7,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Locale; +import java.util.Objects; public class Localization implements Serializable { public static final Localization DEFAULT = new Localization("en", "GB"); @@ -89,14 +90,14 @@ public class Localization implements Serializable { Localization that = (Localization) o; - if (!languageCode.equals(that.languageCode)) return false; - return countryCode != null ? countryCode.equals(that.countryCode) : that.countryCode == null; + return languageCode.equals(that.languageCode) && + Objects.equals(countryCode, that.countryCode); } @Override public int hashCode() { int result = languageCode.hashCode(); - result = 31 * result + (countryCode != null ? countryCode.hashCode() : 0); + result = 31 * result + Objects.hashCode(countryCode); return result; } } From 4c19a88612ec315cd1234551f70ce168a3a6cb48 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Mon, 19 Oct 2020 17:17:41 +0530 Subject: [PATCH 2/3] Use Objects.toString(). --- .../services/youtube/extractors/YoutubeStreamExtractor.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java index 608ae47cd..5eaf80852 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java @@ -55,6 +55,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Objects; import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.fixThumbnailUrl; import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getJsonResponse; @@ -861,7 +862,7 @@ public class YoutubeStreamExtractor extends StreamExtractor { } finally { Context.exit(); } - return result == null ? "" : result.toString(); + return Objects.toString(result, ""); } /*////////////////////////////////////////////////////////////////////////// From 57be1f1123e7b3707ab8a98a0a4cddfd1dcce4c1 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Mon, 19 Oct 2020 17:43:34 +0530 Subject: [PATCH 3/3] Use Objects.requireNonNull(). --- .../java/org/schabi/newpipe/extractor/Extractor.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/Extractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/Extractor.java index df1c22617..9389e255d 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/Extractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/Extractor.java @@ -11,6 +11,7 @@ import org.schabi.newpipe.extractor.localization.TimeAgoParser; import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.io.IOException; +import java.util.Objects; public abstract class Extractor { /** @@ -29,12 +30,9 @@ public abstract class Extractor { private final Downloader downloader; public Extractor(final StreamingService service, final LinkHandler linkHandler) { - if (service == null) throw new NullPointerException("service is null"); - if (linkHandler == null) throw new NullPointerException("LinkHandler is null"); - this.service = service; - this.linkHandler = linkHandler; - this.downloader = NewPipe.getDownloader(); - if (downloader == null) throw new NullPointerException("downloader is null"); + this.service = Objects.requireNonNull(service, "service is null"); + this.linkHandler = Objects.requireNonNull(linkHandler, "LinkHandler is null"); + this.downloader = Objects.requireNonNull(NewPipe.getDownloader(), "downloader is null"); } /**