Package ch.hortis.sonar.core.service

Source Code of ch.hortis.sonar.core.service.ComplexityPercentDistributionCalculator

/*
* This program is copyright (c) 2007 Hortis-GRC SA.
*
* This file is part of Sonar.
* Sonar is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Sonar 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
package ch.hortis.sonar.core.service;

import ch.hortis.sonar.model.Metrics;
import ch.hortis.sonar.service.MeasureKey;

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

public class ComplexityPercentDistributionCalculator extends AbstractMetricCalculator {

  protected Metrics getMetricKey() {
    return Metrics.COMPLEXITY_CLASSES_PERCENT_DISTRIBUTION;
  }

  public void execute(Module module, List<Module> directSubmodules) {
    Double nbTotalClasses = 0.0;
    HashMap<String, Double> percentByRange = new HashMap<String, Double>();

    for (MeasureKey key : module.getMeasureKeys()) {
      if (key.getFile() == null && key.getSubkey() != null &&
          key.getMetric().equals(getMetric(Metrics.COMPLEXITY_CLASSES_COUNT_DISTRIBUTION))) {
        Double nbClasses = module.getMeasureValue(key);
        nbTotalClasses += nbClasses;
        percentByRange.put(key.getSubkey(), nbClasses);
      }
    }

    for (Entry<String, Double> entry : percentByRange.entrySet()) {
      MeasureKey key = new MeasureKey(getMetric(), null, null, null, entry.getKey());
      double percent = 0.0;
      if (nbTotalClasses > 0) {
        percent = entry.getValue() / nbTotalClasses * 100.0;
      }
      module.createMeasure(key, percent);
    }
  }

}
TOP

Related Classes of ch.hortis.sonar.core.service.ComplexityPercentDistributionCalculator

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.