Package ch.hortis.sonar.core.service

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

/*
* 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.Metric;
import ch.hortis.sonar.model.Metrics;
import ch.hortis.sonar.service.MeasureKey;

import java.util.List;

public abstract class RciCalculator extends AbstractMetricCalculator {
  protected abstract Metrics getCountMetric();

  public void execute(Module module, List<Module> directSubmodules) {
    Metric countMetric = getMetric(getCountMetric());

    for (MeasureKey key : module.getMeasureKeys()) {
      if (key.getMetric().equals(countMetric)) {
        MeasureKey linesKey = new MeasureKey(getMetric(Metrics.NCSS_NCSS), null, null, key.getFile());
        Double lines = module.getMeasureValue(linesKey);
        Double failuresCount = module.getMeasureValue(key);
        if ((lines != null) && (lines>0.0) && (failuresCount!=null)) {
          double index = getPercentage( failuresCount, lines);
          module.createMeasure(((MeasureKey)key.clone()).setMetric(getMetric()), index);
        }
      }
    }
  }

  protected double getPercentage(Double numberOfFailures, Double numberOfLines) {
    double failuresFor100Lines = (numberOfFailures * 100.0) / numberOfLines;
    return 100.0 - Math.min(100.0, failuresFor100Lines);
  }
}
TOP

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

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.