org.springframework.batch.core

## Class JobParametersBuilder

- java.lang.Object
- - org.springframework.batch.core.JobParametersBuilder

-     public class JobParametersBuilder
      extends java.lang.Object

  Helper class for creating `JobParameters`. Useful because all `JobParameter` objects are immutable, and must be instantiated separately to ensure type safety. Once created, it can be used in the same was a java.lang.StringBuilder (except, order is irrelevant), by adding various parameter types and creating a valid `JobParameters` once finished.
  Using the identifying flag indicates if the parameter will be used in the identification of a JobInstance. That flag defaults to true.
  Since:
    1.0
  Author:
    Lucas Ward, Michael Minella, Glenn Renfro, Mahmoud Ben Hassine
  See Also:
    `JobParameters`, `JobParameter`

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `JobParametersBuilder()` Default constructor.
    `JobParametersBuilder(JobExplorer jobExplorer)`
    `JobParametersBuilder(JobParameters jobParameters)` Copy constructor.
    `JobParametersBuilder(JobParameters jobParameters, JobExplorer jobExplorer)` Copy constructor.
    `JobParametersBuilder(java.util.Properties properties)` Constructor to add conversion capabilities to support JSR-352.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `JobParametersBuilder` | `addDate(java.lang.String key, java.util.Date parameter)` Add a new identifying `Date` parameter for the given key.
    `JobParametersBuilder` | `addDate(java.lang.String key, java.util.Date parameter, boolean identifying)` Add a new `Date` parameter for the given key.
    `JobParametersBuilder` | `addDouble(java.lang.String key, java.lang.Double parameter)` Add a new identifying Double parameter for the given key.
    `JobParametersBuilder` | `addDouble(java.lang.String key, java.lang.Double parameter, boolean identifying)` Add a new Double parameter for the given key.
    `JobParametersBuilder` | `addJobParameters(JobParameters jobParameters)` Copy job parameters into the current state.
    `JobParametersBuilder` | `addLong(java.lang.String key, java.lang.Long parameter)` Add a new identifying Long parameter for the given key.
    `JobParametersBuilder` | `addLong(java.lang.String key, java.lang.Long parameter, boolean identifying)` Add a new Long parameter for the given key.
    `JobParametersBuilder` | `addParameter(java.lang.String key, JobParameter jobParameter)` Add a new `JobParameter` for the given key.
    `JobParametersBuilder` | `addString(java.lang.String key, java.lang.String parameter)` Add a new identifying String parameter for the given key.
    `JobParametersBuilder` | `addString(java.lang.String key, java.lang.String parameter, boolean identifying)` Add a new String parameter for the given key.
    `JobParametersBuilder` | `getNextJobParameters(Job job)` Initializes the `JobParameters` based on the state of the `Job`.
    `JobParameters` | `toJobParameters()` Conversion method that takes the current state of this builder and returns it as a JobParameters object.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### JobParametersBuilder

          public JobParametersBuilder()

      Default constructor. Initializes the builder with empty parameters.

    - #### JobParametersBuilder

          public JobParametersBuilder(JobExplorer jobExplorer)

      Parameters:
        `jobExplorer` - `JobExplorer` used for looking up previous job parameter information

    - #### JobParametersBuilder

          public JobParametersBuilder(JobParameters jobParameters)

      Copy constructor. Initializes the builder with the supplied parameters.
      Parameters:
        `jobParameters` - `JobParameters` instance used to initialize the builder.

    - #### JobParametersBuilder

          public JobParametersBuilder(java.util.Properties properties)

      Constructor to add conversion capabilities to support JSR-352. Per the spec, it is expected that all keys and values in the provided `Properties` instance are Strings
      Parameters:
        `properties` - the job parameters to be used

    - #### JobParametersBuilder

          public JobParametersBuilder(JobParameters jobParameters,
                                      JobExplorer jobExplorer)

      Copy constructor. Initializes the builder with the supplied parameters.
      Parameters:
        `jobParameters` - `JobParameters` instance used to initialize the builder.
        `jobExplorer` - `JobExplorer` used for looking up previous job parameter information

  - ### Method Detail

    - #### addString

          public JobParametersBuilder addString(java.lang.String key,
                                                java.lang.String parameter)

      Add a new identifying String parameter for the given key.
      Parameters:
        `key` - - parameter accessor.
        `parameter` - - runtime parameter
      Returns:
        a reference to this object.

    - #### addString

          public JobParametersBuilder addString(java.lang.String key,
                                                java.lang.String parameter,
                                                boolean identifying)

      Add a new String parameter for the given key.
      Parameters:
        `key` - - parameter accessor.
        `parameter` - - runtime parameter
        `identifying` - - indicates if the parameter is used as part of identifying a job instance
      Returns:
        a reference to this object.

    - #### addDate

          public JobParametersBuilder addDate(java.lang.String key,
                                              java.util.Date parameter)

      Add a new identifying `Date` parameter for the given key.
      Parameters:
        `key` - - parameter accessor.
        `parameter` - - runtime parameter
      Returns:
        a reference to this object.

    - #### addDate

          public JobParametersBuilder addDate(java.lang.String key,
                                              java.util.Date parameter,
                                              boolean identifying)

      Add a new `Date` parameter for the given key.
      Parameters:
        `key` - - parameter accessor.
        `parameter` - - runtime parameter
        `identifying` - - indicates if the parameter is used as part of identifying a job instance
      Returns:
        a reference to this object.

    - #### addLong

          public JobParametersBuilder addLong(java.lang.String key,
                                              java.lang.Long parameter)

      Add a new identifying Long parameter for the given key.
      Parameters:
        `key` - - parameter accessor.
        `parameter` - - runtime parameter
      Returns:
        a reference to this object.

    - #### addLong

          public JobParametersBuilder addLong(java.lang.String key,
                                              java.lang.Long parameter,
                                              boolean identifying)

      Add a new Long parameter for the given key.
      Parameters:
        `key` - - parameter accessor.
        `parameter` - - runtime parameter
        `identifying` - - indicates if the parameter is used as part of identifying a job instance
      Returns:
        a reference to this object.

    - #### addDouble

          public JobParametersBuilder addDouble(java.lang.String key,
                                                java.lang.Double parameter)

      Add a new identifying Double parameter for the given key.
      Parameters:
        `key` - - parameter accessor.
        `parameter` - - runtime parameter
      Returns:
        a reference to this object.

    - #### addDouble

          public JobParametersBuilder addDouble(java.lang.String key,
                                                java.lang.Double parameter,
                                                boolean identifying)

      Add a new Double parameter for the given key.
      Parameters:
        `key` - - parameter accessor.
        `parameter` - - runtime parameter
        `identifying` - - indicates if the parameter is used as part of identifying a job instance
      Returns:
        a reference to this object.

    - #### toJobParameters

          public JobParameters toJobParameters()

      Conversion method that takes the current state of this builder and returns it as a JobParameters object.
      Returns:
        a valid `JobParameters` object.

    - #### addParameter

          public JobParametersBuilder addParameter(java.lang.String key,
                                                   JobParameter jobParameter)

      Add a new `JobParameter` for the given key.
      Parameters:
        `key` - - parameter accessor
        `jobParameter` - - runtime parameter
      Returns:
        a reference to this object.

    - #### addJobParameters

          public JobParametersBuilder addJobParameters(JobParameters jobParameters)

      Copy job parameters into the current state.
      Parameters:
        `jobParameters` - parameters to copy in
      Returns:
        a reference to this object.

    - #### getNextJobParameters

          public JobParametersBuilder getNextJobParameters(Job job)

      Initializes the `JobParameters` based on the state of the `Job`. This should be called after all parameters have been entered into the builder. All parameters already set on this builder instance will be appended to those retrieved from the job incrementer, overriding any with the same key (Same behaviour as `CommandLineJobRunner` with "-next" option and `JobOperator.startNextInstance(String)`)
      Parameters:
        `job` - the job for which the `JobParameters` are being constructed.
      Returns:
        a reference to this object.
      Since:
        4.0