Modernize more code for diamond, isEmpty & pattern matching
This commit is contained in:
@@ -82,7 +82,7 @@ public final class BindingBuilder {
|
||||
}
|
||||
|
||||
public Binding to(FanoutExchange exchange) {
|
||||
return new Binding(this.queue, this.name, this.type, exchange.getName(), "", new HashMap<String, Object>());
|
||||
return new Binding(this.queue, this.name, this.type, exchange.getName(), "", new HashMap<>());
|
||||
}
|
||||
|
||||
public HeadersExchangeMapConfigurer to(HeadersExchange exchange) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2021-2023 the original author or authors.
|
||||
* Copyright 2021-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 io.micrometer.observation.ObservationRegistry;
|
||||
*
|
||||
* @author Gary Russell
|
||||
* @author Christian Tzolov
|
||||
* @author Ngoc Nhan
|
||||
* @since 2.4
|
||||
*
|
||||
*/
|
||||
@@ -251,7 +252,7 @@ public class StreamListenerContainer extends ObservableListenerContainer {
|
||||
public boolean isRunning() {
|
||||
this.lock.lock();
|
||||
try {
|
||||
return this.consumers.size() > 0;
|
||||
return !this.consumers.isEmpty();
|
||||
}
|
||||
finally {
|
||||
this.lock.unlock();
|
||||
@@ -262,7 +263,7 @@ public class StreamListenerContainer extends ObservableListenerContainer {
|
||||
public void start() {
|
||||
this.lock.lock();
|
||||
try {
|
||||
if (this.consumers.size() == 0) {
|
||||
if (this.consumers.isEmpty()) {
|
||||
this.consumerCustomizer.accept(getListenerId(), this.builder);
|
||||
if (this.simpleStream) {
|
||||
this.consumers.add(this.builder.build());
|
||||
|
||||
@@ -41,6 +41,7 @@ import com.rabbitmq.stream.codec.WrapperMessageBuilder;
|
||||
* Default {@link StreamMessageConverter}.
|
||||
*
|
||||
* @author Gary Russell
|
||||
* @author Ngoc Nhan
|
||||
* @since 2.4
|
||||
*
|
||||
*/
|
||||
@@ -105,7 +106,7 @@ public class DefaultStreamMessageConverter implements StreamMessageConverter {
|
||||
.acceptIfNotNull(mProps.getGroupSequence(), propsBuilder::groupSequence)
|
||||
.acceptIfNotNull(mProps.getReplyToGroupId(), propsBuilder::replyToGroupId);
|
||||
ApplicationPropertiesBuilder appPropsBuilder = builder.applicationProperties();
|
||||
if (mProps.getHeaders().size() > 0) {
|
||||
if (!mProps.getHeaders().isEmpty()) {
|
||||
mProps.getHeaders().forEach((key, val) -> {
|
||||
mapProp(key, val, appPropsBuilder);
|
||||
});
|
||||
|
||||
@@ -317,12 +317,12 @@ public class RabbitListenerAnnotationBeanPostProcessor
|
||||
|
||||
private TypeMetadata buildMetadata(Class<?> targetClass) {
|
||||
List<RabbitListener> classLevelListeners = findListenerAnnotations(targetClass);
|
||||
final boolean hasClassLevelListeners = classLevelListeners.size() > 0;
|
||||
final boolean hasClassLevelListeners = !classLevelListeners.isEmpty();
|
||||
final List<ListenerMethod> methods = new ArrayList<>();
|
||||
final List<Method> multiMethods = new ArrayList<>();
|
||||
ReflectionUtils.doWithMethods(targetClass, method -> {
|
||||
List<RabbitListener> listenerAnnotations = findListenerAnnotations(method);
|
||||
if (listenerAnnotations.size() > 0) {
|
||||
if (!listenerAnnotations.isEmpty()) {
|
||||
methods.add(new ListenerMethod(method,
|
||||
listenerAnnotations.toArray(new RabbitListener[listenerAnnotations.size()])));
|
||||
}
|
||||
@@ -880,7 +880,7 @@ public class RabbitListenerAnnotationBeanPostProcessor
|
||||
}
|
||||
}
|
||||
}
|
||||
return map.size() < 1 ? null : map;
|
||||
return map.isEmpty() ? null : map;
|
||||
}
|
||||
|
||||
private void addToMap(Map<String, Object> map, String key, Object value, Class<?> typeClass, String typeName) {
|
||||
|
||||
@@ -88,7 +88,7 @@ public class SimpleBatchingStrategy implements BatchingStrategy {
|
||||
}
|
||||
int bufferUse = Integer.BYTES + message.getBody().length;
|
||||
MessageBatch batch = null;
|
||||
if (this.messages.size() > 0 && this.currentSize + bufferUse > this.bufferLimit) {
|
||||
if (!this.messages.isEmpty() && this.currentSize + bufferUse > this.bufferLimit) {
|
||||
batch = doReleaseBatch();
|
||||
this.exchange = exch;
|
||||
this.routingKey = routKey;
|
||||
@@ -104,7 +104,7 @@ public class SimpleBatchingStrategy implements BatchingStrategy {
|
||||
|
||||
@Override
|
||||
public Date nextRelease() {
|
||||
if (this.messages.size() == 0 || this.timeout <= 0) {
|
||||
if (this.messages.isEmpty() || this.timeout <= 0) {
|
||||
return null;
|
||||
}
|
||||
else if (this.currentSize >= this.bufferLimit) {
|
||||
@@ -128,7 +128,7 @@ public class SimpleBatchingStrategy implements BatchingStrategy {
|
||||
}
|
||||
|
||||
private MessageBatch doReleaseBatch() {
|
||||
if (this.messages.size() < 1) {
|
||||
if (this.messages.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
Message message = assembleMessage();
|
||||
|
||||
@@ -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.
|
||||
@@ -30,6 +30,7 @@ import org.springframework.util.xml.DomUtils;
|
||||
* @author Dave Syer
|
||||
* @author Gary Russell
|
||||
* @author Artem Bilan
|
||||
* @author Ngoc Nhan
|
||||
*
|
||||
*/
|
||||
public class HeadersExchangeParser extends AbstractExchangeParser {
|
||||
@@ -63,7 +64,7 @@ public class HeadersExchangeParser extends AbstractExchangeParser {
|
||||
parserContext.getReaderContext()
|
||||
.error("At least one of 'binding-arguments' sub-element or 'key/value' attributes pair have to be declared.", binding);
|
||||
}
|
||||
ManagedMap<TypedStringValue, TypedStringValue> map = new ManagedMap<TypedStringValue, TypedStringValue>();
|
||||
ManagedMap<TypedStringValue, TypedStringValue> map = new ManagedMap<>();
|
||||
map.put(new TypedStringValue(key), new TypedStringValue(value));
|
||||
builder.addPropertyValue("arguments", map);
|
||||
}
|
||||
|
||||
@@ -56,6 +56,7 @@ import org.springframework.util.backoff.BackOff;
|
||||
* @author Artem Bilan
|
||||
* @author Johno Crawford
|
||||
* @author Jeonggi Kim
|
||||
* @author Ngoc Nhan
|
||||
*
|
||||
* @since 2.0
|
||||
*
|
||||
@@ -542,7 +543,7 @@ public class ListenerContainerFactoryBean extends AbstractFactoryBean<AbstractMe
|
||||
.acceptIfNotNull(this.exclusiveConsumerExceptionLogger,
|
||||
container::setExclusiveConsumerExceptionLogger)
|
||||
.acceptIfNotNull(this.micrometerEnabled, container::setMicrometerEnabled)
|
||||
.acceptIfCondition(this.micrometerTags.size() > 0, this.micrometerTags,
|
||||
.acceptIfCondition(!this.micrometerTags.isEmpty(), this.micrometerTags,
|
||||
container::setMicrometerTags);
|
||||
if (this.smlcCustomizer != null && this.type.equals(Type.simple)) {
|
||||
this.smlcCustomizer.configure((SimpleMessageListenerContainer) container);
|
||||
|
||||
@@ -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.
|
||||
@@ -42,6 +42,7 @@ import org.springframework.util.xml.DomUtils;
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Gary Russell
|
||||
* @author Ngoc Nhan
|
||||
* @since 1.0
|
||||
*/
|
||||
class ListenerContainerParser implements BeanDefinitionParser {
|
||||
@@ -188,7 +189,7 @@ class ListenerContainerParser implements BeanDefinitionParser {
|
||||
}
|
||||
else {
|
||||
String[] names = StringUtils.commaDelimitedListToStringArray(queues);
|
||||
List<RuntimeBeanReference> values = new ManagedList<RuntimeBeanReference>();
|
||||
List<RuntimeBeanReference> values = new ManagedList<>();
|
||||
for (int i = 0; i < names.length; i++) {
|
||||
values.add(new RuntimeBeanReference(names[i].trim()));
|
||||
}
|
||||
@@ -196,14 +197,14 @@ class ListenerContainerParser implements BeanDefinitionParser {
|
||||
}
|
||||
}
|
||||
|
||||
ManagedMap<String, TypedStringValue> args = new ManagedMap<String, TypedStringValue>();
|
||||
ManagedMap<String, TypedStringValue> args = new ManagedMap<>();
|
||||
|
||||
String priority = listenerEle.getAttribute("priority");
|
||||
if (StringUtils.hasText(priority)) {
|
||||
args.put("x-priority", new TypedStringValue(priority, Integer.class));
|
||||
}
|
||||
|
||||
if (args.size() > 0) {
|
||||
if (!args.isEmpty()) {
|
||||
containerDef.getPropertyValues().add("consumerArguments", args);
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
@@ -33,6 +33,7 @@ import org.springframework.util.xml.DomUtils;
|
||||
* @author Gary Russell
|
||||
* @author Felipe Gutierrez
|
||||
* @author Artem Bilan
|
||||
* @author Ngoc Nhan
|
||||
*
|
||||
*/
|
||||
public class QueueParser extends AbstractSingleBeanDefinitionParser {
|
||||
@@ -134,7 +135,7 @@ public class QueueParser extends AbstractSingleBeanDefinitionParser {
|
||||
Map<?, ?> map = parserContext.getDelegate().parseMapElement(argumentsElement,
|
||||
builder.getRawBeanDefinition());
|
||||
if (StringUtils.hasText(ref)) {
|
||||
if (map != null && map.size() > 0) {
|
||||
if (map != null && !map.isEmpty()) {
|
||||
parserContext.getReaderContext()
|
||||
.error("You cannot have both a 'ref' and a nested map", element);
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -358,28 +358,22 @@ public final class RabbitNamespaceUtils {
|
||||
}
|
||||
|
||||
private static AcknowledgeMode parseAcknowledgeMode(Element ele, ParserContext parserContext) {
|
||||
AcknowledgeMode acknowledgeMode = null;
|
||||
String acknowledge = ele.getAttribute(ACKNOWLEDGE_ATTRIBUTE);
|
||||
if (StringUtils.hasText(acknowledge)) {
|
||||
if (ACKNOWLEDGE_AUTO.equals(acknowledge)) {
|
||||
acknowledgeMode = AcknowledgeMode.AUTO;
|
||||
}
|
||||
else if (ACKNOWLEDGE_MANUAL.equals(acknowledge)) {
|
||||
acknowledgeMode = AcknowledgeMode.MANUAL;
|
||||
}
|
||||
else if (ACKNOWLEDGE_NONE.equals(acknowledge)) {
|
||||
acknowledgeMode = AcknowledgeMode.NONE;
|
||||
}
|
||||
else {
|
||||
parserContext.getReaderContext().error(
|
||||
return switch (acknowledge) {
|
||||
case ACKNOWLEDGE_AUTO -> AcknowledgeMode.AUTO;
|
||||
case ACKNOWLEDGE_MANUAL -> AcknowledgeMode.MANUAL;
|
||||
case ACKNOWLEDGE_NONE -> AcknowledgeMode.NONE;
|
||||
default -> {
|
||||
parserContext.getReaderContext().error(
|
||||
"Invalid listener container 'acknowledge' setting [" + acknowledge
|
||||
+ "]: only \"auto\", \"manual\", and \"none\" supported.", ele);
|
||||
}
|
||||
return acknowledgeMode;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
+ "]: only \"auto\", \"manual\", and \"none\" supported.", ele);
|
||||
yield null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ import org.springframework.util.xml.DomUtils;
|
||||
* @author Dave Syer
|
||||
* @author Gary Russell
|
||||
* @author Artem Bilan
|
||||
* @author Ngoc Nhan
|
||||
*/
|
||||
class TemplateParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
@@ -160,7 +161,7 @@ class TemplateParser extends AbstractSingleBeanDefinitionParser {
|
||||
BeanDefinition replyContainer = null;
|
||||
Element childElement = null;
|
||||
List<Element> childElements = DomUtils.getChildElementsByTagName(element, LISTENER_ELEMENT);
|
||||
if (childElements.size() > 0) {
|
||||
if (!childElements.isEmpty()) {
|
||||
childElement = childElements.get(0);
|
||||
}
|
||||
if (childElement != null) {
|
||||
|
||||
@@ -904,12 +904,12 @@ public class PublisherCallbackChannelImpl
|
||||
@Override
|
||||
public void addListener(Listener listener) {
|
||||
Assert.notNull(listener, "Listener cannot be null");
|
||||
if (this.listeners.size() == 0) {
|
||||
if (this.listeners.isEmpty()) {
|
||||
this.delegate.addConfirmListener(this);
|
||||
this.delegate.addReturnListener(this);
|
||||
}
|
||||
if (this.listeners.putIfAbsent(listener.getUUID(), listener) == null) {
|
||||
this.pendingConfirms.put(listener, new ConcurrentSkipListMap<Long, PendingConfirm>());
|
||||
this.pendingConfirms.put(listener, new ConcurrentSkipListMap<>());
|
||||
if (this.logger.isDebugEnabled()) {
|
||||
this.logger.debug("Added listener " + listener);
|
||||
}
|
||||
|
||||
@@ -176,7 +176,7 @@ public final class SimpleResourceHolder {
|
||||
Map<Object, Deque<Object>> stack = STACK.get();
|
||||
if (stack != null) {
|
||||
Deque<Object> deque = stack.get(key);
|
||||
if (deque != null && deque.size() > 0) {
|
||||
if (deque != null && !deque.isEmpty()) {
|
||||
Object previousValue = deque.pop();
|
||||
if (previousValue != null) {
|
||||
bind(key, previousValue);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2020-2023 the original author or authors.
|
||||
* Copyright 2020-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.
|
||||
@@ -49,6 +49,7 @@ import com.rabbitmq.client.ShutdownListener;
|
||||
* @author Gary Russell
|
||||
* @author Leonardo Ferreira
|
||||
* @author Christian Tzolov
|
||||
* @author Ngoc Nhan
|
||||
* @since 2.3
|
||||
*
|
||||
*/
|
||||
@@ -191,7 +192,7 @@ public class ThreadChannelConnectionFactory extends AbstractConnectionFactory
|
||||
this.connection.forceClose();
|
||||
this.connection = null;
|
||||
}
|
||||
if (this.switchesInProgress.size() > 0 && this.logger.isWarnEnabled()) {
|
||||
if (!this.switchesInProgress.isEmpty() && this.logger.isWarnEnabled()) {
|
||||
this.logger.warn("Unclaimed context switches from threads:" +
|
||||
this.switchesInProgress.values()
|
||||
.stream()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2023 the original author or authors.
|
||||
* Copyright 2014-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.
|
||||
@@ -99,7 +99,7 @@ public class BatchingRabbitTemplate extends RabbitTemplate {
|
||||
}
|
||||
Date next = this.batchingStrategy.nextRelease();
|
||||
if (next != null) {
|
||||
this.scheduledTask = this.scheduler.schedule((Runnable) () -> releaseBatches(), next.toInstant());
|
||||
this.scheduledTask = this.scheduler.schedule(this::releaseBatches, next.toInstant());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -397,8 +397,7 @@ public abstract class AbstractRabbitListenerEndpoint implements RabbitListenerEn
|
||||
throw new IllegalStateException("Queues or queue names must be provided but not both for " + this);
|
||||
}
|
||||
if (queuesEmpty) {
|
||||
Collection<String> names = qNames;
|
||||
container.setQueueNames(names.toArray(new String[0]));
|
||||
container.setQueueNames(qNames.toArray(new String[0]));
|
||||
}
|
||||
else {
|
||||
Collection<Queue> instances = getQueues();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -118,6 +118,7 @@ import com.rabbitmq.client.Channel;
|
||||
* @author Gary Russell
|
||||
* @author Greg Turnquist
|
||||
* @author Cai Kun
|
||||
* @author Ngoc Nhan
|
||||
*
|
||||
* @see #setDelegate
|
||||
* @see #setDefaultListenerMethod
|
||||
@@ -129,7 +130,7 @@ import com.rabbitmq.client.Channel;
|
||||
*/
|
||||
public class MessageListenerAdapter extends AbstractAdaptableMessageListener {
|
||||
|
||||
private final Map<String, String> queueOrTagToMethodName = new HashMap<String, String>();
|
||||
private final Map<String, String> queueOrTagToMethodName = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Out-of-the-box value for the default listener method: "handleMessage".
|
||||
@@ -314,7 +315,7 @@ public class MessageListenerAdapter extends AbstractAdaptableMessageListener {
|
||||
* @see #setQueueOrTagToMethodName
|
||||
*/
|
||||
protected String getListenerMethodName(Message originalMessage, Object extractedMessage) {
|
||||
if (this.queueOrTagToMethodName.size() > 0) {
|
||||
if (!this.queueOrTagToMethodName.isEmpty()) {
|
||||
MessageProperties props = originalMessage.getMessageProperties();
|
||||
String methodName = this.queueOrTagToMethodName.get(props.getConsumerQueue());
|
||||
if (methodName == null) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
* Copyright 2014-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.
|
||||
@@ -91,7 +91,7 @@ public class RepublishMessageRecoverer implements MessageRecoverer {
|
||||
* @param errorTemplate the template.
|
||||
*/
|
||||
public RepublishMessageRecoverer(AmqpTemplate errorTemplate) {
|
||||
this(errorTemplate, (String) null, (String) null);
|
||||
this(errorTemplate, null, (String) null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user