From d0f76b0a15a52d6a69d8653be23cc68d3b0b24b2 Mon Sep 17 00:00:00 2001 From: Jacek Poreda Date: Wed, 20 Mar 2024 11:21:30 +0100 Subject: [PATCH] [NO-JIRA] Remove unused classes --- .../org/sonar/db/issue/HotspotGroupDto.java | 53 ---------------- .../server/measure/live/HotspotsCounter.java | 63 ------------------- .../measure/live/HotspotsCounterTest.java | 49 --------------- 3 files changed, 165 deletions(-) delete mode 100644 server/sonar-db-dao/src/main/java/org/sonar/db/issue/HotspotGroupDto.java delete mode 100644 server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/HotspotsCounter.java delete mode 100644 server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/HotspotsCounterTest.java diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/HotspotGroupDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/issue/HotspotGroupDto.java deleted file mode 100644 index a7cb994ec5c..00000000000 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/issue/HotspotGroupDto.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2024 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.db.issue; - -public class HotspotGroupDto { - private String status; - private long count; - private boolean inLeak; - - public String getStatus() { - return status; - } - - public HotspotGroupDto setStatus(String status) { - this.status = status; - return this; - } - - public long getCount() { - return count; - } - - public HotspotGroupDto setCount(long count) { - this.count = count; - return this; - } - - public boolean isInLeak() { - return inLeak; - } - - public HotspotGroupDto setInLeak(boolean inLeak) { - this.inLeak = inLeak; - return this; - } -} diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/HotspotsCounter.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/HotspotsCounter.java deleted file mode 100644 index 7b0d8040c5e..00000000000 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/live/HotspotsCounter.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2024 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.measure.live; - -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; -import javax.annotation.Nullable; -import org.sonar.db.issue.HotspotGroupDto; - -public class HotspotsCounter { - private final Map hotspotsByStatus = new HashMap<>(); - - HotspotsCounter(Collection groups) { - for (HotspotGroupDto group : groups) { - if (group.getStatus() != null) { - hotspotsByStatus - .computeIfAbsent(group.getStatus(), k -> new Count()) - .add(group); - } - } - } - - public long countHotspotsByStatus(String status, boolean onlyInLeak) { - return value(hotspotsByStatus.get(status), onlyInLeak); - } - - private static long value(@Nullable Count count, boolean onlyInLeak) { - if (count == null) { - return 0; - } - return onlyInLeak ? count.leak : count.absolute; - } - - private static class Count { - private long absolute = 0L; - private long leak = 0L; - - void add(HotspotGroupDto group) { - absolute += group.getCount(); - if (group.isInLeak()) { - leak += group.getCount(); - } - } - } -} diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/HotspotsCounterTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/HotspotsCounterTest.java deleted file mode 100644 index e8994577626..00000000000 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/live/HotspotsCounterTest.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2024 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.measure.live; - -import java.util.List; -import org.junit.Test; -import org.sonar.db.issue.HotspotGroupDto; - -import static java.util.Collections.emptyList; -import static org.assertj.core.api.Assertions.assertThat; - -public class HotspotsCounterTest { - @Test - public void counts_hotspots() { - HotspotGroupDto group1 = new HotspotGroupDto().setCount(3).setStatus("TO_REVIEW").setInLeak(false); - HotspotGroupDto group2 = new HotspotGroupDto().setCount(2).setStatus("REVIEWED").setInLeak(false); - HotspotGroupDto group3 = new HotspotGroupDto().setCount(1).setStatus("TO_REVIEW").setInLeak(true); - HotspotGroupDto group4 = new HotspotGroupDto().setCount(1).setStatus("REVIEWED").setInLeak(true); - - HotspotsCounter counter = new HotspotsCounter(List.of(group1, group2, group3, group4)); - assertThat(counter.countHotspotsByStatus("TO_REVIEW", true)).isEqualTo(1); - assertThat(counter.countHotspotsByStatus("REVIEWED", true)).isEqualTo(1); - assertThat(counter.countHotspotsByStatus("TO_REVIEW", false)).isEqualTo(4); - assertThat(counter.countHotspotsByStatus("REVIEWED", false)).isEqualTo(3); - } - - @Test - public void count_empty_hotspots() { - HotspotsCounter counter = new HotspotsCounter(emptyList()); - assertThat(counter.countHotspotsByStatus("TO_REVIEW", true)).isZero(); - } -} -- 2.39.5