Преглед изворни кода

Move validate() function to the bottom

tags/4.3
Julien Lancelot пре 10 година
родитељ
комит
2aba814fe3

+ 22
- 22
sonar-plugin-api/src/main/java/org/sonar/api/server/rule/DebtRemediationFunction.java Прегледај датотеку

@@ -56,28 +56,6 @@ public class DebtRemediationFunction {
validate();
}

private void validate(){
switch (type) {
case LINEAR:
if (this.factor == null || this.offset != null) {
throw new ValidationException(String.format("%s is invalid, Linear remediation function should only define a factor", this));
}
break;
case LINEAR_OFFSET:
if (this.factor == null || this.offset == null) {
throw new ValidationException(String.format("%s is invalid, Linear with offset remediation function should define both factor and offset", this));
}
break;
case CONSTANT_ISSUE:
if (this.factor != null || this.offset == null) {
throw new ValidationException(String.format("%s is invalid, Constant/issue remediation function should only define an offset", this));
}
break;
default:
throw new IllegalStateException(String.format("Remediation function of %s is unknown", this));
}
}

public static DebtRemediationFunction create(Type type, @Nullable String factor, @Nullable String offset) {
return new DebtRemediationFunction(type, factor, offset);
}
@@ -108,6 +86,28 @@ public class DebtRemediationFunction {
return offset;
}

private void validate(){
switch (type) {
case LINEAR:
if (this.factor == null || this.offset != null) {
throw new ValidationException(String.format("%s is invalid, Linear remediation function should only define a factor", this));
}
break;
case LINEAR_OFFSET:
if (this.factor == null || this.offset == null) {
throw new ValidationException(String.format("%s is invalid, Linear with offset remediation function should define both factor and offset", this));
}
break;
case CONSTANT_ISSUE:
if (this.factor != null || this.offset == null) {
throw new ValidationException(String.format("%s is invalid, Constant/issue remediation function should only define an offset", this));
}
break;
default:
throw new IllegalStateException(String.format("Remediation function of %s is unknown", this));
}
}

@Override
public boolean equals(Object o) {
if (this == o) {

Loading…
Откажи
Сачувај