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 withMetricsextension point.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMetric.BuilderMetric.Builder is used to create metric definitions.static classMetric.Levelstatic classMetric.ValueType
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_DECIMAL_SCALEstatic intDIRECTION_BETTERA metric bigger value means an improvementstatic intDIRECTION_NONEThe metric direction has no meaningstatic intDIRECTION_WORSTA metric bigger value means a degradationstatic intMAX_DECIMAL_SCALEThe 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.Builderfactory.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.Builderfactory.Metric(java.lang.String key, Metric.ValueType type)Deprecated.since 2.7 use theMetric.Builderfactory.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.Object obj)java.lang.DoublegetBestValue()java.lang.IntegergetDecimalScale()Return the number scale if metric type isMetric.ValueType.FLOAT, elsenulljava.lang.BooleangetDeleteHistoricalData()java.lang.StringgetDescription()java.lang.IntegergetDirection()java.lang.StringgetDomain()java.lang.BooleangetEnabled()java.lang.IntegergetId()For internal use onlyjava.lang.StringgetKey()java.lang.StringgetName()java.lang.BooleangetQualitative()Metric.ValueTypegetType()java.lang.BooleangetUserManaged()java.lang.DoublegetWorstValue()inthashCode()booleanisDataType()java.lang.BooleanisHidden()booleanisNumericType()java.lang.BooleanisOptimizedBestValue()booleanisPercentageType()java.lang.Stringkey()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>setId(java.lang.Integer id)For internal use onlyMetric<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>setWorstValue(java.lang.Double d)java.lang.StringtoString()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.Builderfactory.Creates an empty metric
-
Metric
@Deprecated public Metric(java.lang.String key)
Deprecated.since 2.7 use theMetric.Builderfactory.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.Builderfactory.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.Builderfactory.
-
-
Method Detail
-
getId
public java.lang.Integer getId()
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:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin 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()
-
-