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

@@ -112,6 +112,7 @@ import org.springframework.util.StringUtils;
* @author Alen Turkovic
* @author Trung Pham
* @author Christian Tzolov
* @author Ngoc Nhan
*/
public class FileWritingMessageHandler extends AbstractReplyProducingMessageHandler
implements ManageableLifecycle, MessageTriggerAction {
@@ -475,9 +476,9 @@ public class FileWritingMessageHandler extends AbstractReplyProducingMessageHand
}
Flusher flusher = new Flusher();
flusher.run();
boolean needInterrupt = this.fileStates.size() > 0;
boolean needInterrupt = !this.fileStates.isEmpty();
int n = 0;
while (n++ < 10 && this.fileStates.size() > 0) { // NOSONAR
while (n++ < 10 && !this.fileStates.isEmpty()) { // NOSONAR
try {
Thread.sleep(1);
}
@@ -486,7 +487,7 @@ public class FileWritingMessageHandler extends AbstractReplyProducingMessageHand
}
flusher.run();
}
if (this.fileStates.size() > 0) {
if (!this.fileStates.isEmpty()) {
this.logger.error("Failed to flush after multiple attempts, while stopping: " + this.fileStates.keySet());
}
if (needInterrupt) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 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.
@@ -29,12 +29,13 @@ import java.util.List;
* @author Mark Fisher
* @author Iwein Fuld
* @author Gary Russell
* @author Ngoc Nhan
*/
public abstract class AbstractFileListFilter<F> implements FileListFilter<F> {
@Override
public final List<F> filterFiles(F[] files) {
List<F> accepted = new ArrayList<F>();
List<F> accepted = new ArrayList<>();
if (files != null) {
for (F file : files) {
if (this.accept(file)) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017-2021 the original author or authors.
* Copyright 2017-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,7 @@ import java.util.stream.Collectors;
* @param <F> the target protocol file type.
*
* @author Gary Russell
* @author Ngoc Nhan
*
* @since 5.0
*
@@ -125,7 +126,7 @@ public abstract class AbstractMarkerFilePresentFileListFilter<F> implements File
boolean anyMatch = this.filtersAndFunctions.entrySet().stream().anyMatch(entry -> {
F[] fileToCheck = (F[]) Array.newInstance(file.getClass(), 1);
fileToCheck[0] = file;
if (entry.getKey().filterFiles(fileToCheck).size() > 0) {
if (!entry.getKey().filterFiles(fileToCheck).isEmpty()) {
String markerName = entry.getValue().apply(getFilename(file));
return markerName != null && candidates.contains(markerName);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2021 the original author or authors.
* Copyright 2013-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.
@@ -35,6 +35,7 @@ import org.springframework.util.Assert;
*
* @author Gary Russell
* @author Artem Bilan
* @author Ngoc Nhan
*
* @since 3.0
*
@@ -56,8 +57,8 @@ public abstract class AbstractPersistentAcceptOnceFileListFilter<F> extends Abst
Assert.notNull(prefix, "'prefix' cannot be null");
this.store = store;
this.prefix = prefix;
if (store instanceof Flushable) {
this.flushableStore = (Flushable) store;
if (store instanceof Flushable flushable) {
this.flushableStore = flushable;
}
else {
this.flushableStore = null;
@@ -130,8 +131,8 @@ public abstract class AbstractPersistentAcceptOnceFileListFilter<F> extends Abst
@Override
public void close() throws IOException {
if (this.store instanceof Closeable) {
((Closeable) this.store).close();
if (this.store instanceof Closeable closeable) {
closeable.close();
}
}

View File

@@ -40,6 +40,7 @@ import org.springframework.lang.Nullable;
* @author Gary Russell
* @author Artem Bilan
* @author Christian Tzolov
* @author Ngoc Nhan
*/
public class AcceptOnceFileListFilter<F> extends AbstractFileListFilter<F> implements ReversibleFileListFilter<F>,
ResettableFileListFilter<F> {
@@ -47,7 +48,7 @@ public class AcceptOnceFileListFilter<F> extends AbstractFileListFilter<F> imple
@Nullable
private final Queue<F> seen;
private final Set<F> seenSet = new HashSet<F>();
private final Set<F> seenSet = new HashSet<>();
private final Lock monitor = new ReentrantLock();
@@ -58,7 +59,7 @@ public class AcceptOnceFileListFilter<F> extends AbstractFileListFilter<F> imple
* @param maxCapacity the maximum number of Files to maintain in the 'seen' queue.
*/
public AcceptOnceFileListFilter(int maxCapacity) {
this.seen = new LinkedBlockingQueue<F>(maxCapacity);
this.seen = new LinkedBlockingQueue<>(maxCapacity);
}
/**

View File

@@ -74,6 +74,7 @@ import org.springframework.util.StringUtils;
* @author Oleg Zhurakousky
* @author Gary Russell
* @author Artem Bilan
* @author Ngoc Nhan
*
* @since 2.0
*/
@@ -137,7 +138,7 @@ public abstract class AbstractInboundFileSynchronizer<F>
*/
public AbstractInboundFileSynchronizer(SessionFactory<F> sessionFactory) {
Assert.notNull(sessionFactory, "sessionFactory must not be null");
this.remoteFileTemplate = new RemoteFileTemplate<F>(sessionFactory);
this.remoteFileTemplate = new RemoteFileTemplate<>(sessionFactory);
}
@Nullable
@@ -312,8 +313,8 @@ public abstract class AbstractInboundFileSynchronizer<F>
@Override
public void close() throws IOException {
if (this.filter instanceof Closeable) {
((Closeable) this.filter).close();
if (this.filter instanceof Closeable closeable) {
closeable.close();
}
}