From 3120751d3ec2d93c8686e4fedb04c6c0b963d6c4 Mon Sep 17 00:00:00 2001 From: Jan-Peter Klein Date: Tue, 13 Jun 2023 12:48:35 +0200 Subject: [PATCH] resolved sonarclouds mentioned issues --- .../org/cryptomator/ui/common/HttpHelper.java | 3 +++ .../cryptomator/ui/error/ErrorController.java | 18 ++++++++++-------- .../cryptomator/ui/error/ErrorDiscussion.java | 3 --- .../ui/error/ErrorControllerTest.java | 2 +- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/cryptomator/ui/common/HttpHelper.java b/src/main/java/org/cryptomator/ui/common/HttpHelper.java index 5ee63098b..32b44b64a 100644 --- a/src/main/java/org/cryptomator/ui/common/HttpHelper.java +++ b/src/main/java/org/cryptomator/ui/common/HttpHelper.java @@ -10,6 +10,9 @@ import java.nio.charset.StandardCharsets; public class HttpHelper { + private HttpHelper(){ + throw new IllegalStateException("Utility class"); + } public static String readBody(HttpResponse response) throws IOException { try (var in = response.body(); var reader = new InputStreamReader(in, StandardCharsets.UTF_8)) { return CharStreams.toString(reader); diff --git a/src/main/java/org/cryptomator/ui/error/ErrorController.java b/src/main/java/org/cryptomator/ui/error/ErrorController.java index a513c57dc..5503cc595 100644 --- a/src/main/java/org/cryptomator/ui/error/ErrorController.java +++ b/src/main/java/org/cryptomator/ui/error/ErrorController.java @@ -28,6 +28,7 @@ import java.net.http.HttpResponse; import java.nio.charset.StandardCharsets; import java.util.Comparator; import java.util.Map; +import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeUnit; @@ -126,9 +127,7 @@ public class ErrorController implements FxController { Clipboard.getSystemClipboard().setContent(clipboardContent); copiedDetails.set(true); - CompletableFuture.delayedExecutor(2, TimeUnit.SECONDS, Platform::runLater).execute(() -> { - copiedDetails.set(false); - }); + CompletableFuture.delayedExecutor(2, TimeUnit.SECONDS, Platform::runLater).execute(() -> copiedDetails.set(false)); } private void loadHttpResponse(HttpResponse response){ @@ -137,15 +136,18 @@ public class ErrorController implements FxController { new InputStreamReader(response.body(),StandardCharsets.UTF_8), new TypeToken>(){}.getType()); - if(!map.values().stream().filter(this::isPartialMatchFilter).findFirst().isEmpty()) { + if(map.values().stream().anyMatch(this::isPartialMatchFilter)) { Comparator comp = this::compareExactMatch; - matchingErrorDiscussion = map.values().stream().sorted(comp + Optional value = map.values().stream().min(comp .thenComparing(this::compareSecondLevelMatch) .thenComparing(this::compareThirdLevelMatch) .thenComparing(this::compareIsAnswered) - .thenComparing(this::compareUpvoteCount) - ).findFirst().get(); - lookUpSolutionVisibility.set(true); + .thenComparing(this::compareUpvoteCount)); + + if(value.isPresent()){ + matchingErrorDiscussion = value.get(); + lookUpSolutionVisibility.set(true); + } } } } diff --git a/src/main/java/org/cryptomator/ui/error/ErrorDiscussion.java b/src/main/java/org/cryptomator/ui/error/ErrorDiscussion.java index 603450d43..cea9d3b9e 100644 --- a/src/main/java/org/cryptomator/ui/error/ErrorDiscussion.java +++ b/src/main/java/org/cryptomator/ui/error/ErrorDiscussion.java @@ -8,8 +8,5 @@ public class ErrorDiscussion { Answer answer; static class Answer{ - private String url; - private int upvoteCount; } - } diff --git a/src/test/java/org/cryptomator/ui/error/ErrorControllerTest.java b/src/test/java/org/cryptomator/ui/error/ErrorControllerTest.java index f5b274ef6..24936d4d3 100644 --- a/src/test/java/org/cryptomator/ui/error/ErrorControllerTest.java +++ b/src/test/java/org/cryptomator/ui/error/ErrorControllerTest.java @@ -97,7 +97,7 @@ class ErrorControllerTest { ErrorDiscussion ed1 = createErrorDiscussion("",0, null); ErrorDiscussion ed2 = createErrorDiscussion("",0, null); int result = errorController.compareIsAnswered(ed1,ed2); - Assertions.assertEquals(result, 0); + Assertions.assertEquals(0, result); } @Test