org.sonar.api.measures
Class Metric<G extends Serializable>

java.lang.Object
  extended by org.sonar.api.measures.Metric<G>
All Implemented Interfaces:
Serializable, Metric<G>, BatchComponent, BatchExtension, Extension, ServerComponent, ServerExtension

public class Metric<G extends Serializable>
extends Object
implements ServerExtension, BatchExtension, Serializable, Metric<G>

This class represents the definition of a metric in Sonar.

Since:
1.10
See Also:
Serialized Form

Nested Class Summary
static class Metric.Builder
          Metric.Builder is used to create metric definitions.
static class Metric.Level
           
static class Metric.Origin
           
static class Metric.ValueType
           
 
Field Summary
static int DIRECTION_BETTER
          A metric bigger value means an improvement
static int DIRECTION_NONE
          The metric direction has no meaning
static int DIRECTION_WORST
          A metric bigger value means a degradation
 
Constructor Summary
Metric()
          Deprecated. in 1.12. Use the Metric.Builder factory.
Metric(String key)
          Deprecated. since 2.7 use the Metric.Builder factory.
Metric(String key, Metric.ValueType type)
          Deprecated. since 2.7 use the Metric.Builder factory.
Metric(String key, String name, String description, Metric.ValueType type, Integer direction, Boolean qualitative, String domain)
          Deprecated. since 2.7 use the Metric.Builder factory.
 
Method Summary
 boolean equals(Object obj)
           
 Double getBestValue()
           
 Boolean getDeleteHistoricalData()
           
 String getDescription()
           
 Integer getDirection()
           
 String getDomain()
           
 Boolean getEnabled()
           
 Formula getFormula()
           
 Integer getId()
          For internal use only
 String getKey()
           
 String getName()
           
 Metric.Origin getOrigin()
           
 Boolean getQualitative()
           
 Metric.ValueType getType()
           
 Boolean getUserManaged()
           
 Double getWorstValue()
           
 int hashCode()
           
 boolean isDataType()
           
 Boolean isHidden()
           
 boolean isNumericType()
           
 Boolean isOptimizedBestValue()
           
 boolean isPercentageType()
           
 String key()
           
 Metric merge(Metric with)
          Merge with fields from other metric.
 Metric setBestValue(Double bestValue)
           
 Metric setDescription(String description)
          Sets the metric description
 Metric setDirection(Integer direction)
          Sets the metric direction.
 Metric setDomain(String domain)
          Sets the domain for the metric (General, Complexity...)
 Metric setEnabled(Boolean enabled)
          Sets whether the metric is enabled
 Metric setFormula(Formula formula)
          Sets the metric formula
 Metric setHidden(Boolean hidden)
           
 Metric setId(Integer id)
          For internal use only
 Metric setKey(String key)
          Sets the metric key
 Metric setName(String name)
          Sets the metric name
 Metric setOptimizedBestValue(Boolean b)
           
 Metric setOrigin(Metric.Origin origin)
          Set the origin of the metric - Internal use only
 Metric setQualitative(Boolean qualitative)
          Sets whether the metric is qualitative
 Metric setType(Metric.ValueType type)
          Sets the metric type
 Metric setUserManaged(Boolean userManaged)
          Sets whether the metric is managed by users ("manual metric")
 Metric setWorstValue(Double d)
           
 String toString()
           
 Class<G> valueType()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

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 the Metric.Builder factory.

Creates an empty metric. Required for Hibernate.


Metric

@Deprecated
public Metric(String key)
Deprecated. since 2.7 use the Metric.Builder factory.

Creates a metric based on its key. Shortcut to Metric(key, ValueType.INT)

Parameters:
key - the metric key

Metric

@Deprecated
public Metric(String key,
                         Metric.ValueType type)
Deprecated. since 2.7 use the Metric.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 key
type - the type

Metric

@Deprecated
public Metric(String key,
                         String name,
                         String description,
                         Metric.ValueType type,
                         Integer direction,
                         Boolean qualitative,
                         String domain)
Deprecated. since 2.7 use the Metric.Builder factory.

Method Detail

getId

public Integer getId()
For internal use only


setId

public Metric setId(@Nullable
                    Integer id)
For internal use only


getFormula

public Formula getFormula()
Returns:
the metric formula

setFormula

public Metric setFormula(Formula formula)
Sets the metric formula

Parameters:
formula - the formula
Returns:
this

getQualitative

public Boolean getQualitative()
Returns:
wether the metric is qualitative

setQualitative

public Metric setQualitative(Boolean qualitative)
Sets whether the metric is qualitative

Parameters:
qualitative - whether the metric is qualitative
Returns:
this

getKey

public String getKey()
Returns:
the metric key

setKey

public Metric setKey(String key)
Sets the metric key

Parameters:
key - the key
Returns:
this

getType

public Metric.ValueType getType()
Returns:
the metric type

setType

public Metric setType(Metric.ValueType type)
Sets the metric type

Parameters:
type - the type
Returns:
this

getDescription

@CheckForNull
public String getDescription()
Returns:
the metric description

setDescription

public Metric setDescription(@Nullable
                             String description)
Sets the metric description

Parameters:
description - the description
Returns:
this

getUserManaged

public Boolean getUserManaged()
Returns:
whether the metric is a managed by the users ("manual metric")

setUserManaged

public Metric setUserManaged(Boolean userManaged)
Sets whether the metric is managed by users ("manual metric")

Parameters:
userManaged - whether the metric is user managed
Returns:
this

getEnabled

public Boolean getEnabled()
Returns:
whether the metric is enabled

setEnabled

public Metric setEnabled(Boolean enabled)
Sets whether the metric is enabled

Parameters:
enabled - whether the metric is enabled
Returns:
this

getDirection

public Integer getDirection()
Returns:
the metric direction

setDirection

public Metric setDirection(Integer direction)
Sets the metric direction.

Parameters:
direction - the direction

getDomain

public String getDomain()
Returns:
the domain of the metric

setDomain

public Metric setDomain(String domain)
Sets the domain for the metric (General, Complexity...)

Parameters:
domain - the domain
Returns:
this

getName

public String getName()
Returns:
the metric name

setName

public Metric setName(String name)
Sets the metric name

Parameters:
name - the name
Returns:
this

getOrigin

public Metric.Origin getOrigin()
Returns:
the origin of the metric - Internal use only

setOrigin

public Metric setOrigin(Metric.Origin origin)
Set the origin of the metric - Internal use only

Parameters:
origin - the origin
Returns:
this

getWorstValue

public Double getWorstValue()

getBestValue

@CheckForNull
public Double getBestValue()

setWorstValue

public Metric setWorstValue(@Nullable
                            Double d)
Returns:
this

setBestValue

public Metric setBestValue(@Nullable
                           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

setOptimizedBestValue

public Metric setOptimizedBestValue(@Nullable
                                    Boolean b)

isOptimizedBestValue

@CheckForNull
public Boolean isOptimizedBestValue()
Returns:
null for manual metrics

isHidden

public Boolean isHidden()

setHidden

public Metric setHidden(Boolean hidden)

getDeleteHistoricalData

public Boolean getDeleteHistoricalData()

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

toString

public String toString()
Overrides:
toString in class Object

merge

public Metric merge(Metric with)
Merge with fields from other metric. All fields are copied, except the id.

Returns:
this

key

public String key()
Specified by:
key in interface Metric<G extends Serializable>

valueType

public Class<G> valueType()
Specified by:
valueType in interface Metric<G extends Serializable>


Copyright © 2009–2015 SonarSource. All rights reserved.