refac: смена мест ключа и значения

This commit is contained in:
2025-07-18 03:27:20 +03:00
parent eb3c7b8899
commit 66d22f6f7c
2 changed files with 6 additions and 6 deletions

View File

@@ -61,7 +61,7 @@ public class IhcClient {
return isAuth; return isAuth;
} }
public List<Pair<Integer, String>> getDomains() { public List<Pair<String, Integer>> getDomains() {
if (!isAuth) { if (!isAuth) {
throw new RuntimeException("IS NOT AUTH"); throw new RuntimeException("IS NOT AUTH");
} }
@@ -75,13 +75,13 @@ public class IhcClient {
return Collections.emptyList(); return Collections.emptyList();
} }
List<Pair<Integer, String>> list = new ArrayList<>(); List<Pair<String, Integer>> list = new ArrayList<>();
Document document = Jsoup.parse(resp.getEntity().getContent(), StandardCharsets.UTF_8.name(), baseUrl); Document document = Jsoup.parse(resp.getEntity().getContent(), StandardCharsets.UTF_8.name(), baseUrl);
Elements elements = document.select("li[class='zoneList__zone'] a"); Elements elements = document.select("li[class='zoneList__zone'] a");
for (Element element : elements) { for (Element element : elements) {
Integer id = Integer.valueOf(element.attr("href").substring(1).split("/")[2]); Integer id = Integer.valueOf(element.attr("href").substring(1).split("/")[2]);
String domain = element.text(); String domain = element.text();
list.add(Pair.of(id, domain)); list.add(Pair.of(domain, id));
} }
return list; return list;

View File

@@ -50,10 +50,10 @@ class GetDomainsTest {
var ihc = new IhcClient("http://localhost:%d".formatted(port)); var ihc = new IhcClient("http://localhost:%d".formatted(port));
ihc.auth("user1", "passwd1"); ihc.auth("user1", "passwd1");
List<Pair<Integer, String>> domains = ihc.getDomains(); List<Pair<String, Integer>> domains = ihc.getDomains();
assertEquals(2, domains.size()); assertEquals(2, domains.size());
assertEquals(Pair.of(111111, "example-1.ru"), domains.get(0)); assertEquals(Pair.of("example-1.ru", 111111), domains.get(0));
assertEquals(Pair.of(222222, "example-2.ru"), domains.get(1)); assertEquals(Pair.of("example-2.ru", 222222), domains.get(1));
} }
} }