Package org.sonar.api.measures
Class Metric.Builder
- java.lang.Object
-
- org.sonar.api.measures.Metric.Builder
-
-
Constructor Summary
Constructors Constructor Description Builder(java.lang.String key, java.lang.String name, Metric.ValueType type)
Creates a newMetric.Builder
object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <G extends java.io.Serializable>
Metric<G>create()
Creates a new metric definition based on the properties set on this metric builder.Metric.Builder
setBestValue(java.lang.Double d)
Sets the best value that the metric can get (example: 100.0 for code coverage).Metric.Builder
setDecimalScale(int scale)
Scale to be used if the metric has decimal type (Metric.ValueType.FLOAT
orMetric.ValueType.PERCENT
).Metric.Builder
setDeleteHistoricalData(boolean b)
Specifies whether measures from the past can be automatically deleted to minimize database volume.Metric.Builder
setDescription(java.lang.String d)
Sets the metric description.Metric.Builder
setDirection(java.lang.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(java.lang.String d)
Sets the domain for the metric (General, Complexity...).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(java.lang.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(java.lang.Double d)
Sets the worst value that the metric can get (example: 0.0 for code coverage).
-
-
-
Constructor Detail
-
Builder
public Builder(java.lang.String key, java.lang.String name, Metric.ValueType type)
Creates a newMetric.Builder
object.- Parameters:
key
- the metric key, should be unique among all metricsname
- the metric nametype
- the metric type
-
-
Method Detail
-
setDescription
public Metric.Builder setDescription(java.lang.String d)
Sets the metric description.- Parameters:
d
- the description- Returns:
- the builder
-
setDirection
public Metric.Builder setDirection(java.lang.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_WORST: indicates that an increase of the metric value is not a good thing (example: the complexity of a function)
- Metric.DIRECTION_BETTER: indicates that an increase of the metric value is a good thing (example: the code coverage of a function)
- Metric.DIRECTION_NONE: indicates that the variation of the metric value is neither good nor bad (example: number of files).
- Parameters:
d
- the direction- Returns:
- the builder
- See Also:
Metric.DIRECTION_WORST
,Metric.DIRECTION_BETTER
,Metric.DIRECTION_NONE
-
setQualitative
public Metric.Builder setQualitative(java.lang.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(java.lang.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
-
setWorstValue
public Metric.Builder setWorstValue(java.lang.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(java.lang.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
-
setDecimalScale
public Metric.Builder setDecimalScale(int scale)
Scale to be used if the metric has decimal type (Metric.ValueType.FLOAT
orMetric.ValueType.PERCENT
). Default is 1. It is not set ((null
) on non-decimal metrics.- Since:
- 5.3
-
-