@@ -34,27 +34,27 @@ public class OpenLibraryRestClient implements OpenLibraryClient {
3434 private final RestClient restClient ;
3535 @ Value ("${openlibrary.result-size:10}" )
3636 private int resultLimit ;
37-
37+
3838 public OpenLibraryRestClient (RestClient restClient ) {
3939 this .restClient = restClient ;
4040 }
41-
41+
4242 @ Override
4343 public Response apply (Request request ) {
4444 var authorOpt = this .createParamOpt (request .author (), "author" );
4545 var titleOpt = this .createParamOpt (request .title (), "title" );
4646 var subjectOpt = this .createParamOpt (request .subject (), "subject" );
47- var paramsStr = List .of (authorOpt , titleOpt , subjectOpt ).stream ()
48- .filter (Optional ::isPresent ).map (Optional ::get ).collect (Collectors .joining ("&" ));
49- var urlStr =
50- String .format ("%s?%s&limit=%d" , this .baseUrl , paramsStr , this .resultLimit );
47+ var paramsStr = List .of (authorOpt , titleOpt , subjectOpt ).stream ().flatMap (Optional ::stream )
48+ .collect (Collectors .joining ("&" ));
49+ var urlStr = String .format ("%s?%s&limit=%d" , this .baseUrl , paramsStr , this .resultLimit );
5150 LOGGER .info (urlStr );
5251 var response = this .restClient .get ().uri (urlStr ).retrieve ().body (Response .class );
5352 return response ;
5453 }
5554
5655 private Optional <String > createParamOpt (String valueStr , String keyStr ) {
5756 return Optional .ofNullable (valueStr ).stream ().filter (Predicate .not (String ::isBlank ))
58- .map (myAuthor -> String .format ("%s=%s" , keyStr , URLEncoder .encode (myAuthor , StandardCharsets .UTF_8 ))).findFirst ();
57+ .map (myAuthor -> String .format ("%s=%s" , keyStr , URLEncoder .encode (myAuthor , StandardCharsets .UTF_8 )))
58+ .findFirst ();
5959 }
6060}
0 commit comments