001/*
002 * Sonar, open source software quality management tool.
003 * Copyright (C) 2008-2012 SonarSource
004 * mailto:contact AT sonarsource DOT com
005 *
006 * Sonar is free software; you can redistribute it and/or
007 * modify it under the terms of the GNU Lesser General Public
008 * License as published by the Free Software Foundation; either
009 * version 3 of the License, or (at your option) any later version.
010 *
011 * Sonar is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014 * Lesser General Public License for more details.
015 *
016 * You should have received a copy of the GNU Lesser General Public
017 * License along with Sonar; if not, write to the Free Software
018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
019 */
020
021package org.sonar.squid.measures;
022
023public enum Metric implements MetricDef {
024
025  PACKAGES, CLASSES, ANONYMOUS_INNER_CLASSES, FILES, METHODS, CONSTRUCTORS, STATEMENTS, LINES(false), BLANK_LINES(false), COMMENT_LINES(
026      false), HEADER_COMMENT_LINES(false), COMMENTED_OUT_CODE_LINES(false), BRANCHES, PUBLIC_API, PUBLIC_DOC_API, ACCESSORS,
027  COMMENT_BLANK_LINES(false), LINES_OF_CODE(false), COMMENT_LINES_WITHOUT_HEADER(new CommentLinesWithoutHeaderFormula()),
028  PUBLIC_DOCUMENTED_API_DENSITY(new PublicDocumentedApiDensityFormula()), COMMENT_LINES_DENSITY(new CommentLinesDensityFormula()),
029  COMPLEXITY, INTERFACES, ABSTRACT_CLASSES, ABSTRACTNESS(new AbstractnessFormula()), CA(new NoAggregationFormula()), CE(
030      new NoAggregationFormula()), INSTABILITY(new InstabilityFormula()), DISTANCE(new DistanceFormula()), DIT(new NoAggregationFormula()),
031  RFC(new NoAggregationFormula()), NOC(new NoAggregationFormula()), LCOM4(new NoAggregationFormula()), LCOM4_BLOCKS;
032
033  private CalculatedMetricFormula formula = null;
034
035  private AggregationFormula aggregationFormula = new SumAggregationFormula();
036
037  private boolean aggregateIfThereIsAlreadyAValue = true;
038
039  Metric() {
040  }
041
042  Metric(boolean aggregateIfThereIsAlreadyAValue) {
043    this.aggregateIfThereIsAlreadyAValue = aggregateIfThereIsAlreadyAValue;
044  }
045
046  Metric(AggregationFormula aggregationFormula) {
047    this.aggregationFormula = aggregationFormula;
048  }
049
050  Metric(CalculatedMetricFormula formula) {
051    this.formula = formula;
052  }
053
054  public String getName() {
055    return name();
056  }
057
058  public boolean isCalculatedMetric() {
059    return formula != null;
060  }
061
062  public boolean aggregateIfThereIsAlreadyAValue() {
063    return aggregateIfThereIsAlreadyAValue;
064  }
065
066  public boolean isThereAggregationFormula() {
067    return !(aggregationFormula instanceof NoAggregationFormula);
068  }
069
070  public CalculatedMetricFormula getCalculatedMetricFormula() {
071    return formula;
072  }
073
074}