Make improvements to methods using toArray().
This commit is contained in:
parent
fc8b5ebbc6
commit
7daca10a06
|
@ -1,5 +1,7 @@
|
||||||
package org.schabi.newpipe.extractor.kiosk;
|
package org.schabi.newpipe.extractor.kiosk;
|
||||||
|
|
||||||
|
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
||||||
|
|
||||||
import org.schabi.newpipe.extractor.NewPipe;
|
import org.schabi.newpipe.extractor.NewPipe;
|
||||||
import org.schabi.newpipe.extractor.Page;
|
import org.schabi.newpipe.extractor.Page;
|
||||||
import org.schabi.newpipe.extractor.StreamingService;
|
import org.schabi.newpipe.extractor.StreamingService;
|
||||||
|
@ -8,13 +10,12 @@ import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
|
||||||
import org.schabi.newpipe.extractor.localization.ContentCountry;
|
import org.schabi.newpipe.extractor.localization.ContentCountry;
|
||||||
import org.schabi.newpipe.extractor.localization.Localization;
|
import org.schabi.newpipe.extractor.localization.Localization;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class KioskList {
|
public class KioskList {
|
||||||
|
|
||||||
|
@ -78,10 +79,10 @@ public class KioskList {
|
||||||
if (!isNullOrEmpty(defaultKiosk)) {
|
if (!isNullOrEmpty(defaultKiosk)) {
|
||||||
return getExtractorById(defaultKiosk, nextPage, localization);
|
return getExtractorById(defaultKiosk, nextPage, localization);
|
||||||
} else {
|
} else {
|
||||||
if (!kioskList.isEmpty()) {
|
final String first = kioskList.keySet().stream().findAny().orElse(null);
|
||||||
|
if (first != null) {
|
||||||
// if not set get any entry
|
// if not set get any entry
|
||||||
final Object[] keySet = kioskList.keySet().toArray();
|
return getExtractorById(first, nextPage, localization);
|
||||||
return getExtractorById(keySet[0].toString(), nextPage, localization);
|
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,23 +20,18 @@
|
||||||
|
|
||||||
package org.schabi.newpipe.extractor.utils;
|
package org.schabi.newpipe.extractor.utils;
|
||||||
|
|
||||||
import org.nibor.autolink.LinkExtractor;
|
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
|
||||||
import org.nibor.autolink.LinkSpan;
|
|
||||||
import org.nibor.autolink.LinkType;
|
|
||||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.EnumSet;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Avoid using regex !!!
|
* Avoid using regex !!!
|
||||||
|
@ -111,24 +106,4 @@ public final class Parser {
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
public static String[] getLinksFromString(final String txt) throws ParsingException {
|
|
||||||
try {
|
|
||||||
final List<String> links = new ArrayList<>();
|
|
||||||
final LinkExtractor linkExtractor = LinkExtractor.builder()
|
|
||||||
.linkTypes(EnumSet.of(LinkType.URL, LinkType.WWW))
|
|
||||||
.build();
|
|
||||||
final Iterable<LinkSpan> linkSpans = linkExtractor.extractLinks(txt);
|
|
||||||
for (final LinkSpan ls : linkSpans) {
|
|
||||||
links.add(txt.substring(ls.getBeginIndex(), ls.getEndIndex()));
|
|
||||||
}
|
|
||||||
|
|
||||||
String[] linksarray = new String[links.size()];
|
|
||||||
linksarray = links.toArray(linksarray);
|
|
||||||
return linksarray;
|
|
||||||
} catch (final Exception e) {
|
|
||||||
throw new ParsingException("Could not get links from string", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue