Skip to content

Commit 55f7992

Browse files
committed
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.
1 parent 2306141 commit 55f7992

File tree

5 files changed

+133
-4
lines changed

5 files changed

+133
-4
lines changed

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

+24-1
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-2019 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,28 @@ public class CompositeChunkListener implements ChunkListener {
3031

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

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

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

+25
Original file line numberDiff line numberDiff line change
@@ -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,30 @@ public class CompositeItemProcessor<I, O> implements ItemProcessor<I, O>, Initia
3839

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

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

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

+28-1
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-2019 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,15 @@ public class CompositeItemStream implements ItemStream {
3333

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

36+
/**
37+
* Public setter for the {@link ItemStream}s.
38+
*
39+
* @param streams {@link List} of {@link ItemStream}.
40+
*/
41+
public void setStreams(List<ItemStream> streams) {
42+
this.streams = streams;
43+
}
44+
3645
/**
3746
* Public setter for the {@link ItemStream}s.
3847
*
@@ -63,6 +72,24 @@ public CompositeItemStream() {
6372
super();
6473
}
6574

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

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

+24-1
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-2019 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,28 @@ public class CompositeItemWriter<T> implements ItemStreamWriter<T>, Initializing
4142

4243
private boolean ignoreItemStream = false;
4344

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

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

+32-1
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-2019 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,37 @@ public class CompositeRepeatListener implements RepeatListener {
3333

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

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

0 commit comments

Comments
 (0)