Rename BandcampExtractorHelper.smartConcatenate(String[], String) to Utils.nonEmptyAndNullJoin(String, String[])
This commit is contained in:
parent
c07db80ef0
commit
b9e8ee8450
|
@ -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<String> 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.
|
||||
* <a href=https://notabug.org/fynngodau/bandcampDirect/wiki/rewindBandcamp+%E2%80%93+Fetching+artist+details>
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -271,4 +271,17 @@ public class Utils {
|
|||
return join(delimiter, list);
|
||||
}
|
||||
|
||||
/**
|
||||
* Concatenate all non-null, non-empty and strings which are not equal to <code>"null"</code>.
|
||||
*/
|
||||
public static String nonEmptyAndNullJoin(final String delimiter, final String[] elements) {
|
||||
final List<String> 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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue