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(false), HEADER_COMMENT_LINES(false), COMMENTED_OUT_CODE_LINES( 025 false), BRANCHES, PUBLIC_API, PUBLIC_DOC_API, ACCESSORS, COMMENT_BLANK_LINES(false), LINES_OF_CODE(false), COMMENT_LINES_WITHOUT_HEADER( 026 new CommentLinesWithoutHeaderFormula()), PUBLIC_DOCUMENTED_API_DENSITY(new PublicDocumentedApiDensityFormula()), COMMENT_LINES_DENSITY( 027 new CommentLinesDensityFormula()), COMPLEXITY, INTERFACES, ABSTRACT_CLASSES, ABSTRACTNESS(new AbstractnessFormula()), CA( 028 new NoAggregationFormula()), CE(new NoAggregationFormula()), INSTABILITY(new InstabilityFormula()), DISTANCE(new DistanceFormula()); 029 030 private double initValue = 0; 031 032 private CalculatedMetricFormula formula = null; 033 034 private AggregationFormula aggregationFormula = new SumAggregationFormula(); 035 036 private boolean aggregateIfThereIsAlreadyAValue = true; 037 038 Metric() { 039 } 040 041 Metric(boolean aggregateIfThereIsAlreadyAValue) { 042 this.aggregateIfThereIsAlreadyAValue = aggregateIfThereIsAlreadyAValue; 043 } 044 045 Metric(AggregationFormula aggregationFormula) { 046 this.aggregationFormula = aggregationFormula; 047 } 048 049 Metric(CalculatedMetricFormula formula) { 050 this.formula = formula; 051 } 052 053 public double getInitValue() { 054 return initValue; 055 } 056 057 public boolean isCalculatedMetric() { 058 return formula != null; 059 } 060 061 public boolean aggregateIfThereIsAlreadyAValue() { 062 return aggregateIfThereIsAlreadyAValue; 063 } 064 065 public boolean isThereAggregationFormula() { 066 return !(aggregationFormula instanceof NoAggregationFormula); 067 } 068 069 public CalculatedMetricFormula getCalculatedMetricFormula() { 070 return formula; 071 } 072 073 public AggregationFormula getAggregationFormula() { 074 return aggregationFormula; 075 } 076 }