From b9e8ee8450c5222c80d42af59d1e9f197766be87 Mon Sep 17 00:00:00 2001 From: TobiGr Date: Sun, 21 Feb 2021 12:35:14 +0100 Subject: [PATCH] Rename BandcampExtractorHelper.smartConcatenate(String[], String) to Utils.nonEmptyAndNullJoin(String, String[]) --- .../extractors/BandcampExtractorHelper.java | 29 ------------------- .../extractors/BandcampStreamExtractor.java | 6 ++-- .../schabi/newpipe/extractor/utils/Utils.java | 13 +++++++++ 3 files changed, 17 insertions(+), 31 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampExtractorHelper.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampExtractorHelper.java index dad376d58..34bd3c6a2 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampExtractorHelper.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampExtractorHelper.java @@ -67,35 +67,6 @@ public class BandcampExtractorHelper { } - /** - * Concatenate all non-null and non-empty strings together while separating them using - * the comma parameter - */ - public static String smartConcatenate(final String[] strings, final String comma) { - final StringBuilder result = new StringBuilder(); - - // Remove empty strings - final List list = new ArrayList<>(Arrays.asList(strings)); - for (int i = list.size() - 1; i >= 0; i--) { - if (Utils.isNullOrEmpty(list.get(i)) || list.get(i).equals("null")) { - list.remove(i); - } - } - - // Append remaining strings to result - for (int i = 0; i < list.size(); i++) { - result.append(list.get(i)); - - if (i != list.size() - 1) { - // This is not the last iteration yet - result.append(comma); - } - - } - - return result.toString(); - } - /** * Fetch artist details from mobile endpoint. * diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampStreamExtractor.java index 005078a7a..99a19cecd 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampStreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampStreamExtractor.java @@ -17,6 +17,7 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.linkhandler.LinkHandler; import org.schabi.newpipe.extractor.localization.DateWrapper; import org.schabi.newpipe.extractor.stream.*; +import org.schabi.newpipe.extractor.utils.Utils; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -150,12 +151,13 @@ public class BandcampStreamExtractor extends StreamExtractor { @Nonnull @Override public Description getDescription() { - final String s = BandcampExtractorHelper.smartConcatenate( + final String s = Utils.nonEmptyAndNullJoin( + "\n\n", new String[]{ current.getString("about"), current.getString("lyrics"), current.getString("credits") - }, "\n\n" + } ); return new Description(s, Description.PLAIN_TEXT); } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/utils/Utils.java b/extractor/src/main/java/org/schabi/newpipe/extractor/utils/Utils.java index 721bc96c3..09574ab51 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/utils/Utils.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/utils/Utils.java @@ -271,4 +271,17 @@ public class Utils { return join(delimiter, list); } + /** + * Concatenate all non-null, non-empty and strings which are not equal to "null". + */ + public static String nonEmptyAndNullJoin(final String delimiter, final String[] elements) { + final List list = Arrays.asList(elements); + for (int i = list.size() - 1; i >= 0; i--) { + if (isNullOrEmpty(list.get(i)) || list.get(i).equals("null")) { + list.remove(i); + } + } + + return join(delimiter, list); + } }