diff options
author | Matteo Mara <matteo.mara@sonarsource.com> | 2023-01-06 12:59:21 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2023-01-10 20:03:01 +0000 |
commit | 18f91c25d369917f3a99841f6bb31b94a02467fc (patch) | |
tree | 9939b8dfb10c74b95a5addbcadb8fb91ba296f31 /server/sonar-webserver-webapi | |
parent | 215dd7343dc55f91613b820d43c208c19a50d176 (diff) | |
download | sonarqube-18f91c25d369917f3a99841f6bb31b94a02467fc.tar.gz sonarqube-18f91c25d369917f3a99841f6bb31b94a02467fc.zip |
[NO-JIRA] Remove reported code smells about switch statements
Diffstat (limited to 'server/sonar-webserver-webapi')
4 files changed, 25 insertions, 59 deletions
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java index 86407ec6e62..56ecd44fdb4 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java @@ -291,14 +291,10 @@ public class SearchProjectsAction implements ComponentsWsAction { return Sets.newHashSet(Qualifiers.PROJECT); } - switch (edition.get()) { - case ENTERPRISE: - case DATACENTER: - case DEVELOPER: - return Sets.newHashSet(Qualifiers.PROJECT, Qualifiers.APP); - default: - return Sets.newHashSet(Qualifiers.PROJECT); - } + return switch (edition.get()) { + case ENTERPRISE, DATACENTER, DEVELOPER -> Sets.newHashSet(Qualifiers.PROJECT, Qualifiers.APP); + default -> Sets.newHashSet(Qualifiers.PROJECT); + }; } private static boolean hasFavoriteFilter(List<Criterion> criteria) { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MeasureValueFormatter.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MeasureValueFormatter.java index 0540cc7fa11..b6049734459 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MeasureValueFormatter.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MeasureValueFormatter.java @@ -50,50 +50,26 @@ public class MeasureValueFormatter { @CheckForNull static String formatMeasureValue(double doubleValue, @Nullable String stringValue, MetricDto metric) { Metric.ValueType metricType = Metric.ValueType.valueOf(metric.getValueType()); - switch (metricType) { - case BOOL: - return formatBoolean(doubleValue); - case INT: - return formatInteger(doubleValue); - case MILLISEC: - case WORK_DUR: - return formatLong(doubleValue); - case FLOAT: - case PERCENT: - case RATING: - return String.valueOf(doubleValue); - case LEVEL: - case STRING: - case DATA: - case DISTRIB: - return stringValue; - default: - throw new IllegalArgumentException("Unsupported metric type: " + metricType.name()); - } + return switch (metricType) { + case BOOL -> formatBoolean(doubleValue); + case INT -> formatInteger(doubleValue); + case MILLISEC, WORK_DUR -> formatLong(doubleValue); + case FLOAT, PERCENT, RATING -> String.valueOf(doubleValue); + case LEVEL, STRING, DATA, DISTRIB -> stringValue; + default -> throw new IllegalArgumentException("Unsupported metric type: " + metricType.name()); + }; } static String formatNumericalValue(double value, MetricDto metric) { Metric.ValueType metricType = Metric.ValueType.valueOf(metric.getValueType()); - switch (metricType) { - case BOOL: - return formatBoolean(value); - case INT: - return formatInteger(value); - case MILLISEC: - case WORK_DUR: - return formatLong(value); - case FLOAT: - case PERCENT: - case RATING: - return String.valueOf(value); - case LEVEL: - case STRING: - case DATA: - case DISTRIB: - default: - throw new IllegalArgumentException(String.format("Unsupported metric type '%s' for numerical value", metricType.name())); - } + return switch (metricType) { + case BOOL -> formatBoolean(value); + case INT -> formatInteger(value); + case MILLISEC, WORK_DUR -> formatLong(value); + case FLOAT, PERCENT, RATING -> String.valueOf(value); + default -> throw new IllegalArgumentException(String.format("Unsupported metric type '%s' for numerical value", metricType.name())); + }; } private static String formatBoolean(double value) { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/CurrentAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/CurrentAction.java index 708afcc5e29..17dfe192cb9 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/CurrentAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/CurrentAction.java @@ -221,13 +221,10 @@ public class CurrentAction implements UsersWsAction { if (!edition.isPresent()) { return false; } - switch (edition.get()) { - case ENTERPRISE: - case DATACENTER: - return true; - default: - return false; - } + return switch (edition.get()) { + case ENTERPRISE, DATACENTER -> true; + default -> false; + }; } private void cleanUserHomepageInDb(DbSession dbSession, UserDto user) { diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/SetHomepageAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/SetHomepageAction.java index 8c87eae9cb2..3c9f7d18168 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/SetHomepageAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/user/ws/SetHomepageAction.java @@ -121,13 +121,10 @@ public class SetHomepageAction implements UsersWsAction { } else { return projectDto.getUuid(); } - case PORTFOLIO: - case APPLICATION: + case PORTFOLIO, APPLICATION: checkArgument(isNotBlank(componentParameter), PARAMETER_REQUIRED, type.name(), PARAM_COMPONENT); return componentFinder.getByKey(dbSession, componentParameter).uuid(); - case PORTFOLIOS: - case PROJECTS: - case ISSUES: + case PORTFOLIOS, PROJECTS, ISSUES: return null; default: throw new IllegalArgumentException(format("Unknown type '%s'", type.name())); |