BATCH-2761: Varargs in reader, processor, and writer builders

If a builder has a builder method that takes a List, it should also provide a builder method that takes a varargs.
This commit is contained in:
Drummond Dawson
2018-10-01 17:37:26 -04:00
committed by Mahmoud Ben Hassine
parent 2ee15d2f4c
commit 2f0c2a6772
16 changed files with 187 additions and 46 deletions

View File

@@ -16,6 +16,7 @@
package org.springframework.batch.item.data.builder;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@@ -31,6 +32,7 @@ import org.springframework.util.StringUtils;
*
* @author Glenn Renfro
* @author Mahmoud Ben Hassine
* @author Drummond Dawson
* @since 4.0
* @see MongoItemReader
*/
@@ -41,7 +43,7 @@ public class MongoItemReaderBuilder<T> {
private Class<? extends T> targetType;
Map<String, Sort.Direction> sorts;
private Map<String, Sort.Direction> sorts;
private String hint;
@@ -175,6 +177,17 @@ public class MongoItemReaderBuilder<T> {
return this;
}
/**
* Values to be substituted in for each of the parameters in the query.
*
* @param parameterValues values
* @return The current instance of the builder
* @see MongoItemReader#setParameterValues(List)
*/
public MongoItemReaderBuilder<T> parameterValues(Object... parameterValues) {
return parameterValues(Arrays.asList(parameterValues));
}
/**
* JSON defining the fields to be returned from the matching documents by MongoDB.
*

View File

@@ -37,10 +37,10 @@ import org.springframework.util.StringUtils;
*
* @author Glenn Renfro
* @author Mahmoud Ben Hassine
* @author Drummond Dawson
* @since 4.0
* @see RepositoryItemReader
*/
public class RepositoryItemReaderBuilder<T> {
private PagingAndSortingRepository<?, ?> repository;
@@ -131,6 +131,17 @@ public class RepositoryItemReaderBuilder<T> {
return this;
}
/**
* Arguments to be passed to the data providing method.
*
* @param arguments the method arguments to be passed to the repository.
* @return The current instance of the builder.
* @see RepositoryItemReader#setArguments(List)
*/
public RepositoryItemReaderBuilder<T> arguments(Object... arguments) {
return arguments(Arrays.asList(arguments));
}
/**
* Provides ordering of the results so that order is maintained between paged queries.
*

View File

@@ -35,6 +35,7 @@ import org.springframework.util.StringUtils;
*
* @author Michael Minella
* @author Glenn Renfro
* @author Drummond Dawson
* @since 4.0
*/
public class JdbcCursorItemReaderBuilder<T> {
@@ -246,7 +247,7 @@ public class JdbcCursorItemReaderBuilder<T> {
* @param args values to set on the reader query
* @return this instance for method chaining
*/
public JdbcCursorItemReaderBuilder<T> queryArguments(Object[] args) {
public JdbcCursorItemReaderBuilder<T> queryArguments(Object... args) {
this.preparedStatementSetter = new ArgumentPreparedStatementSetter(args);
return this;

View File

@@ -31,6 +31,7 @@ import org.springframework.util.StringUtils;
*
* @author Michael Minella
* @author Mahmoud Ben Hassine
* @author Drummond Dawson
* @since 4.0.0
* @see StoredProcedureItemReader
*/
@@ -284,7 +285,7 @@ public class StoredProcedureItemReaderBuilder<T> {
* @return this instance for method chaining
* @see StoredProcedureItemReader#setParameters(SqlParameter[])
*/
public StoredProcedureItemReaderBuilder<T> parameters(SqlParameter[] parameters) {
public StoredProcedureItemReaderBuilder<T> parameters(SqlParameter... parameters) {
this.parameters = parameters;
return this;

View File

@@ -54,6 +54,7 @@ import org.springframework.util.StringUtils;
* @author Michael Minella
* @author Glenn Renfro
* @author Mahmoud Ben Hassine
* @author Drummond Dawson
* @since 4.0
* @see FlatFileItemReader
*/
@@ -183,7 +184,7 @@ public class FlatFileItemReaderBuilder<T> {
* @return The current instance of the builder.
* @see FlatFileItemReader#setComments(String[])
*/
public FlatFileItemReaderBuilder<T> comments(String[] comments) {
public FlatFileItemReaderBuilder<T> comments(String... comments) {
this.comments.addAll(Arrays.asList(comments));
return this;
}
@@ -610,7 +611,7 @@ public class FlatFileItemReaderBuilder<T> {
* @return The parent {@link FlatFileItemReaderBuilder}
* @see DelimitedLineTokenizer#setNames(String[])
*/
public FlatFileItemReaderBuilder<T> names(String [] names) {
public FlatFileItemReaderBuilder<T> names(String... names) {
this.names.addAll(Arrays.asList(names));
return this.parent;
}
@@ -691,7 +692,7 @@ public class FlatFileItemReaderBuilder<T> {
* @return This instance for chaining
* @see FixedLengthTokenizer#setColumns(Range[])
*/
public FixedLengthBuilder<T> columns(Range[] ranges) {
public FixedLengthBuilder<T> columns(Range... ranges) {
this.ranges.addAll(Arrays.asList(ranges));
return this;
}
@@ -728,7 +729,7 @@ public class FlatFileItemReaderBuilder<T> {
* @return The parent builder
* @see FixedLengthTokenizer#setNames(String[])
*/
public FlatFileItemReaderBuilder<T> names(String [] names) {
public FlatFileItemReaderBuilder<T> names(String... names) {
this.names.addAll(Arrays.asList(names));
return this.parent;
}

View File

@@ -38,6 +38,7 @@ import org.springframework.util.StringUtils;
* @author Michael Minella
* @author Glenn Renfro
* @author Mahmoud Ben Hassine
* @author Drummond Dawson
* @since 4.0
* @see FlatFileItemWriter
*/
@@ -364,7 +365,7 @@ public class FlatFileItemWriterBuilder<T> {
* @return The parent {@link FlatFileItemWriterBuilder}
* @see BeanWrapperFieldExtractor#setNames(String[])
*/
public FlatFileItemWriterBuilder<T> names(String[] names) {
public FlatFileItemWriterBuilder<T> names(String... names) {
this.names.addAll(Arrays.asList(names));
return this.parent;
}
@@ -438,7 +439,7 @@ public class FlatFileItemWriterBuilder<T> {
* @return The parent {@link FlatFileItemWriterBuilder}
* @see BeanWrapperFieldExtractor#setNames(String[])
*/
public FlatFileItemWriterBuilder<T> names(String[] names) {
public FlatFileItemWriterBuilder<T> names(String... names) {
this.names.addAll(Arrays.asList(names));
return this.parent;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017 the original author or authors.
* Copyright 2017-2018 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.
@@ -28,6 +28,7 @@ import org.springframework.util.StringUtils;
* A builder implementation for the {@link MultiResourceItemReader}.
*
* @author Glenn Renfro
* @author Drummond Dawson
* @since 4.0
* @see MultiResourceItemReader
*/
@@ -83,7 +84,7 @@ public class MultiResourceItemReaderBuilder<T> {
*
* @see MultiResourceItemReader#setResources(Resource[])
*/
public MultiResourceItemReaderBuilder<T> resources(Resource[] resources) {
public MultiResourceItemReaderBuilder<T> resources(Resource... resources) {
this.resources = resources;
return this;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017 the original author or authors.
* Copyright 2017-2018 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.
@@ -16,6 +16,7 @@
package org.springframework.batch.item.support.builder;
import java.util.Arrays;
import java.util.List;
import org.springframework.batch.item.ItemProcessor;
@@ -26,7 +27,7 @@ import org.springframework.util.Assert;
* Creates a fully qualified {@link CompositeItemProcessorBuilder}.
*
* @author Glenn Renfro
*
* @author Drummond Dawson
* @since 4.0
*/
public class CompositeItemProcessorBuilder<I, O> {
@@ -44,6 +45,16 @@ public class CompositeItemProcessorBuilder<I, O> {
return this;
}
/**
* Establishes the {@link ItemProcessor} delegates that will work on the item to be processed.
* @param delegates the {@link ItemProcessor} delegates that will work on the item.
* @return this instance for method chaining.
* @see CompositeItemProcessorBuilder#delegates(List)
*/
public CompositeItemProcessorBuilder<I, O> delegates(ItemProcessor<?, ?>... delegates) {
return delegates(Arrays.asList(delegates));
}
/**
* Returns a fully constructed {@link CompositeItemProcessor}.
*

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017 the original author or authors.
* Copyright 2017-2018 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.
@@ -16,6 +16,7 @@
package org.springframework.batch.item.support.builder;
import java.util.Arrays;
import java.util.List;
import org.springframework.batch.item.ItemWriter;
@@ -26,7 +27,7 @@ import org.springframework.util.Assert;
* Creates a fully qualified CompositeItemWriter.
*
* @author Glenn Renfro
*
* @author Drummond Dawson
* @since 4.0
*/
public class CompositeItemWriterBuilder<T> {
@@ -67,6 +68,20 @@ public class CompositeItemWriterBuilder<T> {
return this;
}
/**
* The item writers to use as delegates. Items are written to each of the
* delegates.
*
* @param delegates the delegates to use. The delegates list must not be null
* nor be empty.
* @return this instance for method chaining.
*
* @see CompositeItemWriter#setDelegates(List)
*/
public CompositeItemWriterBuilder<T> delegates(ItemWriter<? super T>... delegates) {
return delegates(Arrays.asList(delegates));
}
/**
* Returns a fully constructed {@link CompositeItemWriter}.
*