Merge pull request #39259 from tobias-lippert

* pr/39259:
  Update copyright header of cleaned up code
  Replace !Optional.isPresent with Optional.isEmpty
  Polish 'Simplify stream chain operations'
  Simplify stream chain operations
  Polish 'Remove redundant array creation'
  Remove redundant array creation
  Replace multiple ifs with switch
  Use try with resources instead of try-finally
  Replace explicit type with diamond operator
  Avoid redundant boxing
  Remove redundant boxing
  Polish 'Use pattern variables'
  Use pattern variables
  Use string.repeat()
  Polish 'Simplify conditionals'
  Simplify conditionals
  Inline redundant if statements
  Remove unnecessary semicolons
  Remove unnecessary toString calls

Closes gh-39259
This commit is contained in:
Phillip Webb
2024-01-23 10:47:15 -08:00
63 changed files with 175 additions and 245 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -291,9 +291,7 @@ public class BomPlugin implements Plugin<Project> {
if ((node.name() instanceof QName qname) && name.equals(qname.getLocalPart())) {
return true;
}
if (name.equals(node.name())) {
return true;
}
return name.equals(node.name());
}
return false;
}

View File

@@ -194,7 +194,7 @@ public abstract class UpgradeDependencies extends DefaultTask {
java.util.Optional<Milestone> matchingMilestone = milestones.stream()
.filter((milestone) -> milestone.getName().equals(getMilestone().get()))
.findFirst();
if (!matchingMilestone.isPresent()) {
if (matchingMilestone.isEmpty()) {
throw new InvalidUserDataException("Unknown milestone: " + getMilestone().get());
}
return matchingMilestone.get();
@@ -242,9 +242,9 @@ public abstract class UpgradeDependencies extends DefaultTask {
}
private boolean isNotProhibited(Library library, DependencyVersion candidate) {
return !library.getProhibitedVersions()
return library.getProhibitedVersions()
.stream()
.anyMatch((prohibited) -> prohibited.isProhibited(candidate.toString()));
.noneMatch((prohibited) -> prohibited.isProhibited(candidate.toString()));
}
private List<Library> matchingLibraries() {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -58,10 +58,7 @@ abstract class AbstractDependencyVersion implements DependencyVersion {
return false;
}
AbstractDependencyVersion other = (AbstractDependencyVersion) obj;
if (!this.comparableVersion.equals(other.comparableVersion)) {
return false;
}
return true;
return this.comparableVersion.equals(other.comparableVersion);
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -64,22 +64,25 @@ final class ReleaseTrainDependencyVersion implements DependencyVersion {
@Override
public boolean isUpgrade(DependencyVersion candidate, boolean movingToSnapshots) {
if (!(candidate instanceof ReleaseTrainDependencyVersion)) {
return true;
if (candidate instanceof ReleaseTrainDependencyVersion candidateReleaseTrain) {
return isUpgrade(candidateReleaseTrain, movingToSnapshots);
}
ReleaseTrainDependencyVersion candidateReleaseTrain = (ReleaseTrainDependencyVersion) candidate;
int comparison = this.releaseTrain.compareTo(candidateReleaseTrain.releaseTrain);
return true;
}
private boolean isUpgrade(ReleaseTrainDependencyVersion candidate, boolean movingToSnapshots) {
int comparison = this.releaseTrain.compareTo(candidate.releaseTrain);
if (comparison != 0) {
return comparison < 0;
}
if (movingToSnapshots && !isSnapshot() && candidateReleaseTrain.isSnapshot()) {
if (movingToSnapshots && !isSnapshot() && candidate.isSnapshot()) {
return true;
}
comparison = this.type.compareTo(candidateReleaseTrain.type);
comparison = this.type.compareTo(candidate.type);
if (comparison != 0) {
return comparison < 0;
}
return Integer.compare(this.version, candidateReleaseTrain.version) < 0;
return Integer.compare(this.version, candidate.version) < 0;
}
private boolean isSnapshot() {
@@ -88,10 +91,9 @@ final class ReleaseTrainDependencyVersion implements DependencyVersion {
@Override
public boolean isSnapshotFor(DependencyVersion candidate) {
if (!isSnapshot() || !(candidate instanceof ReleaseTrainDependencyVersion)) {
if (!isSnapshot() || !(candidate instanceof ReleaseTrainDependencyVersion candidateReleaseTrain)) {
return false;
}
ReleaseTrainDependencyVersion candidateReleaseTrain = (ReleaseTrainDependencyVersion) candidate;
return this.releaseTrain.equals(candidateReleaseTrain.releaseTrain);
}
@@ -127,10 +129,7 @@ final class ReleaseTrainDependencyVersion implements DependencyVersion {
return false;
}
ReleaseTrainDependencyVersion other = (ReleaseTrainDependencyVersion) obj;
if (!this.original.equals(other.original)) {
return false;
}
return true;
return this.original.equals(other.original);
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -100,10 +100,7 @@ public class CheckClasspathForProhibitedDependencies extends DefaultTask {
if (group.equals("org.apache.geronimo.specs")) {
return true;
}
if (group.equals("com.sun.activation")) {
return true;
}
return false;
return group.equals("com.sun.activation");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -65,11 +65,9 @@ public class CloudFoundryWebEndpointDiscoverer extends WebEndpointDiscoverer {
@Override
protected boolean isExtensionTypeExposed(Class<?> extensionBeanType) {
if (isHealthEndpointExtension(extensionBeanType) && !isCloudFoundryHealthEndpointExtension(extensionBeanType)) {
// Filter regular health endpoint extensions so a CF version can replace them
return false;
}
return true;
// Filter regular health endpoint extensions so a CF version can replace them
return !isHealthEndpointExtension(extensionBeanType)
|| isCloudFoundryHealthEndpointExtension(extensionBeanType);
}
private boolean isHealthEndpointExtension(Class<?> extensionBeanType) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,6 +37,6 @@ public enum InfoContributorFallback {
/**
* Do not fall back, thereby disabling the info contributor.
*/
DISABLE;
DISABLE
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -90,7 +90,7 @@ public final class MeterValue {
if (duration != null) {
return new MeterValue(duration);
}
return new MeterValue(Double.valueOf(value));
return new MeterValue(Double.parseDouble(value));
}
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -116,7 +116,7 @@ public class SignalFxProperties extends StepRegistryProperties {
/**
* Delta histogram.
*/
DELTA;
DELTA
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -136,9 +136,7 @@ public final class EndpointRequest {
return true;
}
String managementContextId = applicationContext.getParent().getId() + ":management";
if (!managementContextId.equals(applicationContext.getId())) {
return true;
}
return !managementContextId.equals(applicationContext.getId());
}
return false;
}

View File

@@ -268,7 +268,7 @@ public class TracingProperties {
* <a href="https://github.com/openzipkin/b3-propagation#multiple-headers">B3
* multiple headers</a> propagation.
*/
B3_MULTI;
B3_MULTI
}

View File

@@ -68,7 +68,10 @@ class OperationMethodParameter implements OperationParameter {
if (!ObjectUtils.isEmpty(this.parameter.getAnnotationsByType(Nullable.class))) {
return false;
}
return (jsr305Present) ? new Jsr305().isMandatory(this.parameter) : true;
if (jsr305Present) {
return new Jsr305().isMandatory(this.parameter);
}
return true;
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -482,7 +482,7 @@ public class CassandraProperties {
/**
* No compression.
*/
NONE;
NONE
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -224,7 +224,7 @@ public class JacksonProperties {
* Refuse to decide implicit mode and instead throw an InvalidDefinitionException
* for ambiguous cases.
*/
EXPLICIT_ONLY;
EXPLICIT_ONLY
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -55,8 +55,12 @@ public class ClassLoaderFile implements Serializable {
*/
public ClassLoaderFile(Kind kind, long lastModified, byte[] contents) {
Assert.notNull(kind, "Kind must not be null");
Assert.isTrue((kind != Kind.DELETED) ? contents != null : contents == null,
() -> "Contents must " + ((kind != Kind.DELETED) ? "not " : "") + "be null");
if (kind == Kind.DELETED) {
Assert.isTrue(contents == null, "Contents must be null");
}
else {
Assert.isTrue(contents != null, "Contents must not be null");
}
this.kind = kind;
this.lastModified = lastModified;
this.contents = contents;

View File

@@ -44,7 +44,7 @@ class OverrideAutoConfigurationContextCustomizerFactory implements ContextCustom
}
OverrideAutoConfiguration overrideAutoConfiguration = TestContextAnnotationUtils.findMergedAnnotation(testClass,
OverrideAutoConfiguration.class);
boolean enabled = (overrideAutoConfiguration != null) ? overrideAutoConfiguration.enabled() : true;
boolean enabled = (overrideAutoConfiguration == null) || overrideAutoConfiguration.enabled();
return !enabled ? new DisableAutoConfigurationContextCustomizer() : null;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -39,10 +39,7 @@ class WebDriverContextCustomizer implements ContextCustomizer {
if (obj == this) {
return true;
}
if (obj == null || obj.getClass() != getClass()) {
return false;
}
return true;
return obj != null && obj.getClass() == getClass();
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -211,7 +211,7 @@ public @interface SpringBootTest {
* that class does not have a main method, a test-specific
* {@link SpringApplication} will be used.
*/
WHEN_AVAILABLE;
WHEN_AVAILABLE
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -119,9 +119,7 @@ public class ResetMocksTestExecutionListener extends AbstractTestExecutionListen
String factoryBeanName = BeanFactory.FACTORY_BEAN_PREFIX + name;
if (beanFactory.containsBean(factoryBeanName)) {
FactoryBean<?> factoryBean = (FactoryBean<?>) beanFactory.getBean(factoryBeanName);
if (!factoryBean.isSingleton()) {
return false;
}
return factoryBean.isSingleton();
}
return true;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -75,7 +75,7 @@ class BsdDomainSocket extends DomainSocket {
@Override
protected List<String> getFieldOrder() {
return Arrays.asList(new String[] { "sunLen", "sunFamily", "sunPath" });
return Arrays.asList("sunLen", "sunFamily", "sunPath");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -72,7 +72,7 @@ class LinuxDomainSocket extends DomainSocket {
@Override
protected List<String> getFieldOrder() {
return Arrays.asList(new String[] { "sunFamily", "sunPath" });
return Arrays.asList("sunFamily", "sunPath");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -81,10 +81,7 @@ public class HelpCommand extends AbstractCommand {
}
private boolean isHelpShown(Command command) {
if (command instanceof HelpCommand || command instanceof HintCommand) {
return false;
}
return true;
return !(command instanceof HelpCommand) && !(command instanceof HintCommand);
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -157,10 +157,7 @@ public final class Metadata {
if (this.deprecation == null && itemMetadata.getDeprecation() != null) {
return false;
}
if (this.deprecation != null && !this.deprecation.equals(itemMetadata.getDeprecation())) {
return false;
}
return true;
return this.deprecation == null || this.deprecation.equals(itemMetadata.getDeprecation());
}
public MetadataItemCondition ofType(Class<?> dataType) {
@@ -348,10 +345,7 @@ public final class Metadata {
if (this.value != null && !this.value.equals(valueHint.getValue())) {
return false;
}
if (this.description != null && !this.description.equals(valueHint.getDescription())) {
return false;
}
return true;
return this.description == null || this.description.equals(valueHint.getDescription());
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -130,7 +130,7 @@ final class ApplicationPluginAction implements PluginApplicationAction {
if (GradleVersion.current().compareTo(GradleVersion.version("8.3")) >= 0) {
try {
Method filePermissions = copySpec.getClass().getMethod("filePermissions", Action.class);
filePermissions.invoke(copySpec, new Action<Object>() {
filePermissions.invoke(copySpec, new Action<>() {
@Override
public void execute(Object filePermissions) {

View File

@@ -22,7 +22,6 @@ import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.attribute.BasicFileAttributeView;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.FileTime;
@@ -103,7 +102,7 @@ class ExtractCommandTests {
private void timeAttributes(File file) {
try {
BasicFileAttributes basicAttributes = Files
.getFileAttributeView(file.toPath(), BasicFileAttributeView.class, new LinkOption[0])
.getFileAttributeView(file.toPath(), BasicFileAttributeView.class)
.readAttributes();
assertThat(basicAttributes.lastModifiedTime().to(TimeUnit.SECONDS))
.isEqualTo(LAST_MODIFIED_TIME.to(TimeUnit.SECONDS));

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -651,7 +651,7 @@ abstract class AbstractPackagerTests<P extends Packager> {
expected.add("\\Q" + libraryTwo.getName() + "\\E");
expected.add("^/META-INF/native-image/.*");
assertThat(getPackagedEntryContent("META-INF/native-image/argfile"))
.isEqualTo(expected.stream().collect(Collectors.joining("\n")) + "\n");
.isEqualTo(String.join("\n", expected) + "\n");
}
private File createLibraryJar() throws IOException {

View File

@@ -207,7 +207,7 @@ final class JarUrlConnection extends java.net.JarURLConnection {
@Override
public boolean getAllowUserInteraction() {
return (this.jarFileConnection != null) ? this.jarFileConnection.getAllowUserInteraction() : false;
return (this.jarFileConnection != null) && this.jarFileConnection.getAllowUserInteraction();
}
@Override
@@ -219,7 +219,7 @@ final class JarUrlConnection extends java.net.JarURLConnection {
@Override
public boolean getUseCaches() {
return (this.jarFileConnection != null) ? this.jarFileConnection.getUseCaches() : true;
return (this.jarFileConnection == null) || this.jarFileConnection.getUseCaches();
}
@Override
@@ -231,7 +231,7 @@ final class JarUrlConnection extends java.net.JarURLConnection {
@Override
public boolean getDefaultUseCaches() {
return (this.jarFileConnection != null) ? this.jarFileConnection.getDefaultUseCaches() : true;
return (this.jarFileConnection == null) || this.jarFileConnection.getDefaultUseCaches();
}
@Override

View File

@@ -413,7 +413,7 @@ class NestedJarFileTests {
}
private List<String> collectComments(JarFile jarFile) throws IOException {
try {
try (jarFile) {
List<String> comments = new ArrayList<>();
Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) {
@@ -424,9 +424,6 @@ class NestedJarFileTests {
}
return comments;
}
finally {
jarFile.close();
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -168,9 +168,7 @@ class ZipStringTests {
@Test
void zipStringWhenMultiCodePointAtBufferBoundary() throws Exception {
StringBuilder source = new StringBuilder();
for (int i = 0; i < ZipString.BUFFER_SIZE - 1; i++) {
source.append("A");
}
source.append("A".repeat(ZipString.BUFFER_SIZE - 1));
source.append("\u1EFF");
String charSequence = source.toString();
source.append("suffix");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -127,8 +127,7 @@ class PropertiesMigrationReporter {
new PropertyMigration(match, metadata, determineReplacementMetadata(metadata), false));
}
// Prefix match for maps
if (isMapType(metadata) && propertySource instanceof IterableConfigurationPropertySource) {
IterableConfigurationPropertySource iterableSource = (IterableConfigurationPropertySource) propertySource;
if (isMapType(metadata) && propertySource instanceof IterableConfigurationPropertySource iterableSource) {
iterableSource.stream()
.filter(metadataName::isAncestorOf)
.map(propertySource::getConfigurationProperty)

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -85,11 +85,8 @@ class PropertyMigration {
if (replacementType.equals(currentType)) {
return true;
}
if (replacementType.equals(Duration.class.getName())
&& (currentType.equals(Long.class.getName()) || currentType.equals(Integer.class.getName()))) {
return true;
}
return false;
return replacementType.equals(Duration.class.getName())
&& (currentType.equals(Long.class.getName()) || currentType.equals(Integer.class.getName()));
}
private static String determineType(ConfigurationMetadataProperty metadata) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,7 +37,7 @@ class DisabledOnOsCondition implements ExecutionCondition {
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
if (!context.getElement().isPresent()) {
if (context.getElement().isEmpty()) {
return ConditionEvaluationResult.enabled("No element for @DisabledOnOs found");
}
MergedAnnotation<DisabledOnOs> annotation = MergedAnnotations
@@ -53,7 +53,7 @@ class DisabledOnOsCondition implements ExecutionCondition {
String architecture = System.getProperty("os.arch");
String os = System.getProperty("os.name");
boolean onDisabledOs = Arrays.stream(annotation.os()).anyMatch(OS::isCurrentOs);
boolean onDisabledArchitecture = Arrays.stream(annotation.architecture()).anyMatch(architecture::equals);
boolean onDisabledArchitecture = Arrays.asList(annotation.architecture()).contains(architecture);
if (onDisabledOs && onDisabledArchitecture) {
String reason = annotation.disabledReason().isEmpty()
? String.format("Disabled on OS = %s, architecture = %s", os, architecture)

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -281,7 +281,7 @@ public final class ConfigData {
* profile specific sibling imports.
* @since 2.4.5
*/
PROFILE_SPECIFIC;
PROFILE_SPECIFIC
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -470,7 +470,7 @@ class ConfigDataEnvironmentContributor implements Iterable<ConfigDataEnvironment
/**
* A valid location that contained nothing to load.
*/
EMPTY_LOCATION;
EMPTY_LOCATION
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -326,7 +326,7 @@ class ConfigDataEnvironmentContributors implements Iterable<ConfigDataEnvironmen
/**
* Throw an exception if an inactive contributor contains a bound value.
*/
FAIL_ON_BIND_TO_INACTIVE_SOURCE;
FAIL_ON_BIND_TO_INACTIVE_SOURCE
}

View File

@@ -90,12 +90,9 @@ final class ConfigurationPropertiesCharSequenceToObjectConverter implements Cond
return true;
}
}
if ((targetType.isArray() || targetType.isCollection()) && !targetType.equals(BYTE_ARRAY)) {
// StringToArrayConverter / StringToCollectionConverter are better than
// ObjectToArrayConverter / ObjectToCollectionConverter
return true;
}
return false;
// StringToArrayConverter / StringToCollectionConverter are better than
// ObjectToArrayConverter / ObjectToCollectionConverter
return (targetType.isArray() || targetType.isCollection()) && !targetType.equals(BYTE_ARRAY);
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,8 +16,6 @@
package org.springframework.boot.context.properties;
import java.util.stream.Collectors;
import org.springframework.boot.diagnostics.AbstractFailureAnalyzer;
import org.springframework.boot.diagnostics.FailureAnalysis;
@@ -32,7 +30,7 @@ class IncompatibleConfigurationFailureAnalyzer extends AbstractFailureAnalyzer<I
@Override
protected FailureAnalysis analyze(Throwable rootFailure, IncompatibleConfigurationException cause) {
String action = String.format("Review the docs for %s and change the configured values.",
cause.getIncompatibleKeys().stream().collect(Collectors.joining(", ")));
String.join(", ", cause.getIncompatibleKeys()));
return new FailureAnalysis(cause.getMessage(), action, cause);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -61,8 +61,8 @@ class NotConstructorBoundInjectionFailureAnalyzer
}
private boolean isConstructorBindingConfigurationProperties(InjectionPoint injectionPoint) {
return (injectionPoint != null && injectionPoint.getMember() instanceof Constructor<?> constructor)
? isConstructorBindingConfigurationProperties(constructor) : false;
return injectionPoint != null && injectionPoint.getMember() instanceof Constructor<?> constructor
&& isConstructorBindingConfigurationProperties(constructor);
}
private boolean isConstructorBindingConfigurationProperties(Constructor<?> constructor) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,6 +32,6 @@ public enum BindMethod {
/**
* Value object using constructor binding.
*/
VALUE_OBJECT;
VALUE_OBJECT
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -127,7 +127,7 @@ class DefaultBindConstructorProvider implements BindConstructorProvider {
return true;
}
Class<?> userClass = ClassUtils.getUserClass(type);
return (userClass != type) ? isAutowiredPresent(userClass) : false;
return (userClass != type) && isAutowiredPresent(userClass);
}
private static Constructor<?>[] getCandidateConstructors(Class<?> type) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -53,7 +53,7 @@ final class SpringProfileArbiter implements Arbiter {
@Override
public boolean isCondition() {
return (this.environment != null) ? this.environment.acceptsProfiles(this.profiles) : false;
return (this.environment != null) && this.environment.acceptsProfiles(this.profiles);
}
@PluginBuilderFactory

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -124,7 +124,7 @@ class NestedJarResourceSet extends AbstractSingleArchiveResourceSet {
// JarFile.isMultiRelease() is final so we must go to the manifest
Manifest manifest = getManifest();
Attributes attributes = (manifest != null) ? manifest.getMainAttributes() : null;
this.multiRelease = (attributes != null) ? attributes.containsKey(MULTI_RELEASE) : false;
this.multiRelease = (attributes != null) && attributes.containsKey(MULTI_RELEASE);
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -39,6 +39,6 @@ public enum GracefulShutdownResult {
/**
* The server was shutdown immediately, ignoring any active requests.
*/
IMMEDIATE;
IMMEDIATE
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,6 +33,6 @@ public enum Shutdown {
/**
* The {@link WebServer} should shut down immediately.
*/
IMMEDIATE;
IMMEDIATE
}

View File

@@ -332,10 +332,7 @@ public class ServletContextInitializerBeans extends AbstractCollection<ServletCo
&& this.seen.getOrDefault(type, Collections.emptySet()).contains(object)) {
return true;
}
if (this.seen.getOrDefault(ServletContextInitializer.class, Collections.emptySet()).contains(object)) {
return true;
}
return false;
return this.seen.getOrDefault(ServletContextInitializer.class, Collections.emptySet()).contains(object);
}
static Seen empty() {

View File

@@ -108,7 +108,7 @@ class ConfigurationPropertiesCharSequenceToObjectConverterTests {
@Override
public Long convert(CharSequence source) {
return Long.valueOf(source.toString()) + 1;
return Long.parseLong(source.toString()) + 1;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -104,7 +104,7 @@ class CharSequenceToObjectConverterTests {
@Override
public Long convert(CharSequence source) {
return Long.valueOf(source.toString()) + 1;
return Long.parseLong(source.toString()) + 1;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -50,7 +50,7 @@ class DynamicRegistrationBeanTests {
}
private static DynamicRegistrationBean<?> createBean() {
return new DynamicRegistrationBean<Dynamic>() {
return new DynamicRegistrationBean<>() {
@Override
protected Dynamic addRegistration(String description, ServletContext servletContext) {
return null;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -95,7 +95,7 @@ class StaticResourceJarsTests {
void doesNotCloseJarFromCachedConnection() throws Exception {
File jarFile = createResourcesJar("test-resources.jar");
TrackedURLStreamHandler handler = new TrackedURLStreamHandler(true);
URL url = new URL("jar", null, 0, jarFile.toURI().toURL().toString() + "!/", handler);
URL url = new URL("jar", null, 0, jarFile.toURI().toURL() + "!/", handler);
try {
new StaticResourceJars().getUrlsFrom(url);
assertThatNoException()
@@ -110,7 +110,7 @@ class StaticResourceJarsTests {
void closesJarFromNonCachedConnection() throws Exception {
File jarFile = createResourcesJar("test-resources.jar");
TrackedURLStreamHandler handler = new TrackedURLStreamHandler(false);
URL url = new URL("jar", null, 0, jarFile.toURI().toURL().toString() + "!/", handler);
URL url = new URL("jar", null, 0, jarFile.toURI().toURL() + "!/", handler);
new StaticResourceJars().getUrlsFrom(url);
assertThatIllegalStateException()
.isThrownBy(() -> ((JarURLConnection) handler.getConnection()).getJarFile().getComment())

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -155,10 +155,7 @@ class EmbeddedServerContainerInvocationContextProvider
if (parameterContext.getParameter().getType().equals(AbstractApplicationLauncher.class)) {
return true;
}
if (parameterContext.getParameter().getType().equals(RestTemplate.class)) {
return true;
}
return false;
return parameterContext.getParameter().getType().equals(RestTemplate.class);
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -69,9 +69,7 @@ class SampleLiquibaseApplicationTests {
};
if (nested.contains(ConnectException.class)) {
Throwable root = nested.getRootCause();
if (root.getMessage().contains("Connection refused")) {
return true;
}
return root.getMessage().contains("Connection refused");
}
return false;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -55,10 +55,7 @@ public class Location {
if (this.x != location.x) {
return false;
}
if (this.y != location.y) {
return false;
}
return true;
return this.y == location.y;
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -136,12 +136,12 @@ public class Snake {
public String getLocationsJson() {
synchronized (this.monitor) {
StringBuilder sb = new StringBuilder();
sb.append(String.format("{x: %d, y: %d}", Integer.valueOf(this.head.x), Integer.valueOf(this.head.y)));
sb.append(String.format("{x: %d, y: %d}", this.head.x, this.head.y));
for (Location location : this.tail) {
sb.append(',');
sb.append(String.format("{x: %d, y: %d}", Integer.valueOf(location.x), Integer.valueOf(location.y)));
sb.append(String.format("{x: %d, y: %d}", location.x, location.y));
}
return String.format("{'id':%d,'body':[%s]}", Integer.valueOf(this.id), sb);
return String.format("{'id':%d,'body':[%s]}", this.id, sb);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -50,7 +50,7 @@ public final class SnakeTimer {
if (snakes.isEmpty()) {
startTimer();
}
snakes.put(Integer.valueOf(snake.getId()), snake);
snakes.put(snake.getId(), snake);
}
}
@@ -60,7 +60,7 @@ public final class SnakeTimer {
public static void removeSnake(Snake snake) {
synchronized (MONITOR) {
snakes.remove(Integer.valueOf(snake.getId()));
snakes.remove(snake.getId());
if (snakes.isEmpty()) {
stopTimer();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -69,7 +69,7 @@ public class SnakeWebSocketHandler extends TextWebSocketHandler {
StringBuilder sb = new StringBuilder();
for (Iterator<Snake> iterator = SnakeTimer.getSnakes().iterator(); iterator.hasNext();) {
Snake snake = iterator.next();
sb.append(String.format("{id: %d, color: '%s'}", Integer.valueOf(snake.getId()), snake.getHexColor()));
sb.append(String.format("{id: %d, color: '%s'}", snake.getId(), snake.getHexColor()));
if (iterator.hasNext()) {
sb.append(',');
}
@@ -80,24 +80,18 @@ public class SnakeWebSocketHandler extends TextWebSocketHandler {
@Override
protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
String payload = message.getPayload();
if ("west".equals(payload)) {
this.snake.setDirection(Direction.WEST);
}
else if ("north".equals(payload)) {
this.snake.setDirection(Direction.NORTH);
}
else if ("east".equals(payload)) {
this.snake.setDirection(Direction.EAST);
}
else if ("south".equals(payload)) {
this.snake.setDirection(Direction.SOUTH);
switch (payload) {
case "west" -> this.snake.setDirection(Direction.WEST);
case "north" -> this.snake.setDirection(Direction.NORTH);
case "east" -> this.snake.setDirection(Direction.EAST);
case "south" -> this.snake.setDirection(Direction.SOUTH);
}
}
@Override
public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception {
SnakeTimer.removeSnake(this.snake);
SnakeTimer.broadcast(String.format("{'type': 'leave', 'id': %d}", Integer.valueOf(this.id)));
SnakeTimer.broadcast(String.format("{'type': 'leave', 'id': %d}", this.id));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -55,10 +55,7 @@ public class Location {
if (this.x != location.x) {
return false;
}
if (this.y != location.y) {
return false;
}
return true;
return this.y == location.y;
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -136,12 +136,12 @@ public class Snake {
public String getLocationsJson() {
synchronized (this.monitor) {
StringBuilder sb = new StringBuilder();
sb.append(String.format("{x: %d, y: %d}", Integer.valueOf(this.head.x), Integer.valueOf(this.head.y)));
sb.append(String.format("{x: %d, y: %d}", this.head.x, this.head.y));
for (Location location : this.tail) {
sb.append(',');
sb.append(String.format("{x: %d, y: %d}", Integer.valueOf(location.x), Integer.valueOf(location.y)));
sb.append(String.format("{x: %d, y: %d}", location.x, location.y));
}
return String.format("{'id':%d,'body':[%s]}", Integer.valueOf(this.id), sb);
return String.format("{'id':%d,'body':[%s]}", this.id, sb);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -50,7 +50,7 @@ public final class SnakeTimer {
if (snakes.isEmpty()) {
startTimer();
}
snakes.put(Integer.valueOf(snake.getId()), snake);
snakes.put(snake.getId(), snake);
}
}
@@ -60,7 +60,7 @@ public final class SnakeTimer {
public static void removeSnake(Snake snake) {
synchronized (MONITOR) {
snakes.remove(Integer.valueOf(snake.getId()));
snakes.remove(snake.getId());
if (snakes.isEmpty()) {
stopTimer();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -69,7 +69,7 @@ public class SnakeWebSocketHandler extends TextWebSocketHandler {
StringBuilder sb = new StringBuilder();
for (Iterator<Snake> iterator = SnakeTimer.getSnakes().iterator(); iterator.hasNext();) {
Snake snake = iterator.next();
sb.append(String.format("{id: %d, color: '%s'}", Integer.valueOf(snake.getId()), snake.getHexColor()));
sb.append(String.format("{id: %d, color: '%s'}", snake.getId(), snake.getHexColor()));
if (iterator.hasNext()) {
sb.append(',');
}
@@ -80,24 +80,18 @@ public class SnakeWebSocketHandler extends TextWebSocketHandler {
@Override
protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
String payload = message.getPayload();
if ("west".equals(payload)) {
this.snake.setDirection(Direction.WEST);
}
else if ("north".equals(payload)) {
this.snake.setDirection(Direction.NORTH);
}
else if ("east".equals(payload)) {
this.snake.setDirection(Direction.EAST);
}
else if ("south".equals(payload)) {
this.snake.setDirection(Direction.SOUTH);
switch (payload) {
case "west" -> this.snake.setDirection(Direction.WEST);
case "north" -> this.snake.setDirection(Direction.NORTH);
case "east" -> this.snake.setDirection(Direction.EAST);
case "south" -> this.snake.setDirection(Direction.SOUTH);
}
}
@Override
public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception {
SnakeTimer.removeSnake(this.snake);
SnakeTimer.broadcast(String.format("{'type': 'leave', 'id': %d}", Integer.valueOf(this.id)));
SnakeTimer.broadcast(String.format("{'type': 'leave', 'id': %d}", this.id));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -55,10 +55,7 @@ public class Location {
if (this.x != location.x) {
return false;
}
if (this.y != location.y) {
return false;
}
return true;
return this.y == location.y;
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -136,12 +136,12 @@ public class Snake {
public String getLocationsJson() {
synchronized (this.monitor) {
StringBuilder sb = new StringBuilder();
sb.append(String.format("{x: %d, y: %d}", Integer.valueOf(this.head.x), Integer.valueOf(this.head.y)));
sb.append(String.format("{x: %d, y: %d}", this.head.x, this.head.y));
for (Location location : this.tail) {
sb.append(',');
sb.append(String.format("{x: %d, y: %d}", Integer.valueOf(location.x), Integer.valueOf(location.y)));
sb.append(String.format("{x: %d, y: %d}", location.x, location.y));
}
return String.format("{'id':%d,'body':[%s]}", Integer.valueOf(this.id), sb);
return String.format("{'id':%d,'body':[%s]}", this.id, sb);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -50,7 +50,7 @@ public final class SnakeTimer {
if (snakes.isEmpty()) {
startTimer();
}
snakes.put(Integer.valueOf(snake.getId()), snake);
snakes.put(snake.getId(), snake);
}
}
@@ -60,7 +60,7 @@ public final class SnakeTimer {
public static void removeSnake(Snake snake) {
synchronized (MONITOR) {
snakes.remove(Integer.valueOf(snake.getId()));
snakes.remove(snake.getId());
if (snakes.isEmpty()) {
stopTimer();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -69,7 +69,7 @@ public class SnakeWebSocketHandler extends TextWebSocketHandler {
StringBuilder sb = new StringBuilder();
for (Iterator<Snake> iterator = SnakeTimer.getSnakes().iterator(); iterator.hasNext();) {
Snake snake = iterator.next();
sb.append(String.format("{id: %d, color: '%s'}", Integer.valueOf(snake.getId()), snake.getHexColor()));
sb.append(String.format("{id: %d, color: '%s'}", snake.getId(), snake.getHexColor()));
if (iterator.hasNext()) {
sb.append(',');
}
@@ -80,24 +80,18 @@ public class SnakeWebSocketHandler extends TextWebSocketHandler {
@Override
protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
String payload = message.getPayload();
if ("west".equals(payload)) {
this.snake.setDirection(Direction.WEST);
}
else if ("north".equals(payload)) {
this.snake.setDirection(Direction.NORTH);
}
else if ("east".equals(payload)) {
this.snake.setDirection(Direction.EAST);
}
else if ("south".equals(payload)) {
this.snake.setDirection(Direction.SOUTH);
switch (payload) {
case "west" -> this.snake.setDirection(Direction.WEST);
case "north" -> this.snake.setDirection(Direction.NORTH);
case "east" -> this.snake.setDirection(Direction.EAST);
case "south" -> this.snake.setDirection(Direction.SOUTH);
}
}
@Override
public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception {
SnakeTimer.removeSnake(this.snake);
SnakeTimer.broadcast(String.format("{'type': 'leave', 'id': %d}", Integer.valueOf(this.id)));
SnakeTimer.broadcast(String.format("{'type': 'leave', 'id': %d}", this.id));
}
}