package com.hubspot.blazar.data.service;

import java.util.HashSet;
import java.util.Set;

import javax.inject.Inject;
import javax.inject.Singleton;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.codahale.metrics.MetricRegistry;
import com.google.common.base.Optional;
import com.hubspot.blazar.base.Module;
import com.hubspot.blazar.base.ModuleState;
import com.hubspot.blazar.base.RepositoryState;
import com.hubspot.blazar.data.dao.StateDao;

@Singleton
public class StateService {
  // Tracks how long it takes to get all module states for a branch
  private static final String METRIC_FETCH_BRANCH_STATE_TIMER = StateService.class.getName() + ".branch_state.fetch_time";
  private static final Logger LOG = LoggerFactory.getLogger(StateService.class);
  private final StateDao stateDao;
  private ModuleService moduleService;
  private MetricRegistry metricRegistry;

  @Inject
  public StateService(StateDao stateDao, ModuleService moduleService, MetricRegistry metricRegistry) {
    this.stateDao = stateDao;
    this.moduleService = moduleService;
    this.metricRegistry = metricRegistry;
  }

  public Set<RepositoryState> getAllRepositoryStates() {
    return stateDao.getAllRepositoryStates();
  }

  public Set<RepositoryState> getChangedRepositoryStates(long since) {
    return stateDao.getChangedRepositoryStates(since);
  }

  public Optional<RepositoryState> getRepositoryState(int branchId) {
    return stateDao.getRepositoryState(branchId);
  }

  /**
   * Collects the ModuleState for every module on the branch.
   *
   */
  public Set<ModuleState> getModuleStatesByBranch(int branchId) {
    long start = System.currentTimeMillis();
    Set<ModuleState> states = new HashSet<>();
    Set<Module> modules = moduleService.getByBranch(branchId);
    for (Module m : modules) {
      Optional<ModuleState> optionalState = stateDao.getModuleStateById(m.getId().get());
      if (optionalState.isPresent()) {
        states.add(optionalState.get());
      }
    }
    LOG.info("Built composite state for branch {} in {}", branchId, System.currentTimeMillis() - start);
    return states;
  }

}

@@ -574,131 +574,8 @@
 nch%0A
-  private static final String METRIC_FETCH_BRANCH_STATE_TIMER = StateService.class.getName() + %22.branch_state.fetch_time%22;%0A
   pr
@@ -651,16 +651,16 @@
 class);%0A
+
   privat
@@ -728,49 +728,8 @@
 ice;
-%0A  private MetricRegistry metricRegistry;
 %0A%0A  
@@ -869,16 +869,16 @@
 ateDao;%0A
+
     this
@@ -913,50 +913,8 @@
 ce;%0A
-    this.metricRegistry = metricRegistry;%0A
   %7D%0A

Remove unused metrics registry