001 /*
002 * Sonar, open source software quality management tool.
003 * Copyright (C) 2009 SonarSource SA
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 package org.sonar.squid.measures;
021
022 public enum Metric {
023
024 PACKAGES, CLASSES, ANONYMOUS_INNER_CLASSES, FILES, METHODS, CONSTRUCTORS, STATEMENTS, LINES(false), BLANK_LINES(false), COMMENT_LINES(
025 false), HEADER_COMMENT_LINES(false), COMMENTED_OUT_CODE_LINES(false), BRANCHES, PUBLIC_API, PUBLIC_DOC_API, ACCESSORS, COMMENT_BLANK_LINES(
026 false), LINES_OF_CODE(false), COMMENT_LINES_WITHOUT_HEADER(new CommentLinesWithoutHeaderFormula()), PUBLIC_DOCUMENTED_API_DENSITY(
027 new PublicDocumentedApiDensityFormula()), COMMENT_LINES_DENSITY(new CommentLinesDensityFormula()), COMPLEXITY, INTERFACES, ABSTRACT_CLASSES, ABSTRACTNESS(
028 new AbstractnessFormula()), CA(new NoAggregationFormula()), CE(new NoAggregationFormula()), INSTABILITY(new InstabilityFormula()), DISTANCE(
029 new DistanceFormula()), DIT(new NoAggregationFormula()), RFC(new NoAggregationFormula()), NOC(new NoAggregationFormula()), LCOM4(
030 new NoAggregationFormula()), LCOM4_BLOCKS;
031
032 private double initValue = 0;
033
034 private CalculatedMetricFormula formula = null;
035
036 private AggregationFormula aggregationFormula = new SumAggregationFormula();
037
038 private boolean aggregateIfThereIsAlreadyAValue = true;
039
040 Metric() {
041 }
042
043 Metric(boolean aggregateIfThereIsAlreadyAValue) {
044 this.aggregateIfThereIsAlreadyAValue = aggregateIfThereIsAlreadyAValue;
045 }
046
047 Metric(AggregationFormula aggregationFormula) {
048 this.aggregationFormula = aggregationFormula;
049 }
050
051 Metric(CalculatedMetricFormula formula) {
052 this.formula = formula;
053 }
054
055 public double getInitValue() {
056 return initValue;
057 }
058
059 public boolean isCalculatedMetric() {
060 return formula != null;
061 }
062
063 public boolean aggregateIfThereIsAlreadyAValue() {
064 return aggregateIfThereIsAlreadyAValue;
065 }
066
067 public boolean isThereAggregationFormula() {
068 return !(aggregationFormula instanceof NoAggregationFormula);
069 }
070
071 public CalculatedMetricFormula getCalculatedMetricFormula() {
072 return formula;
073 }
074
075 public AggregationFormula getAggregationFormula() {
076 return aggregationFormula;
077 }
078 }