Skip to content

Polish code to use 'switch' instead of 'if', remove unessary unboxing and redundant cast #40985

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class AntoraAsciidocAttributes {
public AntoraAsciidocAttributes(Project project, BomExtension dependencyBom,
Map<String, String> dependencyVersions) {
this.version = String.valueOf(project.getVersion());
this.latestVersion = Boolean.valueOf(String.valueOf(project.findProperty("latestVersion")));
this.latestVersion = Boolean.parseBoolean(String.valueOf(project.findProperty("latestVersion")));
this.artifactRelease = ArtifactRelease.forProject(project);
this.libraries = dependencyBom.getLibraries();
this.dependencyVersions = dependencyVersions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,36 +70,24 @@ public void checkForProhibitedDependencies() {

private boolean prohibited(ModuleVersionIdentifier id) {
String group = id.getGroup();
if (group.equals("javax.batch")) {
return false;
}
if (group.equals("javax.cache")) {
return false;
}
if (group.equals("javax.money")) {
return false;
}
if (group.equals("org.codehaus.groovy")) {
return true;
}
if (group.equals("org.eclipse.jetty.toolchain")) {
return true;
switch (group) {
case "javax.batch", "javax.cache", "javax.money" -> {
return false;
}
case "commons-logging", "org.codehaus.groovy", "org.eclipse.jetty.toolchain",
"org.apache.geronimo.specs" -> {
return true;
}
}
if (group.startsWith("javax")) {
return true;
}
if (group.equals("commons-logging")) {
return true;
}
if (group.equals("org.slf4j") && id.getName().equals("jcl-over-slf4j")) {
return true;
}
if (group.startsWith("org.jboss.spec")) {
return true;
}
if (group.equals("org.apache.geronimo.specs")) {
return true;
}
return group.equals("com.sun.activation");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,10 @@ class ModifiedClassPathExtensionForkParameterizedTests {
@ParameterizedTest
@ValueSource(strings = { "one", "two", "three" })
void testIsInvokedOnceForEachArgument(String argument) {
if (argument.equals("one")) {
assertThat(arguments).isEmpty();
}
else if (argument.equals("two")) {
assertThat(arguments).doesNotContain("two", "three");
}
else if (argument.equals("three")) {
assertThat(arguments).doesNotContain("three");
switch (argument) {
case "one" -> assertThat(arguments).isEmpty();
case "two" -> assertThat(arguments).doesNotContain("two", "three");
case "three" -> assertThat(arguments).doesNotContain("three");
}
arguments.add(argument);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ private PropertyResolver getPropertyResolver() {
if (this.environment instanceof ConfigurableEnvironment configurableEnvironment) {
PropertySourcesPropertyResolver resolver = new PropertySourcesPropertyResolver(
configurableEnvironment.getPropertySources());
resolver.setConversionService(((ConfigurableEnvironment) this.environment).getConversionService());
resolver.setConversionService(configurableEnvironment.getConversionService());
resolver.setIgnoreUnresolvableNestedPlaceholders(true);
return resolver;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ protected boolean isMultiRelease() {
}
}
}
return this.multiRelease.booleanValue();
return this.multiRelease;
}

@Override
Expand Down