org.sonar.api.measures
Class Metric.Builder

java.lang.Object
  extended by org.sonar.api.measures.Metric.Builder
Enclosing class:
Metric

public static final class Metric.Builder
extends Object

Metric.Builder is used to create metric definitions. It must be preferred to creating new instances of the Metric class directly.

Since:
2.7

Constructor Summary
Metric.Builder(String key, String name, Metric.ValueType type)
          Creates a new Metric.Builder object.
 
Method Summary
 Metric create()
          Creates a new metric definition based on the properties set on this metric builder.
 Metric.Builder setBestValue(Double d)
          Sets the best value that the metric can get (example: 100.0 for code coverage).
 Metric.Builder setDeleteHistoricalData(boolean b)
          Specifies whether measures from the past can be automatically deleted to minimize database volume.
 Metric.Builder setDescription(String d)
          Sets the metric description.
 Metric.Builder setDirection(Integer d)
          Sets the metric direction (used for numeric values only), which is used in the Web UI to show if the trend of a metric is good or not.
 Metric.Builder setDomain(String d)
          Sets the domain for the metric (General, Complexity...).
 Metric.Builder setFormula(Formula f)
          Specifies the formula used by Sonar to automatically aggregate measures stored on files up to the project level.
 Metric.Builder setHidden(boolean b)
          Sets whether the metric should be hidden in Web UI (e.g.
 Metric.Builder setOptimizedBestValue(boolean b)
          Specifies whether file-level measures that equal to the defined best value are stored or not.
 Metric.Builder setQualitative(Boolean b)
          Sets whether the metric is qualitative or not.
 Metric.Builder setUserManaged(boolean b)
          Specifies whether this metric can be edited online in the "Manual measures" page.
 Metric.Builder setWorstValue(Double d)
          Sets the worst value that the metric can get (example: 0.0 for code coverage).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Metric.Builder

public Metric.Builder(String key,
                      String name,
                      Metric.ValueType type)
Creates a new Metric.Builder object.

Parameters:
key - the metric key, should be unique among all metrics
name - the metric name
type - the metric type
Method Detail

setDescription

public Metric.Builder setDescription(String d)
Sets the metric description.

Parameters:
d - the description
Returns:
the builder

setDirection

public Metric.Builder setDirection(Integer d)
Sets the metric direction (used for numeric values only), which is used in the Web UI to show if the trend of a metric is good or not. Metric.DIRECTION_NONE is the default value.

Parameters:
d - the direction
Returns:
the builder
See Also:
Metric.DIRECTION_WORST, Metric.DIRECTION_BETTER, Metric.DIRECTION_NONE

setQualitative

public Metric.Builder setQualitative(Boolean b)
Sets whether the metric is qualitative or not. Default value is false.
If set to true, then variations of this metric will be highlighted in the Web UI (for instance, trend icons will be red or green instead of default grey).

Parameters:
b - Boolean.TRUE if the metric is qualitative
Returns:
the builder

setDomain

public Metric.Builder setDomain(String d)
Sets the domain for the metric (General, Complexity...). This is used to group metrics in the Web UI.
By default, the metric belongs to no specific domain.

Parameters:
d - the domain
Returns:
the builder

setFormula

public Metric.Builder setFormula(Formula f)
Specifies the formula used by Sonar to automatically aggregate measures stored on files up to the project level.

By default, no formula is defined, which means that it's up to a sensor/decorator to compute measures on appropriate levels.
When a formula is set, sensors/decorators just need to store measures at a specific level and let Sonar run the formula to store measures on the remaining levels.

Parameters:
f - the formula
Returns:
the builder
See Also:
SumChildDistributionFormula}, {@link SumChildValuesFormula}, {@link AverageComplexityFormula}, {@link MeanAggregationFormula}, {@link WeightedMeanAggregationFormula}

setWorstValue

public Metric.Builder setWorstValue(Double d)
Sets the worst value that the metric can get (example: 0.0 for code coverage). No worst value is set by default.

Parameters:
d - the worst value
Returns:
the builder

setBestValue

public Metric.Builder setBestValue(Double d)
Sets the best value that the metric can get (example: 100.0 for code coverage). No best value is set by default.
Resources would be hidden on drilldown page, if the value of measure equals to best value.

Parameters:
d - the best value
Returns:
the builder

setOptimizedBestValue

public Metric.Builder setOptimizedBestValue(boolean b)
Specifies whether file-level measures that equal to the defined best value are stored or not. Default is false.
Example with the metric that stores the number of violation (CoreMetrics.VIOLATIONS): if a file has no violation, then the value '0' won't be stored in the database.

Parameters:
b - true if the measures must not be stored when they equal to the best value
Returns:
the builder

setHidden

public Metric.Builder setHidden(boolean b)
Sets whether the metric should be hidden in Web UI (e.g. in Time Machine). Default is false.

Parameters:
b - true if the metric should be hidden.
Returns:
the builder

setUserManaged

public Metric.Builder setUserManaged(boolean b)
Specifies whether this metric can be edited online in the "Manual measures" page. Default is false.

Parameters:
b - true if the metric can be edited online.
Returns:
the builder
Since:
2.10

setDeleteHistoricalData

public Metric.Builder setDeleteHistoricalData(boolean b)
Specifies whether measures from the past can be automatically deleted to minimize database volume.
By default, historical data are kept.

Parameters:
b - true if measures from the past can be deleted automatically.
Returns:
the builder
Since:
2.14

create

public Metric create()
Creates a new metric definition based on the properties set on this metric builder.

Returns:
a new Metric object


Copyright © 2009-2012 SonarSource. All Rights Reserved.