All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dk.alexandra.fresco.logging.PerformanceLoggerCountingAggregate Maven / Gradle / Ivy

package dk.alexandra.fresco.logging;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * An aggregator of {@link PerformanceLogger}s.
 */
public class PerformanceLoggerCountingAggregate implements PerformanceLogger {


  private List performanceLoggers = new ArrayList<>();

  @Override
  public void reset() {
    for (PerformanceLogger performanceLogger : performanceLoggers) {
      performanceLogger.reset();
    }
  }

  @Override
  public Map getLoggedValues() {
    Map result = new HashMap<>();
    for (PerformanceLogger performanceLogger : performanceLoggers) {
      Map loggedValues = performanceLogger.getLoggedValues();
      for (String key : loggedValues.keySet()) {
        result.merge(key, loggedValues.get(key), (left, right) -> left + right);
      }
    }
    return result;
  }

  /**
   * Adds a performance logger to this.
   *
   * @param performanceLogger the sub logger to add.
   */
  public void add(PerformanceLogger performanceLogger) {
    performanceLoggers.add(performanceLogger);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy