From c47a83a0b4c0234a20f2ecb374f69a0bdbc58eab Mon Sep 17 00:00:00 2001 From: Sashir Estela Date: Sat, 18 Jan 2025 03:05:30 +0000 Subject: [PATCH] Fixing code style in examples --- .../example/ResponseInterceptorExample.java | 77 +++++++++---------- .../example/jsonplaceholder/UserService.java | 4 +- 2 files changed, 40 insertions(+), 41 deletions(-) diff --git a/src/example/java/io/github/sashirestela/cleverclient/example/ResponseInterceptorExample.java b/src/example/java/io/github/sashirestela/cleverclient/example/ResponseInterceptorExample.java index 975573c..479352c 100644 --- a/src/example/java/io/github/sashirestela/cleverclient/example/ResponseInterceptorExample.java +++ b/src/example/java/io/github/sashirestela/cleverclient/example/ResponseInterceptorExample.java @@ -1,13 +1,13 @@ package io.github.sashirestela.cleverclient.example; +import io.github.sashirestela.cleverclient.CleverClient; +import io.github.sashirestela.cleverclient.example.jsonplaceholder.UserService; + import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; -import io.github.sashirestela.cleverclient.CleverClient; -import io.github.sashirestela.cleverclient.example.jsonplaceholder.UserService; - public class ResponseInterceptorExample extends AbstractExample { public ResponseInterceptorExample(String clientAlias) { @@ -38,55 +38,54 @@ public void run() { private String transformUsers(String jsonInput) { List flatUsers = new ArrayList<>(); - + // Simpler pattern that matches each field individually - String patternStr = - "\"id\":\\s*(\\d+).*?" + // id - "\"name\":\\s*\"([^\"]+)\".*?" + // name - "\"username\":\\s*\"([^\"]+)\".*?" + // username - "\"email\":\\s*\"([^\"]+)\".*?" + // email - "\"street\":\\s*\"([^\"]+)\".*?" + // street - "\"suite\":\\s*\"([^\"]+)\".*?" + // suite - "\"city\":\\s*\"([^\"]+)\".*?" + // city - "\"phone\":\\s*\"([^\"]+)\".*?" + // phone - "\"website\":\\s*\"([^\"]+)\".*?" + // website - "\"company\":\\s*\\{\\s*\"name\":\\s*\"([^\"]+)\""; // company name - + String patternStr = "\"id\":\\s*(\\d+).*?" + // id + "\"name\":\\s*\"([^\"]+)\".*?" + // name + "\"username\":\\s*\"([^\"]+)\".*?" + // username + "\"email\":\\s*\"([^\"]+)\".*?" + // email + "\"street\":\\s*\"([^\"]+)\".*?" + // street + "\"suite\":\\s*\"([^\"]+)\".*?" + // suite + "\"city\":\\s*\"([^\"]+)\".*?" + // city + "\"phone\":\\s*\"([^\"]+)\".*?" + // phone + "\"website\":\\s*\"([^\"]+)\".*?" + // website + "\"company\":\\s*\\{\\s*\"name\":\\s*\"([^\"]+)\""; // company name + Pattern pattern = Pattern.compile(patternStr, Pattern.DOTALL); Matcher matcher = pattern.matcher(jsonInput); - + while (matcher.find()) { String flatUser = String.format( - "{\n" + - " \"id\": %s,\n" + - " \"name\": \"%s\",\n" + - " \"username\": \"%s\",\n" + - " \"email\": \"%s\",\n" + - " \"address\": \"%s, %s, %s\",\n" + - " \"phone\": \"%s\",\n" + - " \"website\": \"%s\",\n" + - " \"company\": \"%s\"\n" + - "}", - matcher.group(1), // id - matcher.group(2), // name - matcher.group(3), // username - matcher.group(4), // email - matcher.group(5), // street - matcher.group(6), // suite - matcher.group(7), // city - matcher.group(8), // phone - matcher.group(9), // website - matcher.group(10) // company name + "{\n" + + " \"id\": %s,\n" + + " \"name\": \"%s\",\n" + + " \"username\": \"%s\",\n" + + " \"email\": \"%s\",\n" + + " \"address\": \"%s, %s, %s\",\n" + + " \"phone\": \"%s\",\n" + + " \"website\": \"%s\",\n" + + " \"company\": \"%s\"\n" + + "}", + matcher.group(1), // id + matcher.group(2), // name + matcher.group(3), // username + matcher.group(4), // email + matcher.group(5), // street + matcher.group(6), // suite + matcher.group(7), // city + matcher.group(8), // phone + matcher.group(9), // website + matcher.group(10) // company name ); flatUsers.add(flatUser); } - + // If no matches were found, print input for debugging if (flatUsers.isEmpty()) { System.err.println("No matches found in input: " + jsonInput); return "[]"; } - + // Combine all users into a JSON array return "[\n " + String.join(",\n ", flatUsers) + "\n]"; } diff --git a/src/example/java/io/github/sashirestela/cleverclient/example/jsonplaceholder/UserService.java b/src/example/java/io/github/sashirestela/cleverclient/example/jsonplaceholder/UserService.java index d378b8d..0082741 100644 --- a/src/example/java/io/github/sashirestela/cleverclient/example/jsonplaceholder/UserService.java +++ b/src/example/java/io/github/sashirestela/cleverclient/example/jsonplaceholder/UserService.java @@ -1,11 +1,11 @@ package io.github.sashirestela.cleverclient.example.jsonplaceholder; -import java.util.List; - import io.github.sashirestela.cleverclient.annotation.GET; import io.github.sashirestela.cleverclient.annotation.Query; import io.github.sashirestela.cleverclient.annotation.Resource; +import java.util.List; + @Resource("/users") public interface UserService {