Modernize code for diamond, isEmpty & pattern matching

This commit is contained in:
Tran Ngoc Nhan
2024-09-24 01:42:38 +07:00
committed by GitHub
parent 40faaa0c15
commit fc377126de
107 changed files with 550 additions and 454 deletions

View File

@@ -61,6 +61,7 @@ import org.springframework.util.Assert;
* @author Gary Russell
* @author Artem Bilan
* @author Christian Tzolov
* @author Ngoc Nhan
*
* @since 2.0
*
@@ -153,9 +154,8 @@ public abstract class AbstractConnectionFactory extends IntegrationObjectSupport
@Override
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
this.applicationEventPublisher = applicationEventPublisher;
if (!this.deserializerSet && this.deserializer instanceof ApplicationEventPublisherAware) {
((ApplicationEventPublisherAware) this.deserializer)
.setApplicationEventPublisher(applicationEventPublisher);
if (!this.deserializerSet && this.deserializer instanceof ApplicationEventPublisherAware applicationEventPublisherAware) {
applicationEventPublisherAware.setApplicationEventPublisher(applicationEventPublisher);
}
}
@@ -335,7 +335,7 @@ public abstract class AbstractConnectionFactory extends IntegrationObjectSupport
*/
@Nullable
public TcpSender getSender() {
return this.senders.size() > 0 ? this.senders.get(0) : null;
return !this.senders.isEmpty() ? this.senders.get(0) : null;
}
/**
@@ -827,7 +827,7 @@ public abstract class AbstractConnectionFactory extends IntegrationObjectSupport
private void rescheduleDelayedReads(Selector selector, long now) {
boolean wakeSelector = false;
try {
while (this.delayedReads.size() > 0) {
while (!this.delayedReads.isEmpty()) {
if (this.delayedReads.peek().failedAt + this.readDelay < now) {
PendingIO pendingRead = this.delayedReads.take();
if (pendingRead.key.channel().isOpen()) {

View File

@@ -37,6 +37,7 @@ import org.springframework.messaging.support.ErrorMessage;
* @author Gary Russell
* @author Kazuki Shimizu
* @author Christian Tzolov
* @author Ngoc Nhan
*
* @since 2.0
*/
@@ -110,7 +111,7 @@ public abstract class TcpConnectionInterceptorSupport extends TcpConnectionSuppo
@Override
public void registerSenders(List<TcpSender> sendersToRegister) {
this.interceptedSenders = sendersToRegister;
if (sendersToRegister.size() > 0) {
if (!sendersToRegister.isEmpty()) {
if (!(sendersToRegister.get(0) instanceof TcpConnectionInterceptorSupport)) {
this.realSender = true;
}
@@ -249,8 +250,8 @@ public abstract class TcpConnectionInterceptorSupport extends TcpConnectionSuppo
return;
}
this.removed = true;
if (this.theConnection instanceof TcpConnectionInterceptorSupport && !this.theConnection.equals(this)) {
((TcpConnectionInterceptorSupport) this.theConnection).removeDeadConnection(this);
if (this.theConnection instanceof TcpConnectionInterceptorSupport tcpConnectionInterceptorSupport && !this.theConnection.equals(this)) {
tcpConnectionInterceptorSupport.removeDeadConnection(this);
}
TcpSender sender = getSender();
if (sender != null && !(sender instanceof TcpConnectionInterceptorSupport)) {
@@ -270,7 +271,7 @@ public abstract class TcpConnectionInterceptorSupport extends TcpConnectionSuppo
@Override
@Nullable
public TcpSender getSender() {
return this.interceptedSenders != null && this.interceptedSenders.size() > 0
return this.interceptedSenders != null && !this.interceptedSenders.isEmpty()
? this.interceptedSenders.get(0)
: null;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2001-2022 the original author or authors.
* Copyright 2001-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.
@@ -48,6 +48,7 @@ import org.springframework.util.Assert;
*
* @author Gary Russell
* @author Artem Bilan
* @author Ngoc Nhan
*
* @since 2.0
*
@@ -370,7 +371,7 @@ public abstract class TcpConnectionSupport implements TcpConnection {
*/
@Nullable
public TcpSender getSender() {
return this.senders.size() > 0 ? this.senders.get(0) : null;
return !this.senders.isEmpty() ? this.senders.get(0) : null;
}
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-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.
@@ -56,6 +56,7 @@ import org.springframework.util.MimeType;
* *
* @author Gary Russell
* @author Artem Bilan
* @author Ngoc Nhan
*
* @since 2.0
*
@@ -260,12 +261,12 @@ public class TcpMessageMapper implements
private byte[] getPayloadAsBytes(Message<?> message) {
byte[] bytes = null;
Object payload = message.getPayload();
if (payload instanceof byte[]) {
bytes = (byte[]) payload;
if (payload instanceof byte[] castBytes) {
bytes = castBytes;
}
else if (payload instanceof String) {
else if (payload instanceof String string) {
try {
bytes = ((String) payload).getBytes(this.charset);
bytes = string.getBytes(this.charset);
}
catch (UnsupportedEncodingException e) {
throw new UncheckedIOException(e);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2001-2023 the original author or authors.
* Copyright 2001-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.
@@ -46,6 +46,7 @@ import org.springframework.util.Assert;
* @author Gary Russell
* @author Artem Bilan
* @author Christian Tzolov
* @author Ngoc Nhan
*
* @since 2.0
*
@@ -172,8 +173,8 @@ public class TcpNetConnection extends TcpConnectionSupport implements Scheduling
@Override
@Nullable
public SSLSession getSslSession() {
if (this.socket instanceof SSLSocket) {
return ((SSLSocket) this.socket).getSession();
if (this.socket instanceof SSLSocket sslSocket) {
return sslSocket.getSession();
}
else {
return null;

View File

@@ -39,6 +39,7 @@ import org.springframework.util.Assert;
* @author Gary Russell
* @author Artem Bilan
* @author Christian Tzolov
* @author Ngoc Nhan
*
* @since 2.0
*
@@ -210,7 +211,7 @@ public class TcpNioClientConnectionFactory extends
int selectionCount = 0;
try {
long timeout = Math.max(soTimeout, 0);
if (getDelayedReads().size() > 0 && (timeout == 0 || getReadDelay() < timeout)) {
if (!getDelayedReads().isEmpty() && (timeout == 0 || getReadDelay() < timeout)) {
timeout = getReadDelay();
}
selectionCount = this.selector.select(timeout);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-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.
@@ -41,6 +41,7 @@ import org.springframework.util.Assert;
*
* @author Gary Russell
* @author Artem Bilan
* @author Ngoc Nhan
*
* @since 2.0
*
@@ -185,7 +186,7 @@ public class TcpNioServerConnectionFactory extends AbstractServerConnectionFacto
int selectionCount;
try {
long timeout = Math.max(soTimeout, 0);
if (getDelayedReads().size() > 0 && (timeout == 0 || getReadDelay() < timeout)) {
if (!getDelayedReads().isEmpty() && (timeout == 0 || getReadDelay() < timeout)) {
timeout = getReadDelay();
}
long timeoutToLog = timeout;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2019 the original author or authors.
* Copyright 2016-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.
@@ -28,6 +28,7 @@ import org.springframework.util.Assert;
* Optionally pools buffers.
*
* @author Gary Russell
* @author Ngoc Nhan
* @since 4.3
*
*/
@@ -44,7 +45,7 @@ public abstract class AbstractPooledBufferByteArraySerializer extends AbstractBy
*/
public void setPoolSize(int size) {
Assert.isNull(this.pool, "Cannot change pool size once set");
this.pool = new SimplePool<byte[]>(size, new PoolItemCallback<byte[]>() {
this.pool = new SimplePool<>(size, new PoolItemCallback<>() {
@Override
public byte[] createForPool() {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2001-2023 the original author or authors.
* Copyright 2001-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,6 +61,7 @@ import org.springframework.util.StringUtils;
* @author Marcin Pilaczynski
* @author Artem Bilan
* @author Christian Tzolov
* @author Ngoc Nhan
*
* @since 2.0
*/
@@ -357,15 +358,14 @@ public class UnicastSendingMessageHandler extends
SocketAddress destinationAddress;
if (this.destinationExpression != null) {
Object destination = this.destinationExpression.getValue(this.evaluationContext, message);
if (destination instanceof String) {
destination = new URI((String) destination);
if (destination instanceof String string) {
destination = new URI(string);
}
if (destination instanceof URI) {
URI uri = (URI) destination;
if (destination instanceof URI uri) {
destination = new InetSocketAddress(uri.getHost(), uri.getPort());
}
if (destination instanceof SocketAddress) {
destinationAddress = (SocketAddress) destination;
if (destination instanceof SocketAddress socketAddress) {
destinationAddress = socketAddress;
}
else {
throw new IllegalStateException("'destinationExpression' must evaluate to String, URI " +