Skip to content

Commit

Permalink
Add constructors with var args/Lists
Browse files Browse the repository at this point in the history
For classes that have a setter for a List<T> field,
create Constructors that take List<T> and var args of T.

Issue #686
  • Loading branch information
drumonii authored and fmbenhassine committed Mar 21, 2022
1 parent 968a5b5 commit 15e18e5
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 6 deletions.
@@ -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.
Expand All @@ -15,6 +15,7 @@
*/
package org.springframework.batch.core.listener;

import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

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

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

/**
* Default constrcutor
*/
public CompositeChunkListener() {

}

/**
* Convenience constructor for setting the {@link ChunkListener}s.
*
* @param listeners list of {@link ChunkListener}.
*/
public CompositeChunkListener(List<? extends ChunkListener> 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.
*
Expand Down
@@ -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.
Expand All @@ -21,6 +21,7 @@
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;

import java.util.Arrays;
import java.util.List;

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

private List<? extends ItemProcessor<?, ?>> 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<? extends ItemProcessor<?, ?>> delegates) {
setDelegates(delegates);
}

@Nullable
@Override
@SuppressWarnings("unchecked")
Expand Down
@@ -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.
Expand Down Expand Up @@ -34,6 +34,15 @@ public class CompositeItemStream implements ItemStream {

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

/**
* Public setter for the {@link ItemStream}s.
*
* @param streams {@link List} of {@link ItemStream}.
*/
public void setStreams(List<ItemStream> streams) {
this.streams.addAll(streams);
}

/**
* Public setter for the {@link ItemStream}s.
*
Expand All @@ -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<ItemStream> 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.
Expand Down
@@ -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.
Expand All @@ -24,6 +24,7 @@
import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.Assert;

import java.util.Arrays;
import java.util.List;

/**
Expand All @@ -41,6 +42,31 @@ public class CompositeItemWriter<T> implements ItemStreamWriter<T>, 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<ItemWriter<? super T>> delegates) {
setDelegates(delegates);
}

/**
* Convenience constructor for setting the delegates.
*
* @param delegates the array of delegates to use.
*/
public CompositeItemWriter(ItemWriter<? super T>... 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.
Expand Down
@@ -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.
Expand Down Expand Up @@ -33,6 +33,40 @@ public class CompositeRepeatListener implements RepeatListener {

private List<RepeatListener> 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<RepeatListener> 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<RepeatListener> listeners) {
this.listeners = listeners;
}

/**
* Public setter for the listeners.
*
Expand Down

0 comments on commit 15e18e5

Please sign in to comment.