Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
org.sonar.api.measures.Metric Maven / Gradle / Ivy
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2009 SonarSource SA
* mailto:contact AT sonarsource DOT com
*
* Sonar is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* Sonar is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
package org.sonar.api.measures;
import org.sonar.api.BatchExtension;
import org.sonar.api.ServerExtension;
import org.sonar.api.database.BaseIdentifiable;
import javax.persistence.*;
/**
* @since 1.10
*/
@Table(name = "metrics")
@Entity(name = "Metric")
public class Metric extends BaseIdentifiable implements ServerExtension, BatchExtension {
/**
* A metric bigger value means a degradation
*/
public final static int DIRECTION_WORST = -1;
/**
* A metric bigger value means an improvement
*/
public final static int DIRECTION_BETTER = 1;
/**
* The metric direction has no meaning
*/
public final static int DIRECTION_NONE = 0;
public enum ValueType {
INT, FLOAT, PERCENT, BOOL, STRING, MILLISEC, DATA, LEVEL, DISTRIB
}
public enum Level {
OK("Green"), WARN("Orange"), ERROR("Red");
private String colorName;
Level(String colorName) {
this.colorName = colorName;
}
public String getColorName() {
return colorName;
}
}
public enum Origin {
JAV, GUI, WS
}
@Transient
private Formula formula;
@Column(name = "name", updatable = false, nullable = false, length = 64)
private String key;
@Column(name = "description", updatable = true, nullable = true, length = 255)
private String description;
@Column(name = "val_type", updatable = true, nullable = true)
@Enumerated(EnumType.STRING)
private ValueType type;
@Column(name = "direction", updatable = true, nullable = true)
private Integer direction;
@Column(name = "domain", updatable = true, nullable = true, length = 60)
private String domain;
@Column(name = "short_name", updatable = true, nullable = true, length = 64)
private String name;
@Column(name = "qualitative", updatable = true, nullable = true)
private Boolean qualitative = Boolean.FALSE;
@Column(name = "user_managed", updatable = true, nullable = true)
private Boolean userManaged = Boolean.FALSE;
@Column(name = "enabled", updatable = true, nullable = true)
private Boolean enabled = Boolean.TRUE;
@Column(name = "origin", updatable = true, nullable = true, length = 3)
@Enumerated(EnumType.STRING)
private Origin origin;
public Metric() {
}
public Metric(String key) {
this(key, ValueType.INT);
}
public Metric(String key, ValueType type) {
this(key, key, key, type, -1, Boolean.FALSE, null, false);
}
public Metric(String key, String name, String description, ValueType type, Integer direction, Boolean qualitative, String domain) {
this(key, name, description, type, direction, qualitative, domain, false);
}
@Deprecated
public Metric(String key, String name, String description, ValueType type, Integer direction, Boolean qualitative, String domain, boolean userManaged) {
this.key = key;
this.description = description;
this.type = type;
this.direction = direction;
this.domain = domain;
this.name = name;
this.qualitative = qualitative;
this.userManaged = userManaged;
this.origin = Origin.JAV;
}
public Metric(String key, String name, ValueType type, Integer direction, Boolean qualitative, String domain, Formula formula) {
this.key = key;
this.name = name;
this.type = type;
this.direction = direction;
this.domain = domain;
this.qualitative = qualitative;
this.origin = Origin.JAV;
this.enabled = true;
this.userManaged = false;
this.formula = formula;
}
public Formula getFormula() {
return formula;
}
public Metric setFormula(Formula formula) {
this.formula = formula;
return this;
}
public Boolean getQualitative() {
return qualitative;
}
public void setQualitative(Boolean qualitative) {
this.qualitative = qualitative;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public ValueType getType() {
return type;
}
public void setType(ValueType type) {
this.type = type;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Boolean getUserManaged() {
return userManaged;
}
public void setUserManaged(Boolean userManaged) {
this.userManaged = userManaged;
}
public Boolean getEnabled() {
return enabled;
}
public void setEnabled(Boolean enabled) {
this.enabled = enabled;
}
public Integer getDirection() {
return direction;
}
public void setDirection(Integer direction) {
this.direction = direction;
}
public String getDomain() {
return domain;
}
public void setDomain(String domain) {
this.domain = domain;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Origin getOrigin() {
return origin;
}
public void setOrigin(Origin origin) {
this.origin = origin;
}
public boolean isNumericType() {
return ValueType.INT.equals(type)
|| ValueType.FLOAT.equals(type)
|| ValueType.PERCENT.equals(type)
|| ValueType.BOOL.equals(type)
|| ValueType.MILLISEC.equals(type);
}
public boolean isDataType() {
return ValueType.DATA.equals(type) || ValueType.DISTRIB.equals(type);
}
public boolean isPercentageType() {
return ValueType.PERCENT.equals(type);
}
@Override
public int hashCode() {
return key.hashCode();
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof Metric)) {
return false;
}
if (this == obj) {
return true;
}
Metric other = (Metric) obj;
return key.equals(other.getKey());
}
@Override
public String toString() {
return key;
}
}