From 15e18e5fcd4d7be70c4a4bcfe149202e587b8fe3 Mon Sep 17 00:00:00 2001 From: Drummond Dawson Date: Thu, 21 Feb 2019 21:02:01 -0500 Subject: [PATCH] Add constructors with var args/Lists For classes that have a setter for a List field, create Constructors that take List and var args of T. Issue #686 --- .../core/listener/CompositeChunkListener.java | 28 ++++++++++++++- .../item/support/CompositeItemProcessor.java | 30 +++++++++++++++- .../item/support/CompositeItemStream.java | 31 ++++++++++++++-- .../item/support/CompositeItemWriter.java | 28 ++++++++++++++- .../listener/CompositeRepeatListener.java | 36 ++++++++++++++++++- 5 files changed, 147 insertions(+), 6 deletions(-) diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/CompositeChunkListener.java b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/CompositeChunkListener.java index 66e882cc2d..ba887b04c9 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/listener/CompositeChunkListener.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/listener/CompositeChunkListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2013 the original author or authors. + * Copyright 2006-2022 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. @@ -15,6 +15,7 @@ */ package org.springframework.batch.core.listener; +import java.util.Arrays; import java.util.Iterator; import java.util.List; @@ -30,6 +31,31 @@ public class CompositeChunkListener implements ChunkListener { private OrderedComposite listeners = new OrderedComposite<>(); + /** + * Default constrcutor + */ + public CompositeChunkListener() { + + } + + /** + * Convenience constructor for setting the {@link ChunkListener}s. + * + * @param listeners list of {@link ChunkListener}. + */ + public CompositeChunkListener(List listeners) { + setListeners(listeners); + } + + /** + * Convenience constructor for setting the {@link ChunkListener}s. + * + * @param listeners array of {@link ChunkListener}. + */ + public CompositeChunkListener(ChunkListener... listeners) { + this(Arrays.asList(listeners)); + } + /** * Public setter for the listeners. * diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/CompositeItemProcessor.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/CompositeItemProcessor.java index 28705db22c..ebea1dbf16 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/CompositeItemProcessor.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/CompositeItemProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2019 the original author or authors. + * Copyright 2006-2022 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. @@ -21,6 +21,7 @@ import org.springframework.lang.Nullable; import org.springframework.util.Assert; +import java.util.Arrays; import java.util.List; /** @@ -38,6 +39,33 @@ public class CompositeItemProcessor implements ItemProcessor, Initia private List> delegates; + /** + * Default constrcutor + */ + public CompositeItemProcessor() { + + } + + /** + * Convenience constructor for setting the delegates. + * + * @param delegates array of {@link ItemProcessor} delegates that will work on the + * item. + */ + public CompositeItemProcessor(ItemProcessor... delegates) { + this(Arrays.asList(delegates)); + } + + /** + * Convenience constructor for setting the delegates. + * + * @param delegates list of {@link ItemProcessor} delegates that will work on the + * item. + */ + public CompositeItemProcessor(List> delegates) { + setDelegates(delegates); + } + @Nullable @Override @SuppressWarnings("unchecked") diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/CompositeItemStream.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/CompositeItemStream.java index 75a64bdc31..331cdf6721 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/CompositeItemStream.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/CompositeItemStream.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2019 the original author or authors. + * Copyright 2006-2022 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. @@ -34,6 +34,15 @@ public class CompositeItemStream implements ItemStream { private final List streams = new ArrayList<>(); + /** + * Public setter for the {@link ItemStream}s. + * + * @param streams {@link List} of {@link ItemStream}. + */ + public void setStreams(List streams) { + this.streams.addAll(streams); + } + /** * Public setter for the {@link ItemStream}s. * @@ -58,12 +67,30 @@ public void register(ItemStream stream) { } /** - * + * Default constrcutor */ public CompositeItemStream() { super(); } + /** + * Convenience constructor for setting the {@link ItemStream}s. + * + * @param streams {@link List} of {@link ItemStream}. + */ + public CompositeItemStream(List streams) { + setStreams(streams); + } + + /** + * Convenience constructor for setting the {@link ItemStream}s. + * + * @param streams array of {@link ItemStream}. + */ + public CompositeItemStream(ItemStream... streams) { + setStreams(streams); + } + /** * Simple aggregate {@link ExecutionContext} provider for the contributions * registered under the given key. diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/CompositeItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/CompositeItemWriter.java index 8630a958c3..7357c1ede7 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/CompositeItemWriter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/CompositeItemWriter.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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. @@ -24,6 +24,7 @@ import org.springframework.beans.factory.InitializingBean; import org.springframework.util.Assert; +import java.util.Arrays; import java.util.List; /** @@ -41,6 +42,31 @@ public class CompositeItemWriter implements ItemStreamWriter, Initializing private boolean ignoreItemStream = false; + /** + * Default constrcutor + */ + public CompositeItemWriter() { + + } + + /** + * Convenience constructor for setting the delegates. + * + * @param delegates the list of delegates to use. + */ + public CompositeItemWriter(List> delegates) { + setDelegates(delegates); + } + + /** + * Convenience constructor for setting the delegates. + * + * @param delegates the array of delegates to use. + */ + public CompositeItemWriter(ItemWriter... delegates) { + this(Arrays.asList(delegates)); + } + /** * Establishes the policy whether to call the open, close, or update methods for the * item writer delegates associated with the CompositeItemWriter. diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/listener/CompositeRepeatListener.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/listener/CompositeRepeatListener.java index 35f2f70359..68919c42c8 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/listener/CompositeRepeatListener.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/listener/CompositeRepeatListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,40 @@ public class CompositeRepeatListener implements RepeatListener { private List listeners = new ArrayList<>(); + /** + * Default constrcutor + */ + public CompositeRepeatListener() { + + } + + /** + * Convenience constructor for setting the {@link RepeatListener}s. + * + * @param listeners {@link List} of RepeatListeners to be used by the CompositeRepeatListener. + */ + public CompositeRepeatListener(List listeners) { + setListeners(listeners); + } + + /** + * Convenience constructor for setting the {@link RepeatListener}s. + * + * @param listeners array of RepeatListeners to be used by the CompositeRepeatListener. + */ + public CompositeRepeatListener(RepeatListener... listeners) { + setListeners(listeners); + } + + /** + * Public setter for the listeners. + * + * @param listeners {@link List} of RepeatListeners to be used by the CompositeRepeatListener. + */ + public void setListeners(List listeners) { + this.listeners = listeners; + } + /** * Public setter for the listeners. *