Package org.sonar.api.measures
Class Metric<G extends java.io.Serializable>
- java.lang.Object
-
- org.sonar.api.measures.Metric<G>
-
- All Implemented Interfaces:
java.io.Serializable
,Metric<G>
@ScannerSide @ServerSide @ComputeEngineSide public class Metric<G extends java.io.Serializable> extends java.lang.Object implements java.io.Serializable, Metric<G>
Used to define a metric in a plugin. Should be used withMetrics
extension point.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Metric.Builder
Metric.Builder is used to create metric definitions.static class
Metric.Level
static class
Metric.ValueType
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_DECIMAL_SCALE
static int
DIRECTION_BETTER
A metric bigger value means an improvementstatic int
DIRECTION_NONE
The metric direction has no meaningstatic int
DIRECTION_WORST
A metric bigger value means a degradationstatic int
MAX_DECIMAL_SCALE
The maximum supported value of scale for decimal metrics
-
Constructor Summary
Constructors Constructor Description Metric()
Deprecated.in 1.12.Metric(java.lang.String key)
Deprecated.since 2.7 use theMetric.Builder
factory.Metric(java.lang.String key, java.lang.String name, java.lang.String description, Metric.ValueType type, java.lang.Integer direction, java.lang.Boolean qualitative, java.lang.String domain)
Deprecated.since 2.7 use theMetric.Builder
factory.Metric(java.lang.String key, Metric.ValueType type)
Deprecated.since 2.7 use theMetric.Builder
factory.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object obj)
java.lang.Double
getBestValue()
java.lang.Integer
getDecimalScale()
Return the number scale if metric type isMetric.ValueType.FLOAT
, elsenull
java.lang.Boolean
getDeleteHistoricalData()
java.lang.String
getDescription()
java.lang.Integer
getDirection()
java.lang.String
getDomain()
java.lang.Boolean
getEnabled()
java.lang.String
getKey()
java.lang.String
getName()
java.lang.Boolean
getQualitative()
Metric.ValueType
getType()
java.lang.Boolean
getUserManaged()
java.lang.String
getUuid()
For internal use onlyjava.lang.Double
getWorstValue()
int
hashCode()
boolean
isDataType()
java.lang.Boolean
isHidden()
boolean
isNumericType()
java.lang.Boolean
isOptimizedBestValue()
boolean
isPercentageType()
java.lang.String
key()
Metric<G>
merge(Metric with)
Merge with fields from other metric.Metric<G>
setBestValue(java.lang.Double bestValue)
Metric<G>
setDescription(java.lang.String description)
Sets the metric descriptionMetric<G>
setDirection(java.lang.Integer direction)
Sets the metric direction.Metric<G>
setDomain(java.lang.String domain)
Sets the domain for the metric (General, Complexity...)Metric<G>
setEnabled(java.lang.Boolean enabled)
Sets whether the metric is enabledMetric<G>
setHidden(java.lang.Boolean hidden)
Metric<G>
setKey(java.lang.String key)
Sets the metric keyMetric<G>
setName(java.lang.String name)
Sets the metric nameMetric<G>
setOptimizedBestValue(java.lang.Boolean b)
Metric<G>
setQualitative(java.lang.Boolean qualitative)
Sets whether the metric is qualitativeMetric<G>
setType(Metric.ValueType type)
Sets the metric typeMetric<G>
setUserManaged(java.lang.Boolean userManaged)
Sets whether the metric is managed by users ("manual metric")Metric<G>
setUuid(java.lang.String uuid)
For internal use onlyMetric<G>
setWorstValue(java.lang.Double d)
java.lang.String
toString()
java.lang.Class<G>
valueType()
-
-
-
Field Detail
-
DEFAULT_DECIMAL_SCALE
public static final int DEFAULT_DECIMAL_SCALE
- Since:
- 5.3
- See Also:
- Constant Field Values
-
MAX_DECIMAL_SCALE
public static final int MAX_DECIMAL_SCALE
The maximum supported value of scale for decimal metrics- Since:
- 5.3
- See Also:
- Constant Field Values
-
DIRECTION_WORST
public static final int DIRECTION_WORST
A metric bigger value means a degradation- See Also:
- Constant Field Values
-
DIRECTION_BETTER
public static final int DIRECTION_BETTER
A metric bigger value means an improvement- See Also:
- Constant Field Values
-
DIRECTION_NONE
public static final int DIRECTION_NONE
The metric direction has no meaning- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Metric
@Deprecated public Metric()
Deprecated.in 1.12. Use theMetric.Builder
factory.Creates an empty metric
-
Metric
@Deprecated public Metric(java.lang.String key)
Deprecated.since 2.7 use theMetric.Builder
factory.Creates a metric based on its key. Shortcut to Metric(key, ValueType.INT)- Parameters:
key
- the metric key
-
Metric
@Deprecated public Metric(java.lang.String key, Metric.ValueType type)
Deprecated.since 2.7 use theMetric.Builder
factory.Creates a metric based on a key and a type. Shortcut to Metric(key, key, key, type, -1, Boolean.FALSE, null, false)- Parameters:
key
- the keytype
- the type
-
Metric
@Deprecated public Metric(java.lang.String key, java.lang.String name, java.lang.String description, Metric.ValueType type, java.lang.Integer direction, java.lang.Boolean qualitative, java.lang.String domain)
Deprecated.since 2.7 use theMetric.Builder
factory.
-
-
Method Detail
-
getUuid
public java.lang.String getUuid()
For internal use only
-
getQualitative
public java.lang.Boolean getQualitative()
- Returns:
- wether the metric is qualitative
-
setQualitative
public Metric<G> setQualitative(java.lang.Boolean qualitative)
Sets whether the metric is qualitative- Parameters:
qualitative
- whether the metric is qualitative- Returns:
- this
-
getKey
public java.lang.String getKey()
- Returns:
- the metric key
-
setKey
public Metric<G> setKey(java.lang.String key)
Sets the metric key- Parameters:
key
- the key- Returns:
- this
-
getType
public Metric.ValueType getType()
- Returns:
- the metric type
-
setType
public Metric<G> setType(Metric.ValueType type)
Sets the metric type- Parameters:
type
- the type- Returns:
- this
-
getDescription
@CheckForNull public java.lang.String getDescription()
- Returns:
- the metric description
-
setDescription
public Metric<G> setDescription(@Nullable java.lang.String description)
Sets the metric description- Parameters:
description
- the description- Returns:
- this
-
getUserManaged
public java.lang.Boolean getUserManaged()
- Returns:
- whether the metric is a managed by the users ("manual metric")
-
setUserManaged
public Metric<G> setUserManaged(java.lang.Boolean userManaged)
Sets whether the metric is managed by users ("manual metric")- Parameters:
userManaged
- whether the metric is user managed- Returns:
- this
-
getEnabled
public java.lang.Boolean getEnabled()
- Returns:
- whether the metric is enabled
-
setEnabled
public Metric<G> setEnabled(java.lang.Boolean enabled)
Sets whether the metric is enabled- Parameters:
enabled
- whether the metric is enabled- Returns:
- this
-
getDirection
public java.lang.Integer getDirection()
- Returns:
- the metric direction
-
setDirection
public Metric<G> setDirection(java.lang.Integer direction)
Sets the metric direction.- Parameters:
direction
- the direction
-
getDomain
public java.lang.String getDomain()
- Returns:
- the domain of the metric
-
setDomain
public Metric<G> setDomain(java.lang.String domain)
Sets the domain for the metric (General, Complexity...)- Parameters:
domain
- the domain- Returns:
- this
-
getName
public java.lang.String getName()
- Returns:
- the metric name
-
setName
public Metric<G> setName(java.lang.String name)
Sets the metric name- Parameters:
name
- the name- Returns:
- this
-
getWorstValue
public java.lang.Double getWorstValue()
-
getBestValue
@CheckForNull public java.lang.Double getBestValue()
-
setBestValue
public Metric<G> setBestValue(@Nullable java.lang.Double bestValue)
- Parameters:
bestValue
- the best value. It can be null.- Returns:
- this
-
isNumericType
public boolean isNumericType()
- Returns:
- whether the metric is of a numeric type (int, percentage...)
-
isDataType
public boolean isDataType()
- Returns:
- whether the metric is of type data
-
isPercentageType
public boolean isPercentageType()
- Returns:
- whether the metric is of type percentage
-
isOptimizedBestValue
@CheckForNull public java.lang.Boolean isOptimizedBestValue()
- Returns:
- null for manual metrics
-
isHidden
public java.lang.Boolean isHidden()
-
getDeleteHistoricalData
public java.lang.Boolean getDeleteHistoricalData()
-
getDecimalScale
@CheckForNull public java.lang.Integer getDecimalScale()
Return the number scale if metric type isMetric.ValueType.FLOAT
, elsenull
- Since:
- 5.3
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
merge
public Metric<G> merge(Metric with)
Merge with fields from other metric. All fields are copied, except the id.- Returns:
- this
-
key
public java.lang.String key()
-
-