Use Objects.requireNonNull().
This commit is contained in:
parent
8c5f014a6f
commit
682a4263e5
|
@ -32,15 +32,8 @@ public class Request {
|
||||||
@Nullable final byte[] dataToSend,
|
@Nullable final byte[] dataToSend,
|
||||||
@Nullable final Localization localization,
|
@Nullable final Localization localization,
|
||||||
final boolean automaticLocalizationHeader) {
|
final boolean automaticLocalizationHeader) {
|
||||||
if (httpMethod == null) {
|
this.httpMethod = Objects.requireNonNull(httpMethod, "Request's httpMethod is null");
|
||||||
throw new IllegalArgumentException("Request's httpMethod is null");
|
this.url = Objects.requireNonNull(url, "Request's url is null");
|
||||||
}
|
|
||||||
if (url == null) {
|
|
||||||
throw new IllegalArgumentException("Request's url is null");
|
|
||||||
}
|
|
||||||
|
|
||||||
this.httpMethod = httpMethod;
|
|
||||||
this.url = url;
|
|
||||||
this.dataToSend = dataToSend;
|
this.dataToSend = dataToSend;
|
||||||
this.localization = localization;
|
this.localization = localization;
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,8 @@ package org.schabi.newpipe.extractor.linkhandler;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||||
import org.schabi.newpipe.extractor.utils.Utils;
|
import org.schabi.newpipe.extractor.utils.Utils;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Created by Christian Schabesberger on 26.07.16.
|
* Created by Christian Schabesberger on 26.07.16.
|
||||||
*
|
*
|
||||||
|
@ -72,9 +74,7 @@ public abstract class LinkHandlerFactory {
|
||||||
* @return a {@link LinkHandler} complete with information
|
* @return a {@link LinkHandler} complete with information
|
||||||
*/
|
*/
|
||||||
public LinkHandler fromUrl(final String url, final String baseUrl) throws ParsingException {
|
public LinkHandler fromUrl(final String url, final String baseUrl) throws ParsingException {
|
||||||
if (url == null) {
|
Objects.requireNonNull(url, "URL cannot be null");
|
||||||
throw new IllegalArgumentException("URL cannot be null");
|
|
||||||
}
|
|
||||||
if (!acceptUrl(url)) {
|
if (!acceptUrl(url)) {
|
||||||
throw new ParsingException("URL not accepted: " + url);
|
throw new ParsingException("URL not accepted: " + url);
|
||||||
}
|
}
|
||||||
|
@ -84,17 +84,13 @@ public abstract class LinkHandlerFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
public LinkHandler fromId(final String id) throws ParsingException {
|
public LinkHandler fromId(final String id) throws ParsingException {
|
||||||
if (id == null) {
|
Objects.requireNonNull(id, "ID cannot be null");
|
||||||
throw new IllegalArgumentException("id can not be null");
|
|
||||||
}
|
|
||||||
final String url = getUrl(id);
|
final String url = getUrl(id);
|
||||||
return new LinkHandler(url, url, id);
|
return new LinkHandler(url, url, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public LinkHandler fromId(final String id, final String baseUrl) throws ParsingException {
|
public LinkHandler fromId(final String id, final String baseUrl) throws ParsingException {
|
||||||
if (id == null) {
|
Objects.requireNonNull(id, "ID cannot be null");
|
||||||
throw new IllegalArgumentException("id can not be null");
|
|
||||||
}
|
|
||||||
final String url = getUrl(id, baseUrl);
|
final String url = getUrl(id, baseUrl);
|
||||||
return new LinkHandler(url, url, id);
|
return new LinkHandler(url, url, id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import org.schabi.newpipe.extractor.utils.Utils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public abstract class ListLinkHandlerFactory extends LinkHandlerFactory {
|
public abstract class ListLinkHandlerFactory extends LinkHandlerFactory {
|
||||||
|
|
||||||
|
@ -35,10 +36,7 @@ public abstract class ListLinkHandlerFactory extends LinkHandlerFactory {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ListLinkHandler fromUrl(final String url, final String baseUrl) throws ParsingException {
|
public ListLinkHandler fromUrl(final String url, final String baseUrl) throws ParsingException {
|
||||||
if (url == null) {
|
Objects.requireNonNull(url, "URL may not be null");
|
||||||
throw new IllegalArgumentException("url may not be null");
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ListLinkHandler(super.fromUrl(url, baseUrl));
|
return new ListLinkHandler(super.fromUrl(url, baseUrl));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue