org.sonar.api.measures
Class Metric

java.lang.Object
  extended by org.sonar.api.database.BaseIdentifiable
      extended by org.sonar.api.measures.Metric
All Implemented Interfaces:
BatchExtension, Extension, ServerExtension

public class Metric
extends BaseIdentifiable
implements ServerExtension, BatchExtension

Since:
1.10

Nested Class Summary
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. 
Metric(String key)
          Creates a metric based on its key.
Metric(String key, Metric.ValueType type)
          Creates a metric based on a key and a type.
Metric(String key, String name, Metric.ValueType type, Integer direction, Boolean qualitative, String domain, Formula formula)
          Creates a fully qualified metric.
Metric(String key, String name, String description, Metric.ValueType type, Integer direction, Boolean qualitative, String domain)
           
Metric(String key, String name, String description, Metric.ValueType type, Integer direction, Boolean qualitative, String domain, boolean userManaged)
          Deprecated. 
 
Method Summary
 boolean equals(Object obj)
           
 Double getBestValue()
           
 String getDescription()
           
 Integer getDirection()
           
 String getDomain()
           
 Boolean getEnabled()
           
 Formula getFormula()
           
 String getKey()
           
 String getName()
           
 Metric.Origin getOrigin()
           
 Boolean getQualitative()
           
 Metric.ValueType getType()
           
 Boolean getUserManaged()
           
 Double getWorstValue()
           
 int hashCode()
           
 boolean isDataType()
           
 boolean isNumericType()
           
 Boolean isOptimizedBestValue()
           
 boolean isPercentageType()
           
 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 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 user managed
 Metric setWorstValue(Double d)
           
 String toString()
           
 
Methods inherited from class org.sonar.api.database.BaseIdentifiable
getId, setId
 
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. 

Creates an empty metric


Metric

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

Parameters:
key - the metric key

Metric

public Metric(String key,
              Metric.ValueType type)
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

public Metric(String key,
              String name,
              String description,
              Metric.ValueType type,
              Integer direction,
              Boolean qualitative,
              String domain)

Metric

@Deprecated
public Metric(String key,
                         String name,
                         String description,
                         Metric.ValueType type,
                         Integer direction,
                         Boolean qualitative,
                         String domain,
                         boolean userManaged)
Deprecated. 

Creates a fully qualified metric. This defaults some values:

Parameters:
key - the metric key
name - the metric name
description - the metric description
type - the metric type
direction - the metric direction
qualitative - whether the metric is qualitative
domain - the metric domain
userManaged - whether the metric is user managed

Metric

public Metric(String key,
              String name,
              Metric.ValueType type,
              Integer direction,
              Boolean qualitative,
              String domain,
              Formula formula)
Creates a fully qualified metric. This defaults some values:

Parameters:
key - the metric key
name - the metric name
type - the metric type
direction - the metric direction
qualitative - whether the metric is qualitative
domain - the metric domain
formula - the metric formula
Method Detail

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

public String getDescription()
Returns:
the metric description

setDescription

public Metric setDescription(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 user managed

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

public Double getBestValue()

setWorstValue

public Metric setWorstValue(Double d)
Returns:
this

setBestValue

public Metric setBestValue(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(Boolean b)

isOptimizedBestValue

public Boolean isOptimizedBestValue()

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


Copyright © 2009 SonarSource SA. All Rights Reserved.