diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2021-11-18 09:08:40 -0600 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2021-11-18 20:03:33 +0000 |
commit | 9f7a5068bb26f2760332c6e0bacec424e2edd47a (patch) | |
tree | 51ff128c6f77d1d15db5abe7960a90c74ee3d783 /sonar-plugin-api-impl | |
parent | eda9dff59cc60209b15b69ef4aa4c18885c0c744 (diff) | |
download | sonarqube-9f7a5068bb26f2760332c6e0bacec424e2edd47a.tar.gz sonarqube-9f7a5068bb26f2760332c6e0bacec424e2edd47a.zip |
Improve code quality
Diffstat (limited to 'sonar-plugin-api-impl')
4 files changed, 12 insertions, 7 deletions
diff --git a/sonar-plugin-api-impl/src/main/java/org/sonar/api/config/internal/MultivalueProperty.java b/sonar-plugin-api-impl/src/main/java/org/sonar/api/config/internal/MultivalueProperty.java index 41473a7f91e..338aca11c34 100644 --- a/sonar-plugin-api-impl/src/main/java/org/sonar/api/config/internal/MultivalueProperty.java +++ b/sonar-plugin-api-impl/src/main/java/org/sonar/api/config/internal/MultivalueProperty.java @@ -25,21 +25,24 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.function.Function; +import java.util.function.UnaryOperator; import org.apache.commons.csv.CSVFormat; import org.apache.commons.csv.CSVParser; import org.apache.commons.csv.CSVRecord; import org.apache.commons.lang.ArrayUtils; +import static java.util.function.UnaryOperator.identity; + public class MultivalueProperty { private MultivalueProperty() { // prevents instantiation } public static String[] parseAsCsv(String key, String value) { - return parseAsCsv(key, value, Function.identity()); + return parseAsCsv(key, value, identity()); } - public static String[] parseAsCsv(String key, String value, Function<String, String> valueProcessor) { + public static String[] parseAsCsv(String key, String value, UnaryOperator<String> valueProcessor) { String cleanValue = MultivalueProperty.trimFieldsAndRemoveEmptyFields(value); List<String> result = new ArrayList<>(); try (CSVParser csvParser = CSVFormat.RFC4180 diff --git a/sonar-plugin-api-impl/src/main/java/org/sonar/api/impl/server/RulesDefinitionContext.java b/sonar-plugin-api-impl/src/main/java/org/sonar/api/impl/server/RulesDefinitionContext.java index 90140b89905..437af08e5ec 100644 --- a/sonar-plugin-api-impl/src/main/java/org/sonar/api/impl/server/RulesDefinitionContext.java +++ b/sonar-plugin-api-impl/src/main/java/org/sonar/api/impl/server/RulesDefinitionContext.java @@ -58,6 +58,7 @@ public class RulesDefinitionContext extends RulesDefinition.Context { return unmodifiableList(new ArrayList<>(repositoriesByKey.values())); } + @Override public void registerRepository(DefaultNewRepository newRepository) { RulesDefinition.Repository existing = repositoriesByKey.get(newRepository.key()); if (existing != null) { @@ -69,6 +70,7 @@ public class RulesDefinitionContext extends RulesDefinition.Context { repositoriesByKey.put(newRepository.key(), new DefaultRepository(newRepository, existing)); } + @Override public String currentPluginKey() { return currentPluginKey; } diff --git a/sonar-plugin-api-impl/src/main/java/org/sonar/api/impl/utils/AlwaysIncreasingSystem2.java b/sonar-plugin-api-impl/src/main/java/org/sonar/api/impl/utils/AlwaysIncreasingSystem2.java index c0fb5b70b87..70a895ba4fd 100644 --- a/sonar-plugin-api-impl/src/main/java/org/sonar/api/impl/utils/AlwaysIncreasingSystem2.java +++ b/sonar-plugin-api-impl/src/main/java/org/sonar/api/impl/utils/AlwaysIncreasingSystem2.java @@ -21,7 +21,7 @@ package org.sonar.api.impl.utils; import java.security.SecureRandom; import java.util.concurrent.atomic.AtomicLong; -import java.util.function.Supplier; +import java.util.function.LongSupplier; import org.sonar.api.utils.System2; import static org.sonar.api.utils.Preconditions.checkArgument; @@ -38,9 +38,9 @@ public class AlwaysIncreasingSystem2 extends System2 { private final AtomicLong now; private final long increment; - private AlwaysIncreasingSystem2(Supplier<Long> initialValueSupplier, long increment) { + private AlwaysIncreasingSystem2(LongSupplier initialValueSupplier, long increment) { checkArgument(increment > 0, "increment must be > 0"); - long initialValue = initialValueSupplier.get(); + long initialValue = initialValueSupplier.getAsLong(); checkArgument(initialValue >= 0, "Initial value must be >= 0"); this.now = new AtomicLong(initialValue); this.increment = increment; diff --git a/sonar-plugin-api-impl/src/test/java/org/sonar/api/config/internal/MultivaluePropertyTest.java b/sonar-plugin-api-impl/src/test/java/org/sonar/api/config/internal/MultivaluePropertyTest.java index dff864dbd64..9ac4bedc574 100644 --- a/sonar-plugin-api-impl/src/test/java/org/sonar/api/config/internal/MultivaluePropertyTest.java +++ b/sonar-plugin-api-impl/src/test/java/org/sonar/api/config/internal/MultivaluePropertyTest.java @@ -23,12 +23,12 @@ import com.tngtech.java.junit.dataprovider.DataProvider; import com.tngtech.java.junit.dataprovider.DataProviderRunner; import com.tngtech.java.junit.dataprovider.UseDataProvider; import java.util.Random; -import java.util.function.Function; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; +import static java.util.function.UnaryOperator.identity; import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric; import static org.assertj.core.api.Assertions.assertThat; import static org.sonar.api.config.internal.MultivalueProperty.parseAsCsv; @@ -46,7 +46,7 @@ public class MultivaluePropertyTest { public void parseAsCsv_for_coverage(String value, String[] expected) { // parseAsCsv is extensively tested in org.sonar.server.config.ConfigurationProviderTest assertThat(parseAsCsv("key", value)) - .isEqualTo(parseAsCsv("key", value, Function.identity())) + .isEqualTo(parseAsCsv("key", value, identity())) .isEqualTo(expected); } |