From 74c8f07db471391618d80ea30101e2af3f34bb35 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Mon, 28 Sep 2015 16:44:57 +0200 Subject: [PATCH] Fix quality flaws --- .../DefaultDebtRemediationFunction.java | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/debt/internal/DefaultDebtRemediationFunction.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/debt/internal/DefaultDebtRemediationFunction.java index a5bd987880c..eaba94744d1 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/server/debt/internal/DefaultDebtRemediationFunction.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/debt/internal/DefaultDebtRemediationFunction.java @@ -21,13 +21,14 @@ package org.sonar.api.server.debt.internal; import com.google.common.base.Objects; +import javax.annotation.CheckForNull; +import javax.annotation.Nullable; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.builder.EqualsBuilder; import org.sonar.api.server.debt.DebtRemediationFunction; import org.sonar.api.utils.Duration; -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; +import static com.google.common.base.Preconditions.checkArgument; public class DefaultDebtRemediationFunction implements DebtRemediationFunction { @@ -75,24 +76,16 @@ public class DefaultDebtRemediationFunction implements DebtRemediationFunction { } private void validate() { - if (type == null) { - throw new IllegalArgumentException("Remediation function type cannot be null"); - } + checkArgument(type != null, "Remediation function type cannot be null"); switch (type) { case LINEAR: - if (this.coefficient == null || this.offset != null) { - throw new IllegalArgumentException("Linear functions must only have a non empty coefficient"); - } + checkArgument(this.coefficient != null && this.offset == null, "Linear functions must only have a non empty coefficient"); break; case LINEAR_OFFSET: - if (this.coefficient == null || this.offset == null) { - throw new IllegalArgumentException("Linear with offset functions must have both non null coefficient and offset"); - } + checkArgument(this.coefficient != null && this.offset != null, "Linear with offset functions must have both non null coefficient and offset"); break; case CONSTANT_ISSUE: - if (this.coefficient != null || this.offset == null) { - throw new IllegalArgumentException("Constant/issue functions must only have a non empty offset"); - } + checkArgument(this.coefficient == null && this.offset != null, "Constant/issue functions must only have a non empty offset"); break; default: throw new IllegalArgumentException(String.format("Unknown type on %s", this)); -- 2.39.5