Skip to content

Commit 7aee981

Browse files
drumoniilcmarvin
authored andcommitted
Add constructors with var args/Lists
For classes that have a setter for a List<T> field, create Constructors that take List<T> and var args of T. Issue spring-projects#686
1 parent 108aac6 commit 7aee981

File tree

5 files changed

+147
-6
lines changed

5 files changed

+147
-6
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/listener/CompositeChunkListener.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2013 the original author or authors.
2+
* Copyright 2006-2022 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.
@@ -15,6 +15,7 @@
1515
*/
1616
package org.springframework.batch.core.listener;
1717

18+
import java.util.Arrays;
1819
import java.util.Iterator;
1920
import java.util.List;
2021

@@ -30,6 +31,31 @@ public class CompositeChunkListener implements ChunkListener {
3031

3132
private OrderedComposite<ChunkListener> listeners = new OrderedComposite<>();
3233

34+
/**
35+
* Default constrcutor
36+
*/
37+
public CompositeChunkListener() {
38+
39+
}
40+
41+
/**
42+
* Convenience constructor for setting the {@link ChunkListener}s.
43+
*
44+
* @param listeners list of {@link ChunkListener}.
45+
*/
46+
public CompositeChunkListener(List<? extends ChunkListener> listeners) {
47+
setListeners(listeners);
48+
}
49+
50+
/**
51+
* Convenience constructor for setting the {@link ChunkListener}s.
52+
*
53+
* @param listeners array of {@link ChunkListener}.
54+
*/
55+
public CompositeChunkListener(ChunkListener... listeners) {
56+
this(Arrays.asList(listeners));
57+
}
58+
3359
/**
3460
* Public setter for the listeners.
3561
*

spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/CompositeItemProcessor.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2019 the original author or authors.
2+
* Copyright 2006-2022 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.
@@ -21,6 +21,7 @@
2121
import org.springframework.lang.Nullable;
2222
import org.springframework.util.Assert;
2323

24+
import java.util.Arrays;
2425
import java.util.List;
2526

2627
/**
@@ -38,6 +39,33 @@ public class CompositeItemProcessor<I, O> implements ItemProcessor<I, O>, Initia
3839

3940
private List<? extends ItemProcessor<?, ?>> delegates;
4041

42+
/**
43+
* Default constrcutor
44+
*/
45+
public CompositeItemProcessor() {
46+
47+
}
48+
49+
/**
50+
* Convenience constructor for setting the delegates.
51+
*
52+
* @param delegates array of {@link ItemProcessor} delegates that will work on the
53+
* item.
54+
*/
55+
public CompositeItemProcessor(ItemProcessor<?, ?>... delegates) {
56+
this(Arrays.asList(delegates));
57+
}
58+
59+
/**
60+
* Convenience constructor for setting the delegates.
61+
*
62+
* @param delegates list of {@link ItemProcessor} delegates that will work on the
63+
* item.
64+
*/
65+
public CompositeItemProcessor(List<? extends ItemProcessor<?, ?>> delegates) {
66+
setDelegates(delegates);
67+
}
68+
4169
@Nullable
4270
@Override
4371
@SuppressWarnings("unchecked")

spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/CompositeItemStream.java

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2019 the original author or authors.
2+
* Copyright 2006-2022 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.
@@ -34,6 +34,15 @@ public class CompositeItemStream implements ItemStream {
3434

3535
private final List<ItemStream> streams = new ArrayList<>();
3636

37+
/**
38+
* Public setter for the {@link ItemStream}s.
39+
*
40+
* @param streams {@link List} of {@link ItemStream}.
41+
*/
42+
public void setStreams(List<ItemStream> streams) {
43+
this.streams.addAll(streams);
44+
}
45+
3746
/**
3847
* Public setter for the {@link ItemStream}s.
3948
*
@@ -58,12 +67,30 @@ public void register(ItemStream stream) {
5867
}
5968

6069
/**
61-
*
70+
* Default constrcutor
6271
*/
6372
public CompositeItemStream() {
6473
super();
6574
}
6675

76+
/**
77+
* Convenience constructor for setting the {@link ItemStream}s.
78+
*
79+
* @param streams {@link List} of {@link ItemStream}.
80+
*/
81+
public CompositeItemStream(List<ItemStream> streams) {
82+
setStreams(streams);
83+
}
84+
85+
/**
86+
* Convenience constructor for setting the {@link ItemStream}s.
87+
*
88+
* @param streams array of {@link ItemStream}.
89+
*/
90+
public CompositeItemStream(ItemStream... streams) {
91+
setStreams(streams);
92+
}
93+
6794
/**
6895
* Simple aggregate {@link ExecutionContext} provider for the contributions
6996
* registered under the given key.

spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/CompositeItemWriter.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2007 the original author or authors.
2+
* Copyright 2006-2022 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,6 +24,7 @@
2424
import org.springframework.beans.factory.InitializingBean;
2525
import org.springframework.util.Assert;
2626

27+
import java.util.Arrays;
2728
import java.util.List;
2829

2930
/**
@@ -41,6 +42,31 @@ public class CompositeItemWriter<T> implements ItemStreamWriter<T>, Initializing
4142

4243
private boolean ignoreItemStream = false;
4344

45+
/**
46+
* Default constrcutor
47+
*/
48+
public CompositeItemWriter() {
49+
50+
}
51+
52+
/**
53+
* Convenience constructor for setting the delegates.
54+
*
55+
* @param delegates the list of delegates to use.
56+
*/
57+
public CompositeItemWriter(List<ItemWriter<? super T>> delegates) {
58+
setDelegates(delegates);
59+
}
60+
61+
/**
62+
* Convenience constructor for setting the delegates.
63+
*
64+
* @param delegates the array of delegates to use.
65+
*/
66+
public CompositeItemWriter(ItemWriter<? super T>... delegates) {
67+
this(Arrays.asList(delegates));
68+
}
69+
4470
/**
4571
* Establishes the policy whether to call the open, close, or update methods for the
4672
* item writer delegates associated with the CompositeItemWriter.

spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/listener/CompositeRepeatListener.java

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2007 the original author or authors.
2+
* Copyright 2006-2022 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.
@@ -33,6 +33,40 @@ public class CompositeRepeatListener implements RepeatListener {
3333

3434
private List<RepeatListener> listeners = new ArrayList<>();
3535

36+
/**
37+
* Default constrcutor
38+
*/
39+
public CompositeRepeatListener() {
40+
41+
}
42+
43+
/**
44+
* Convenience constructor for setting the {@link RepeatListener}s.
45+
*
46+
* @param listeners {@link List} of RepeatListeners to be used by the CompositeRepeatListener.
47+
*/
48+
public CompositeRepeatListener(List<RepeatListener> listeners) {
49+
setListeners(listeners);
50+
}
51+
52+
/**
53+
* Convenience constructor for setting the {@link RepeatListener}s.
54+
*
55+
* @param listeners array of RepeatListeners to be used by the CompositeRepeatListener.
56+
*/
57+
public CompositeRepeatListener(RepeatListener... listeners) {
58+
setListeners(listeners);
59+
}
60+
61+
/**
62+
* Public setter for the listeners.
63+
*
64+
* @param listeners {@link List} of RepeatListeners to be used by the CompositeRepeatListener.
65+
*/
66+
public void setListeners(List<RepeatListener> listeners) {
67+
this.listeners = listeners;
68+
}
69+
3670
/**
3771
* Public setter for the listeners.
3872
*

0 commit comments

Comments
 (0)