Skip to content
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

Polish #2846

Merged
merged 2 commits into from
Sep 30, 2024
Merged

Polish #2846

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 @@ -82,7 +82,7 @@ public static final class DestinationConfigurer {
}

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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -56,6 +56,7 @@
*
* @author Gary Russell
* @author Christian Tzolov
* @author Ngoc Nhan
* @since 2.4
*
*/
Expand Down Expand Up @@ -251,7 +252,7 @@ public void afterPropertiesSet() {
public boolean isRunning() {
this.lock.lock();
try {
return this.consumers.size() > 0;
return !this.consumers.isEmpty();
}
finally {
this.lock.unlock();
Expand All @@ -262,7 +263,7 @@ public boolean isRunning() {
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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
* Default {@link StreamMessageConverter}.
*
* @author Gary Russell
* @author Ngoc Nhan
* @since 2.4
*
*/
Expand Down Expand Up @@ -105,7 +106,7 @@ public com.rabbitmq.stream.Message fromMessage(Message message) throws MessageCo
.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);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,12 +317,12 @@ public Object postProcessAfterInitialization(final Object bean, final String bea

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()])));
}
Expand Down Expand Up @@ -880,7 +880,7 @@ private Map<String, Object> resolveArguments(Argument[] arguments) {
}
}
}
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public MessageBatch addToBatch(String exch, String routKey, Message message) {
}
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;
Expand All @@ -104,7 +104,7 @@ public MessageBatch addToBatch(String exch, String routKey, Message message) {

@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) {
Expand All @@ -128,7 +128,7 @@ public Collection<MessageBatch> releaseBatches() {
}

private MessageBatch doReleaseBatch() {
if (this.messages.size() < 1) {
if (this.messages.isEmpty()) {
return null;
}
Message message = assembleMessage();
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -30,6 +30,7 @@
* @author Dave Syer
* @author Gary Russell
* @author Artem Bilan
* @author Ngoc Nhan
*
*/
public class HeadersExchangeParser extends AbstractExchangeParser {
Expand Down Expand Up @@ -63,7 +64,7 @@ protected BeanDefinitionBuilder parseBinding(String exchangeName, Element bindin
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
* @author Artem Bilan
* @author Johno Crawford
* @author Jeonggi Kim
* @author Ngoc Nhan
*
* @since 2.0
*
Expand Down Expand Up @@ -542,7 +543,7 @@ protected AbstractMessageListenerContainer createInstance() { // NOSONAR complex
.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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -42,6 +42,7 @@
/**
* @author Mark Fisher
* @author Gary Russell
* @author Ngoc Nhan
* @since 1.0
*/
class ListenerContainerParser implements BeanDefinitionParser {
Expand Down Expand Up @@ -188,22 +189,22 @@ private void parseListener(Element listenerEle, Element containerEle, ParserCont
}
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()));
}
containerDef.getPropertyValues().add("queues", values);
}
}

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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -33,6 +33,7 @@
* @author Gary Russell
* @author Felipe Gutierrez
* @author Artem Bilan
* @author Ngoc Nhan
*
*/
public class QueueParser extends AbstractSingleBeanDefinitionParser {
Expand Down Expand Up @@ -134,7 +135,7 @@ private void parseArguments(Element element, ParserContext parserContext, BeanDe
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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -358,28 +358,22 @@ public static BeanDefinition parseContainer(Element containerEle, ParserContext
}

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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
* @author Dave Syer
* @author Gary Russell
* @author Artem Bilan
* @author Ngoc Nhan
*/
class TemplateParser extends AbstractSingleBeanDefinitionParser {

Expand Down Expand Up @@ -160,7 +161,7 @@ protected void doParse(Element element, ParserContext parserContext, BeanDefinit
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -904,12 +904,12 @@ public int getPendingConfirmsCount() {
@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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public static Object pop(Object key) {
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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -49,6 +49,7 @@
* @author Gary Russell
* @author Leonardo Ferreira
* @author Christian Tzolov
* @author Ngoc Nhan
* @since 2.3
*
*/
Expand Down Expand Up @@ -191,7 +192,7 @@ public void destroy() {
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()
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -99,7 +99,7 @@ public void send(String exchange, String routingKey, Message message,
}
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());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,7 @@ public void setupListenerContainer(MessageListenerContainer listenerContainer) {
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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -118,6 +118,7 @@
* @author Gary Russell
* @author Greg Turnquist
* @author Cai Kun
* @author Ngoc Nhan
*
* @see #setDelegate
* @see #setDefaultListenerMethod
Expand All @@ -129,7 +130,7 @@
*/
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".
Expand Down Expand Up @@ -314,7 +315,7 @@ else if (delegateListener instanceof MessageListener messageListener) {
* @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) {
Expand Down
Loading