diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2016-11-11 15:54:18 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2016-11-11 15:54:18 +0100 |
commit | 15e9f443eed5c74be9abe4738b07d62fe335c8e6 (patch) | |
tree | f8a3f00e91c202b615cd391ddc84470db8ca09c0 /sonar-core | |
parent | 129d630f52bd531f070969d806166f8c70593751 (diff) | |
download | sonarqube-15e9f443eed5c74be9abe4738b07d62fe335c8e6.tar.gz sonarqube-15e9f443eed5c74be9abe4738b07d62fe335c8e6.zip |
Fix Quality flaws about complexity
Diffstat (limited to 'sonar-core')
-rw-r--r-- | sonar-core/src/main/java/org/sonar/core/issue/FieldDiffs.java | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/FieldDiffs.java b/sonar-core/src/main/java/org/sonar/core/issue/FieldDiffs.java index 8bc22fa3554..8722f76fb27 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/FieldDiffs.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/FieldDiffs.java @@ -28,6 +28,8 @@ import java.util.Map; import javax.annotation.CheckForNull; import javax.annotation.Nullable; +import static com.google.common.base.Strings.isNullOrEmpty; + /** * PLUGINS MUST NOT USE THIS CLASS, EXCEPT FOR UNIT TESTING. * @@ -110,24 +112,25 @@ public class FieldDiffs implements Serializable { public static FieldDiffs parse(@Nullable String s) { FieldDiffs diffs = new FieldDiffs(); - if (!Strings.isNullOrEmpty(s)) { - Iterable<String> fields = FIELDS_SPLITTER.split(s); - for (String field : fields) { - String[] keyValues = field.split("="); - if (keyValues.length == 2) { - String[] values = keyValues[1].split("\\|"); - String oldValue = ""; - String newValue = ""; - if (values.length == 1) { - newValue = Strings.nullToEmpty(values[0]); - } else if (values.length == 2) { - oldValue = Strings.nullToEmpty(values[0]); - newValue = Strings.nullToEmpty(values[1]); - } - diffs.setDiff(keyValues[0], oldValue, newValue); - } else { - diffs.setDiff(keyValues[0], "", ""); + if (isNullOrEmpty(s)) { + return diffs; + } + Iterable<String> fields = FIELDS_SPLITTER.split(s); + for (String field : fields) { + String[] keyValues = field.split("="); + if (keyValues.length == 2) { + String[] values = keyValues[1].split("\\|"); + String oldValue = ""; + String newValue = ""; + if (values.length == 1) { + newValue = Strings.nullToEmpty(values[0]); + } else if (values.length == 2) { + oldValue = Strings.nullToEmpty(values[0]); + newValue = Strings.nullToEmpty(values[1]); } + diffs.setDiff(keyValues[0], oldValue, newValue); + } else { + diffs.setDiff(keyValues[0], "", ""); } } return diffs; |