Package ch.hortis.sonar.core.service

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

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

import java.util.List;

public class SumCalculator extends AbstractMetricCalculator {
  private Metrics metricKey;

  public SumCalculator(Metrics metricKey) {
    this.metricKey = metricKey;
  }

  public Metrics getMetricKey() {
    return metricKey;
  }

  public void execute(Module module, List<Module> directSubmodules) {
    MeasureKey key = new MeasureKey(getMetric());
    if (module.getMeasure(key)==null) {
      double value = 0;
      boolean add = false;
      for(Module submodule:directSubmodules) {
        MetricMeasure submeasure = submodule.getMeasure(key);
        if (submeasure!=null) {
          value += submeasure.getValue();
          add = true;
        }
      }

      if (add) {
        if (log.isDebugEnabled()) log.debug( module.getMavenProject().getArtifactId() + " create " + key.getMetric() + ":" + value );
        module.createMeasure(key, value);
      }
    }
  }
}
TOP

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

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.