aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api/src
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2014-03-18 11:33:43 +0100
committerJulien Lancelot <julien.lancelot@sonarsource.com>2014-03-18 11:33:54 +0100
commitf9b18cc1aea5d6b80095664248ee18a5afb8a655 (patch)
tree2e8e40be6c081bfc81ede4269c0d7c584e650a79 /sonar-plugin-api/src
parentd4cc5ad93f1043e9f992be95dc5b1b1e056ea7c7 (diff)
downloadsonarqube-f9b18cc1aea5d6b80095664248ee18a5afb8a655.tar.gz
sonarqube-f9b18cc1aea5d6b80095664248ee18a5afb8a655.zip
Fix quality flaws
Diffstat (limited to 'sonar-plugin-api/src')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/DebtRemediationFunction.java29
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Rule.java2
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/server/rule/DebtRemediationFunction.java29
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/rule/DebtRemediationFunctionTest.java38
4 files changed, 44 insertions, 54 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/DebtRemediationFunction.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/DebtRemediationFunction.java
index 60f3faccefe..459f96655de 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/DebtRemediationFunction.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/DebtRemediationFunction.java
@@ -20,6 +20,8 @@
package org.sonar.api.batch.rule;
+import org.apache.commons.lang.builder.EqualsBuilder;
+import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.sonar.api.utils.Duration;
@@ -84,28 +86,21 @@ public class DebtRemediationFunction {
if (o == null || getClass() != o.getClass()) {
return false;
}
-
DebtRemediationFunction that = (DebtRemediationFunction) o;
-
- if (type != that.type) {
- return false;
- }
- if (factor != null ? !factor.equals(that.factor) : that.factor != null) {
- return false;
- }
- if (offset != null ? !offset.equals(that.offset) : that.offset != null) {
- return false;
- }
-
- return true;
+ return new EqualsBuilder()
+ .append(type, that.type())
+ .append(factor, that.factor())
+ .append(offset, that.offset())
+ .isEquals();
}
@Override
public int hashCode() {
- int result = type.hashCode();
- result = 31 * result + (factor != null ? factor.hashCode() : 0);
- result = 31 * result + (offset != null ? offset.hashCode() : 0);
- return result;
+ return new HashCodeBuilder(15, 31)
+ .append(type)
+ .append(factor)
+ .append(offset)
+ .toHashCode();
}
@Override
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Rule.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Rule.java
index 27a75566c09..b1aed121df0 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Rule.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Rule.java
@@ -61,7 +61,7 @@ public interface Rule {
String debtCharacteristic();
/**
- * Remediation function : one of LINEAR (with a factor), LINEAR_OFFSET (with a factor and an offset) or CONSTANT_ISSUE (with an offset)
+ * Remediation function : can by Linear (with a factor), Linear with offset (with a factor and an offset) or Constant per issue (with an offset)
*
* @since 4.3
*/
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/DebtRemediationFunction.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/DebtRemediationFunction.java
index 74b95aea2f1..476fe769849 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/DebtRemediationFunction.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/DebtRemediationFunction.java
@@ -21,6 +21,8 @@
package org.sonar.api.server.rule;
import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.builder.EqualsBuilder;
+import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
@@ -37,7 +39,6 @@ public class DebtRemediationFunction {
}
public static class ValidationException extends RuntimeException {
-
public ValidationException(String message) {
super(message);
}
@@ -117,26 +118,20 @@ public class DebtRemediationFunction {
}
DebtRemediationFunction that = (DebtRemediationFunction) o;
-
- if (type != that.type) {
- return false;
- }
- if (factor != null ? !factor.equals(that.factor) : that.factor != null) {
- return false;
- }
- if (offset != null ? !offset.equals(that.offset) : that.offset != null) {
- return false;
- }
-
- return true;
+ return new EqualsBuilder()
+ .append(type, that.type())
+ .append(factor, that.factor())
+ .append(offset, that.offset())
+ .isEquals();
}
@Override
public int hashCode() {
- int result = type.hashCode();
- result = 31 * result + (factor != null ? factor.hashCode() : 0);
- result = 31 * result + (offset != null ? offset.hashCode() : 0);
- return result;
+ return new HashCodeBuilder(15, 33)
+ .append(type)
+ .append(factor)
+ .append(offset)
+ .toHashCode();
}
@Override
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/rule/DebtRemediationFunctionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/rule/DebtRemediationFunctionTest.java
index a377c4abb73..7f5ec006ce9 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/rule/DebtRemediationFunctionTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/rule/DebtRemediationFunctionTest.java
@@ -21,7 +21,7 @@
package org.sonar.api.batch.rule;
import org.junit.Test;
-import org.sonar.api.server.rule.DebtRemediationFunction;
+import org.sonar.api.utils.Duration;
import static org.fest.assertions.Assertions.assertThat;
@@ -29,41 +29,41 @@ public class DebtRemediationFunctionTest {
@Test
public void create_linear() throws Exception {
- org.sonar.api.server.rule.DebtRemediationFunction function = org.sonar.api.server.rule.DebtRemediationFunction.createLinear("10h");
- assertThat(function.type()).isEqualTo(org.sonar.api.server.rule.DebtRemediationFunction.Type.LINEAR);
- assertThat(function.factor()).isEqualTo("10h");
+ DebtRemediationFunction function = DebtRemediationFunction.createLinear(Duration.create(10));
+ assertThat(function.type()).isEqualTo(DebtRemediationFunction.Type.LINEAR);
+ assertThat(function.factor()).isEqualTo(Duration.create(10));
assertThat(function.offset()).isNull();
}
@Test
public void create_linear_with_offset() throws Exception {
- org.sonar.api.server.rule.DebtRemediationFunction function = org.sonar.api.server.rule.DebtRemediationFunction.createLinearWithOffset("10h", "5min");
- assertThat(function.type()).isEqualTo(org.sonar.api.server.rule.DebtRemediationFunction.Type.LINEAR_OFFSET);
- assertThat(function.factor()).isEqualTo("10h");
- assertThat(function.offset()).isEqualTo("5min");
+ DebtRemediationFunction function = DebtRemediationFunction.createLinearWithOffset(Duration.create(10), Duration.create(5));
+ assertThat(function.type()).isEqualTo(DebtRemediationFunction.Type.LINEAR_OFFSET);
+ assertThat(function.factor()).isEqualTo(Duration.create(10));
+ assertThat(function.offset()).isEqualTo(Duration.create(5));
}
@Test
public void create_constant_per_issue() throws Exception {
- org.sonar.api.server.rule.DebtRemediationFunction function = org.sonar.api.server.rule.DebtRemediationFunction.createConstantPerIssue("10h");
- assertThat(function.type()).isEqualTo(org.sonar.api.server.rule.DebtRemediationFunction.Type.CONSTANT_ISSUE);
+ DebtRemediationFunction function = DebtRemediationFunction.createConstantPerIssue(Duration.create(10));
+ assertThat(function.type()).isEqualTo(DebtRemediationFunction.Type.CONSTANT_ISSUE);
assertThat(function.factor()).isNull();
- assertThat(function.offset()).isEqualTo("10h");
+ assertThat(function.offset()).isEqualTo(Duration.create(10));
}
@Test
public void test_equals_and_hashcode() throws Exception {
- org.sonar.api.server.rule.DebtRemediationFunction function = org.sonar.api.server.rule.DebtRemediationFunction.createLinearWithOffset("10h", "5min");
- org.sonar.api.server.rule.DebtRemediationFunction functionWithSameValue = org.sonar.api.server.rule.DebtRemediationFunction.createLinearWithOffset("10h", "5min");
- org.sonar.api.server.rule.DebtRemediationFunction functionWithDifferentType = org.sonar.api.server.rule.DebtRemediationFunction.createConstantPerIssue("5min");
+ DebtRemediationFunction function = DebtRemediationFunction.createLinearWithOffset(Duration.create(10), Duration.create(5));
+ DebtRemediationFunction functionWithSameValue = DebtRemediationFunction.createLinearWithOffset(Duration.create(10), Duration.create(5));
+ DebtRemediationFunction functionWithDifferentType = DebtRemediationFunction.createConstantPerIssue(Duration.create(5));
assertThat(function).isEqualTo(function);
assertThat(function).isEqualTo(functionWithSameValue);
assertThat(function).isNotEqualTo(functionWithDifferentType);
- assertThat(function).isNotEqualTo(org.sonar.api.server.rule.DebtRemediationFunction.createLinearWithOffset("11h", "5min"));
- assertThat(function).isNotEqualTo(org.sonar.api.server.rule.DebtRemediationFunction.createLinearWithOffset("10h", "6min"));
- assertThat(function).isNotEqualTo(org.sonar.api.server.rule.DebtRemediationFunction.createLinear("10h"));
- assertThat(function).isNotEqualTo(org.sonar.api.server.rule.DebtRemediationFunction.createConstantPerIssue("6min"));
+ assertThat(function).isNotEqualTo(DebtRemediationFunction.createLinearWithOffset(Duration.create(11), Duration.create(5)));
+ assertThat(function).isNotEqualTo(DebtRemediationFunction.createLinearWithOffset(Duration.create(10), Duration.create(6)));
+ assertThat(function).isNotEqualTo(DebtRemediationFunction.createLinear(Duration.create(10)));
+ assertThat(function).isNotEqualTo(DebtRemediationFunction.createConstantPerIssue(Duration.create(6)));
assertThat(function.hashCode()).isEqualTo(function.hashCode());
assertThat(function.hashCode()).isEqualTo(functionWithSameValue.hashCode());
@@ -72,6 +72,6 @@ public class DebtRemediationFunctionTest {
@Test
public void test_to_string() throws Exception {
- assertThat(DebtRemediationFunction.createLinearWithOffset("10h", "5min").toString()).isNotNull();
+ assertThat(DebtRemediationFunction.createLinearWithOffset(Duration.create(10), Duration.create(5)).toString()).isNotNull();
}
}