Record Class JobParameters

java.lang.Object
java.lang.Record
org.springframework.batch.core.job.parameters.JobParameters
All Implemented Interfaces:
Serializable, Iterable<JobParameter<?>>

public record JobParameters(Set<JobParameter<?>> parameters) extends Record implements Serializable, Iterable<JobParameter<?>>
Value object representing runtime parameters of a batch job. Because the parameters have no individual meaning outside the JobParameters object they are contained within, it is a value object rather than an entity. It is also extremely important that a parameters object can be reliably compared to another for equality, in order to determine if one JobParameters object equals another. This class is a namespace of job parameters and all parameters should have a unique name within that namespace.

Furthermore, because these parameters need to be persisted, it is vital that the types added are restricted.

This class is immutable and, therefore, thread-safe.

Since:
1.0
Author:
Lucas Ward, Michael Minella, Mahmoud Ben Hassine, Taeik Lim
See Also:
  • Constructor Details

    • JobParameters

      public JobParameters()
      Create a new empty JobParameters instance.
      Since:
      6.0
    • JobParameters

      public JobParameters(Set<JobParameter<?>> parameters)
      Create a new JobParameters instance.
      Parameters:
      parameters - the set of job parameters, must not be null or empty
      Since:
      6.0
  • Method Details

    • getLong

      public @Nullable Long getLong(String key)
      Typesafe getter for the Long represented by the provided key.
      Parameters:
      key - The key for which to get a value.
      Returns:
      The Long value or null if the key is absent.
    • getLong

      public @Nullable Long getLong(String key, Long defaultValue)
      Typesafe getter for the Long represented by the provided key. If the key does not exist, the default value is returned.
      Parameters:
      key - The key for which to return the value.
      defaultValue - The default value to return if the value does not exist.
      Returns:
      the parameter represented by the provided key or, if that is missing, the default value.
    • getString

      public @Nullable String getString(String key)
      Typesafe getter for the String represented by the provided key.
      Parameters:
      key - The key for which to get a value.
      Returns:
      The String value or null if the key is absent.
    • getString

      public @Nullable String getString(String key, String defaultValue)
      Typesafe getter for the String represented by the provided key. If the key does not exist, the default value is returned.
      Parameters:
      key - The key for which to return the value.
      defaultValue - The defult value to return if the value does not exist.
      Returns:
      the parameter represented by the provided key or, if that is missing, the default value.
    • getDouble

      public @Nullable Double getDouble(String key)
      Typesafe getter for the Double represented by the provided key.
      Parameters:
      key - The key for which to get a value.
      Returns:
      The Double value or null if the key is absent.
    • getDouble

      public @Nullable Double getDouble(String key, Double defaultValue)
      Typesafe getter for the Double represented by the provided key. If the key does not exist, the default value is returned.
      Parameters:
      key - The key for which to return the value.
      defaultValue - The default value to return if the value does not exist.
      Returns:
      the parameter represented by the provided key or, if that is missing, the default value.
    • getDate

      public @Nullable Date getDate(String key)
      Typesafe getter for the Date represented by the provided key.
      Parameters:
      key - The key for which to get a value.
      Returns:
      the Date value or null if the key is absent.
    • getDate

      public @Nullable Date getDate(String key, Date defaultValue)
      Typesafe getter for the Date represented by the provided key. If the key does not exist, the default value is returned.
      Parameters:
      key - The key for which to return the value.
      defaultValue - The default value to return if the value does not exist.
      Returns:
      the parameter represented by the provided key or, if that is missing, the default value.
    • getLocalDate

      public @Nullable LocalDate getLocalDate(String key)
      Typesafe getter for the LocalDate represented by the provided key.
      Parameters:
      key - The key for which to get a value.
      Returns:
      the LocalDate value or null if the key is absent.
    • getLocalDate

      public @Nullable LocalDate getLocalDate(String key, LocalDate defaultValue)
      Typesafe getter for the LocalDate represented by the provided key. If the key does not exist, the default value is returned.
      Parameters:
      key - The key for which to return the value.
      defaultValue - The default value to return if the value does not exist.
      Returns:
      the parameter represented by the provided key or, if that is missing, the default value.
    • getLocalTime

      public @Nullable LocalTime getLocalTime(String key)
      Typesafe getter for the LocalTime represented by the provided key.
      Parameters:
      key - The key for which to get a value.
      Returns:
      the LocalTime value or null if the key is absent.
    • getLocalTime

      public @Nullable LocalTime getLocalTime(String key, LocalTime defaultValue)
      Typesafe getter for the LocalTime represented by the provided key. If the key does not exist, the default value is returned.
      Parameters:
      key - The key for which to return the value.
      defaultValue - The default value to return if the value does not exist.
      Returns:
      the parameter represented by the provided key or, if that is missing, the default value.
    • getLocalDateTime

      public @Nullable LocalDateTime getLocalDateTime(String key)
      Typesafe getter for the LocalDateTime represented by the provided key.
      Parameters:
      key - The key for which to get a value.
      Returns:
      the LocalDateTime value or null if the key is absent.
    • getLocalDateTime

      public @Nullable LocalDateTime getLocalDateTime(String key, LocalDateTime defaultValue)
      Typesafe getter for the LocalDateTime represented by the provided key. If the key does not exist, the default value is returned.
      Parameters:
      key - The key for which to return the value.
      defaultValue - The default value to return if the value does not exist.
      Returns:
      the parameter represented by the provided key or, if that is missing, the default value.
    • getParameter

      public @Nullable JobParameter<?> getParameter(String key)
    • parameters

      public Set<JobParameter<?>> parameters()
      Get a set of all parameters.
      Returns:
      an unmodifiable set containing all parameters.
    • getIdentifyingParameters

      public Set<JobParameter<?>> getIdentifyingParameters()
      Get a set of identifying parameters.
      Returns:
      an unmodifiable set containing identifying parameters.
      Since:
      5.1
    • isEmpty

      public boolean isEmpty()
      Returns:
      true if the parameters object is empty or false otherwise.
    • iterator

      public Iterator<JobParameter<?>> iterator()
      Specified by:
      iterator in interface Iterable<JobParameter<?>>
    • forEach

      public void forEach(Consumer<? super JobParameter<?>> action)
      Specified by:
      forEach in interface Iterable<JobParameter<?>>
    • equals

      public boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object