Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

HotspotsCounter.java 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2024 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonar.server.measure.live;
  21. import java.util.Collection;
  22. import java.util.HashMap;
  23. import java.util.Map;
  24. import javax.annotation.Nullable;
  25. import org.sonar.db.issue.HotspotGroupDto;
  26. public class HotspotsCounter {
  27. private final Map<String, Count> hotspotsByStatus = new HashMap<>();
  28. HotspotsCounter(Collection<HotspotGroupDto> groups) {
  29. for (HotspotGroupDto group : groups) {
  30. if (group.getStatus() != null) {
  31. hotspotsByStatus
  32. .computeIfAbsent(group.getStatus(), k -> new Count())
  33. .add(group);
  34. }
  35. }
  36. }
  37. public long countHotspotsByStatus(String status, boolean onlyInLeak) {
  38. return value(hotspotsByStatus.get(status), onlyInLeak);
  39. }
  40. private static long value(@Nullable Count count, boolean onlyInLeak) {
  41. if (count == null) {
  42. return 0;
  43. }
  44. return onlyInLeak ? count.leak : count.absolute;
  45. }
  46. private static class Count {
  47. private long absolute = 0L;
  48. private long leak = 0L;
  49. void add(HotspotGroupDto group) {
  50. absolute += group.getCount();
  51. if (group.isInLeak()) {
  52. leak += group.getCount();
  53. }
  54. }
  55. }
  56. }