From 4c0580363f578a46641a7121ef147ce7032980e9 Mon Sep 17 00:00:00 2001 From: Stephan Fuhrmann Date: Sun, 7 Jan 2024 19:21:14 +0100 Subject: [PATCH] Fix checkstyle findings --- .../radiobrowser4j/EndpointDiscovery.java | 8 ++- .../sfuhrm/radiobrowser4j/RadioBrowser.java | 23 +++++--- .../de/sfuhrm/radiobrowser4j/RestImpl.java | 52 +++++++++++++------ 3 files changed, 60 insertions(+), 23 deletions(-) diff --git a/radiobrowser4j/src/main/java/de/sfuhrm/radiobrowser4j/EndpointDiscovery.java b/radiobrowser4j/src/main/java/de/sfuhrm/radiobrowser4j/EndpointDiscovery.java index f6d72d93..fecc4664 100644 --- a/radiobrowser4j/src/main/java/de/sfuhrm/radiobrowser4j/EndpointDiscovery.java +++ b/radiobrowser4j/src/main/java/de/sfuhrm/radiobrowser4j/EndpointDiscovery.java @@ -161,7 +161,13 @@ Stats getStats(final String endpoint, final int timeout) { + timeout); } - RestImpl rest = new RestImpl(URI.create(endpoint), timeout, proxyUri, proxyUser, proxyPassword, userAgent); + RestImpl rest = new RestImpl( + URI.create(endpoint), + timeout, + proxyUri, + proxyUser, + proxyPassword, + userAgent); return rest.get("json/stats", Stats.class); } diff --git a/radiobrowser4j/src/main/java/de/sfuhrm/radiobrowser4j/RadioBrowser.java b/radiobrowser4j/src/main/java/de/sfuhrm/radiobrowser4j/RadioBrowser.java index c0f0cbf4..9f9be567 100644 --- a/radiobrowser4j/src/main/java/de/sfuhrm/radiobrowser4j/RadioBrowser.java +++ b/radiobrowser4j/src/main/java/de/sfuhrm/radiobrowser4j/RadioBrowser.java @@ -103,7 +103,13 @@ public RadioBrowser(@NonNull final String apiUrl, + timeout); } this.userAgent = myUserAgent; - rest = new RestImpl(URI.create(apiUrl), timeout, proxyUri, proxyUser, proxyPassword, myUserAgent); + rest = new RestImpl( + URI.create(apiUrl), + timeout, + proxyUri, + proxyUser, + proxyPassword, + myUserAgent); } /** @@ -134,7 +140,7 @@ private Map retrieveValueStationCountList( List> map = rest.post(subPath, Collections.emptyMap(), - new GenericType>>() {}); + new GenericType>>() { }); return map.stream() .collect(Collectors.toMap( m -> m.get("name"), @@ -222,7 +228,7 @@ private List listStationsPathWithLimit( return rest.post(myPath, requestParams, - new GenericType>() {}); + new GenericType>() { }); } /** Get a list of all stations. Will return a single batch. @@ -416,10 +422,13 @@ public List listStationsBy(@NonNull final Paging paging, paging.apply(requestParams); Arrays.stream(listParam).forEach(l -> l.apply(requestParams)); - String path = RestImpl.paths("json/stations", searchMode.name().toLowerCase(), searchTerm); + String path = RestImpl.paths( + "json/stations", + searchMode.name().toLowerCase(), + searchTerm); return rest.post(path, requestParams, - new GenericType>() {}); + new GenericType>() { }); } /** Get a stream of stations matching a certain search criteria. @@ -445,7 +454,7 @@ public Stream listStationsBy( return rest.post(path, requestParams, - new GenericType>() {}); + new GenericType>() { }); }; return StreamSupport.stream( @@ -559,7 +568,7 @@ private UUID postNewOrEditStation(@NonNull final Station station, UrlResponse urlResponse = rest.post(path, requestParams, - new GenericType() {}); + new GenericType() { }); if (log.isDebugEnabled()) { log.debug("Result: {}", urlResponse); diff --git a/radiobrowser4j/src/main/java/de/sfuhrm/radiobrowser4j/RestImpl.java b/radiobrowser4j/src/main/java/de/sfuhrm/radiobrowser4j/RestImpl.java index 647a64cc..e25ebc4a 100644 --- a/radiobrowser4j/src/main/java/de/sfuhrm/radiobrowser4j/RestImpl.java +++ b/radiobrowser4j/src/main/java/de/sfuhrm/radiobrowser4j/RestImpl.java @@ -23,20 +23,37 @@ import java.util.stream.Collectors; @Slf4j -public class RestImpl { - private Client client; +final class RestImpl { - private URI endpoint; + /** The internal jax-rs client to use. */ + private final Client client; - private String userAgent; + /** The URI of the API endpoint. All paths are relative to this one. */ + private final URI endpoint; - RestImpl(URI endpoint, int timeout, String proxyUri, String proxyUser, String proxyPassword, String userAgent) { - this.endpoint = endpoint; - client = newClient(timeout, - proxyUri, - proxyUser, - proxyPassword); - this.userAgent = userAgent; + /** The String of the user agent to identify with. */ + private final String userAgent; + + /** Create a new instance. + * @param inEndpoint the API endpoint URI address. + * @param inTimeout the timeout in millis. + * @param inProxyUri the optional proxy URI. + * @param inProxyUser the optional proxy user. + * @param inProxyPassword the optional proxy password. + * @param inUserAgent the mandatory user agent string to send. + * */ + RestImpl(final URI inEndpoint, + final int inTimeout, + final String inProxyUri, + final String inProxyUser, + final String inProxyPassword, + final String inUserAgent) { + this.endpoint = inEndpoint; + client = newClient(inTimeout, + inProxyUri, + inProxyUser, + inProxyPassword); + this.userAgent = inUserAgent; } /** Create a new JAX-RS client. @@ -74,16 +91,17 @@ private static Client newClient(final int timeout, * @param components the components to compose. * @return the joint path. * */ - static String paths(String...components) { + static String paths(final String...components) { return Arrays.stream(components).collect(Collectors.joining("/")); } /** Sends a GET request to the remote server. * @param path the path on the web server. * @param resultClass the result class to retrieve. + * @param the expected return type. * @return an instance of the result class. * */ - T get(String path, Class resultClass) { + T get(final String path, final Class resultClass) { WebTarget webTarget = client.target(endpoint); return webTarget.path(path) .request(MediaType.APPLICATION_JSON_TYPE) @@ -98,11 +116,15 @@ T get(String path, Class resultClass) { * @param path the path on the web server. * @param requestParams the request parameters to send as the POST body in * "application/x-www-form-urlencoded" encoding. - * @param resultClass the expected resulting class wrapped in a generic type. + * @param resultClass the expected resulting class wrapped in a + * generic type. + * @param the expected return type. * @return the resulting type. * @throws RadioBrowserException if the sever sent a non-OK response. * */ - T post(String path, Map requestParams, GenericType resultClass) { + T post(final String path, + final Map requestParams, + final GenericType resultClass) { Entity
entity = Entity.form( new MultivaluedHashMap<>(requestParams)); WebTarget webTarget = client.target(endpoint);