class GarbageCollectionHealthIndicator implements HealthIndicator {

  /**
   * The memory usage threshold above which a warning message is included in the health check
   * report.
   */
  @Value("${memory.usage.threshold:0.8}")
  private double memoryUsageThreshold;

  /**
   * Performs a health check by gathering garbage collection metrics and evaluating the overall
   * health of the garbage collection system.
   *
   * @return a {@link Health} object representing the health status of the garbage collection system
   */
  @Override
  public Health health() {<FILL_FUNCTION_BODY>}

  /**
   * Creates details for the given garbage collector, including collection count, collection time,
   * and memory pool information.
   *
   * @param gcBean The garbage collector MXBean
   * @param memoryPoolMxBeans List of memory pool MXBeans
   * @return Map containing details for the garbage collector
   */
  private Map<String, String> createCollectorDetails(
      GarbageCollectorMXBean gcBean, List<MemoryPoolMXBean> memoryPoolMxBeans) {
    Map<String, String> collectorDetails = new HashMap<>();
    long count = gcBean.getCollectionCount();
    long time = gcBean.getCollectionTime();
    collectorDetails.put("count", String.format("%d", count));
    collectorDetails.put("time", String.format("%dms", time));

    String[] memoryPoolNames = gcBean.getMemoryPoolNames();
    List<String> memoryPoolNamesList = Arrays.asList(memoryPoolNames);
    if (!memoryPoolNamesList.isEmpty()) {
      addMemoryPoolDetails(collectorDetails, memoryPoolMxBeans, memoryPoolNamesList);
    } else {
      LOGGER.error("Garbage collector '{}' does not have any memory pools", gcBean.getName());
    }

    return collectorDetails;
  }

  /**
   * Adds memory pool details to the collector details.
   *
   * @param collectorDetails Map containing details for the garbage collector
   * @param memoryPoolMxBeans List of memory pool MXBeans
   * @param memoryPoolNamesList List of memory pool names associated with the garbage collector
   */
  private void addMemoryPoolDetails(
      Map<String, String> collectorDetails,
      List<MemoryPoolMXBean> memoryPoolMxBeans,
      List<String> memoryPoolNamesList) {
    for (MemoryPoolMXBean memoryPoolmxbean : memoryPoolMxBeans) {
      if (memoryPoolNamesList.contains(memoryPoolmxbean.getName())) {
        double memoryUsage =
            memoryPoolmxbean.getUsage().getUsed() / (double) memoryPoolmxbean.getUsage().getMax();
        if (memoryUsage > memoryUsageThreshold) {
          collectorDetails.put(
              "warning",
              String.format(
                  "Memory pool '%s' usage is high (%2f%%)",
                  memoryPoolmxbean.getName(), memoryUsage));
        }

        collectorDetails.put(
            "memoryPools", String.format("%s: %s%%", memoryPoolmxbean.getName(), memoryUsage));
      }
    }
  }

  /**
   * Retrieves the list of garbage collector MXBeans using ManagementFactory.
   *
   * @return a list of {@link GarbageCollectorMXBean} objects representing the garbage collectors
   */
  protected List<GarbageCollectorMXBean> getGarbageCollectorMxBeans() {
    return ManagementFactory.getGarbageCollectorMXBeans();
  }

  /**
   * Retrieves the list of memory pool MXBeans using ManagementFactory.
   *
   * @return a list of {@link MemoryPoolMXBean} objects representing the memory pools
   */
  protected List<MemoryPoolMXBean> getMemoryPoolMxBeans() {
    return ManagementFactory.getMemoryPoolMXBeans();
  }
}

    List<GarbageCollectorMXBean> gcBeans = getGarbageCollectorMxBeans();
    List<MemoryPoolMXBean> memoryPoolMxBeans = getMemoryPoolMxBeans();
    Map<String, Map<String, String>> gcDetails = new HashMap<>();

    for (GarbageCollectorMXBean gcBean : gcBeans) {
      Map<String, String> collectorDetails = createCollectorDetails(gcBean, memoryPoolMxBeans);
      gcDetails.put(gcBean.getName(), collectorDetails);
    }

    return Health.up().withDetails(gcDetails).build();
  
<no_super_class>