Skip to content

Commit 559d493

Browse files
authored
Merge pull request #3017 from omercelikceng/codecleanupp
Code Cleanup - StringBuilder, Redundant Iteration, Record
2 parents eea905f + e445a34 commit 559d493

File tree

6 files changed

+24
-36
lines changed

6 files changed

+24
-36
lines changed

binders/kafka-binder/spring-cloud-stream-binder-kafka-streams/src/main/java/org/springframework/cloud/stream/binder/kafka/streams/KafkaStreamsFunctionProcessor.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
* @author Soby Chacko
7070
* @author Byungjun You
7171
* @author Georg Friedrich
72+
* @author Omer Celik
7273
* @since 2.2.0
7374
*/
7475
public class KafkaStreamsFunctionProcessor extends AbstractKafkaStreamsBinderProcessor implements BeanFactoryAware {
@@ -475,7 +476,7 @@ private void handleKStreamArrayOutbound(ResolvableType resolvableType, String fu
475476
String next = iterator.next();
476477
kafkaStreamsBindableProxyFactory.addOutputBinding(next, KStream.class);
477478
RootBeanDefinition rootBeanDefinition1 = new RootBeanDefinition();
478-
rootBeanDefinition1.setInstanceSupplier(() -> kafkaStreamsBindableProxyFactory.getOutputHolders().get(next).getBoundTarget());
479+
rootBeanDefinition1.setInstanceSupplier(() -> kafkaStreamsBindableProxyFactory.getOutputHolders().get(next).boundTarget());
479480
registry.registerBeanDefinition(next, rootBeanDefinition1);
480481

481482
Object targetBean = this.applicationContext.getBean(next);

binders/kafka-binder/spring-cloud-stream-binder-kafka-streams/src/main/java/org/springframework/cloud/stream/binder/kafka/streams/function/KafkaStreamsBindableProxyFactory.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2023 the original author or authors.
2+
* Copyright 2019-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -65,6 +65,7 @@
6565
* the actual size in the returned array. That has to wait until the function is invoked and we get a result.
6666
*
6767
* @author Soby Chacko
68+
* @author Omer Celik
6869
* @since 3.0.0
6970
*/
7071
public class KafkaStreamsBindableProxyFactory extends AbstractBindableProxyFactory implements InitializingBean, BeanFactoryAware {
@@ -173,7 +174,7 @@ public void afterPropertiesSet() {
173174
.createOutput(outputBinding), true));
174175
String outputBinding1 = outputBinding;
175176
RootBeanDefinition rootBeanDefinition1 = new RootBeanDefinition();
176-
rootBeanDefinition1.setInstanceSupplier(() -> outputHolders.get(outputBinding1).getBoundTarget());
177+
rootBeanDefinition1.setInstanceSupplier(() -> outputHolders.get(outputBinding1).boundTarget());
177178
BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
178179
registry.registerBeanDefinition(outputBinding1, rootBeanDefinition1);
179180
}
@@ -248,7 +249,7 @@ private void bindInput(ResolvableType arg0, String inputName) {
248249
}
249250
BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
250251
RootBeanDefinition rootBeanDefinition = new RootBeanDefinition();
251-
rootBeanDefinition.setInstanceSupplier(() -> inputHolders.get(inputName).getBoundTarget());
252+
rootBeanDefinition.setInstanceSupplier(() -> inputHolders.get(inputName).boundTarget());
252253
registry.registerBeanDefinition(inputName, rootBeanDefinition);
253254
}
254255

core/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binding/AbstractBindableProxyFactory.java

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2022 the original author or authors.
2+
* Copyright 2019-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -35,6 +35,7 @@
3535
*
3636
* Original authors in {@link BindableProxyFactory}
3737
* @author Soby Chacko
38+
* @author Omer Celik
3839
* @since 3.0.0
3940
*/
4041
public class AbstractBindableProxyFactory implements Bindable {
@@ -94,9 +95,9 @@ public Collection<Binding<Object>> createAndBindInputs(
9495
.entrySet()) {
9596
String inputTargetName = boundTargetHolderEntry.getKey();
9697
BoundTargetHolder boundTargetHolder = boundTargetHolderEntry.getValue();
97-
if (boundTargetHolder.isBindable()) {
98+
if (boundTargetHolder.bindable()) {
9899
bindings.addAll(bindingService.bindConsumer(
99-
boundTargetHolder.getBoundTarget(), inputTargetName));
100+
boundTargetHolder.boundTarget(), inputTargetName));
100101
}
101102
}
102103
return bindings;
@@ -111,9 +112,9 @@ public Collection<Binding<Object>> createAndBindOutputs(
111112
.entrySet()) {
112113
BoundTargetHolder boundTargetHolder = boundTargetHolderEntry.getValue();
113114
String outputTargetName = boundTargetHolderEntry.getKey();
114-
if (boundTargetHolderEntry.getValue().isBindable()) {
115+
if (boundTargetHolderEntry.getValue().bindable()) {
115116
bindings.add(bindingService.bindProducer(
116-
boundTargetHolder.getBoundTarget(), outputTargetName));
117+
boundTargetHolder.boundTarget(), outputTargetName));
117118
}
118119
}
119120
return bindings;
@@ -123,7 +124,7 @@ public Collection<Binding<Object>> createAndBindOutputs(
123124
public void unbindInputs(BindingService bindingService) {
124125
for (Map.Entry<String, BoundTargetHolder> boundTargetHolderEntry : this.inputHolders
125126
.entrySet()) {
126-
if (boundTargetHolderEntry.getValue().isBindable()) {
127+
if (boundTargetHolderEntry.getValue().bindable()) {
127128
bindingService.unbindConsumers(boundTargetHolderEntry.getKey());
128129
}
129130
}
@@ -133,7 +134,7 @@ public void unbindInputs(BindingService bindingService) {
133134
public void unbindOutputs(BindingService bindingService) {
134135
for (Map.Entry<String, BoundTargetHolder> boundTargetHolderEntry : this.outputHolders
135136
.entrySet()) {
136-
if (boundTargetHolderEntry.getValue().isBindable()) {
137+
if (boundTargetHolderEntry.getValue().bindable()) {
137138
bindingService.unbindProducers(boundTargetHolderEntry.getKey());
138139
}
139140
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015-2019 the original author or authors.
2+
* Copyright 2015-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,25 +24,8 @@
2424
*
2525
* @author Original authors in {@link BindableProxyFactory}
2626
* @author Soby Chacko
27+
* @author Omer Celik
2728
* @since 3.0.0
2829
*/
29-
public final class BoundTargetHolder {
30-
31-
private Object boundTarget;
32-
33-
private boolean bindable;
34-
35-
public BoundTargetHolder(Object boundTarget, boolean bindable) {
36-
this.boundTarget = boundTarget;
37-
this.bindable = bindable;
38-
}
39-
40-
public Object getBoundTarget() {
41-
return this.boundTarget;
42-
}
43-
44-
public boolean isBindable() {
45-
return this.bindable;
46-
}
47-
30+
public record BoundTargetHolder(Object boundTarget, boolean bindable) {
4831
}

core/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/config/BindingProperties.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015-2018 the original author or authors.
2+
* Copyright 2015-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -148,16 +148,16 @@ public boolean onlyOneOfProducerOrConsumerSet() {
148148
@Override
149149
public String toString() {
150150
StringBuilder sb = new StringBuilder();
151-
sb.append("destination=" + this.destination);
151+
sb.append("destination=").append(this.destination);
152152
sb.append(COMMA);
153-
sb.append("group=" + this.group);
153+
sb.append("group=").append(this.group);
154154
sb.append(COMMA);
155155
if (this.contentType != null) {
156-
sb.append("contentType=" + this.contentType);
156+
sb.append("contentType=").append(this.contentType);
157157
sb.append(COMMA);
158158
}
159159
if (this.binder != null) {
160-
sb.append("binder=" + this.binder);
160+
sb.append("binder=").append(this.binder);
161161
sb.append(COMMA);
162162
}
163163
sb.deleteCharAt(sb.lastIndexOf(COMMA));

core/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/config/BindingServiceConfiguration.java

+2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
* @author Oleg Zhurakousky
7979
* @author Soby Chacko
8080
* @author Chris Bono
81+
* @author Omer Celik
8182
*/
8283
@AutoConfiguration
8384
@EnableConfigurationProperties({ BindingServiceProperties.class,
@@ -132,6 +133,7 @@ public static Map<String, BinderConfiguration> getBinderConfigurations(
132133
.entrySet()) {
133134
if (configurationEntry.getValue().isDefaultCandidate()) {
134135
defaultCandidatesExist = true;
136+
break;
135137
}
136138
}
137139
if (!defaultCandidatesExist) {

0 commit comments

Comments
 (0)