]> source.dussan.org Git - sonarqube.git/commitdiff
Fix quality flaws
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 28 Sep 2015 14:44:57 +0000 (16:44 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 28 Sep 2015 14:45:11 +0000 (16:45 +0200)
sonar-plugin-api/src/main/java/org/sonar/api/server/debt/internal/DefaultDebtRemediationFunction.java

index a5bd987880c2c70ee5a5644af0c3df9d93a1d219..eaba94744d1388143f050d57266e74caffe6d3f2 100644 (file)
 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));