Skip to content

Commit

Permalink
Fix checkstyle findings
Browse files Browse the repository at this point in the history
  • Loading branch information
sfuhrm committed Jan 7, 2024
1 parent f5da60c commit 4c05803
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -134,7 +140,7 @@ private Map<String, Integer> retrieveValueStationCountList(

List<Map<String, String>> map =
rest.post(subPath, Collections.emptyMap(),
new GenericType<List<Map<String, String>>>() {});
new GenericType<List<Map<String, String>>>() { });
return map.stream()
.collect(Collectors.toMap(
m -> m.get("name"),
Expand Down Expand Up @@ -222,7 +228,7 @@ private List<Station> listStationsPathWithLimit(

return rest.post(myPath,
requestParams,
new GenericType<List<Station>>() {});
new GenericType<List<Station>>() { });
}

/** Get a list of all stations. Will return a single batch.
Expand Down Expand Up @@ -416,10 +422,13 @@ public List<Station> 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<List<Station>>() {});
new GenericType<List<Station>>() { });
}

/** Get a stream of stations matching a certain search criteria.
Expand All @@ -445,7 +454,7 @@ public Stream<Station> listStationsBy(

return rest.post(path,
requestParams,
new GenericType<List<Station>>() {});
new GenericType<List<Station>>() { });
};

return StreamSupport.stream(
Expand Down Expand Up @@ -559,7 +568,7 @@ private UUID postNewOrEditStation(@NonNull final Station station,

UrlResponse urlResponse = rest.post(path,
requestParams,
new GenericType<UrlResponse>() {});
new GenericType<UrlResponse>() { });

if (log.isDebugEnabled()) {
log.debug("Result: {}", urlResponse);
Expand Down
52 changes: 37 additions & 15 deletions radiobrowser4j/src/main/java/de/sfuhrm/radiobrowser4j/RestImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 <T> the expected return type.
* @return an instance of the result class.
* */
<T> T get(String path, Class<T> resultClass) {
<T> T get(final String path, final Class<T> resultClass) {
WebTarget webTarget = client.target(endpoint);
return webTarget.path(path)
.request(MediaType.APPLICATION_JSON_TYPE)
Expand All @@ -98,11 +116,15 @@ <T> T get(String path, Class<T> 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 <T> the expected return type.
* @return the resulting type.
* @throws RadioBrowserException if the sever sent a non-OK response.
* */
<T> T post(String path, Map<String, String> requestParams, GenericType<T> resultClass) {
<T> T post(final String path,
final Map<String, String> requestParams,
final GenericType<T> resultClass) {
Entity<Form> entity = Entity.form(
new MultivaluedHashMap<>(requestParams));
WebTarget webTarget = client.target(endpoint);
Expand Down

0 comments on commit 4c05803

Please sign in to comment.