Package org.springframework.batch.core.job.flow.support

# Class StateTransition

java.lang.Object
org.springframework.batch.core.job.flow.support.StateTransition

public final class StateTransition extends Object
Value object representing a potential transition from one `State` to another. The originating State name and the next `State` to execute are linked by a pattern for the `exit code` of an execution of the originating State.

Since:
  2.0
Author:
  Dave Syer, Michael Minella, Mahmoud Ben Hassine

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static StateTransition`
  `createEndStateTransition(State state)`
  Create a new end state `StateTransition` specification.
  `static StateTransition`
  `createEndStateTransition(State state, String pattern)`
  Create a new end state `StateTransition` specification.
  `static StateTransition`
  `createStateTransition(State state, String next)`
  Create a new state `StateTransition` specification with a wildcard pattern that matches all outcomes.
  `static StateTransition`
  `createStateTransition(State state, String pattern, String next)`
  Create a new `StateTransition` specification from one `State` to another (by name).
  `String`
  `getNext()`
  Public getter for the next State name.
  `String`
  `getPattern()`
  `State`
  `getState()`
  Public getter for the State.
  `boolean`
  `isEnd()`
  Check for a special next State signalling the end of a job.
  `boolean`
  `matches(String status)`
  Check if the provided status matches the pattern, signalling that the next State should be executed.
  `static StateTransition`
  `switchOriginAndDestination(StateTransition stateTransition, State state, String next)`
  Convenience method to switch the origin and destination of a transition, creating a new instance.
  `String`
  `toString()`

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

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

- ## Method Details

  - ### getPattern

    public String getPattern()
    Returns:
      the pattern the `ExitStatus.getExitCode()` will be compared against.

  - ### createEndStateTransition

    public static StateTransition createEndStateTransition(State state)
    Create a new end state `StateTransition` specification. This transition explicitly goes unconditionally to an end state (i.e. no more executions).
    Parameters:
      `state` - the `State` used to generate the outcome for this transition
    Returns:
      `StateTransition` that was created.

  - ### createEndStateTransition

    public static StateTransition createEndStateTransition(State state, String pattern)
    Create a new end state `StateTransition` specification. This transition explicitly goes to an end state (i.e. no more processing) if the outcome matches the pattern.
    Parameters:
      `state` - the `State` used to generate the outcome for this transition
      `pattern` - the pattern to match in the exit status of the `State`
    Returns:
      `StateTransition` that was created.

  - ### switchOriginAndDestination

    public static StateTransition switchOriginAndDestination(StateTransition stateTransition, State state, String next)
    Convenience method to switch the origin and destination of a transition, creating a new instance.
    Parameters:
      `stateTransition` - an existing state transition
      `state` - the new state for the origin
      `next` - the new name for the destination
    Returns:
      `StateTransition` that was created.

  - ### createStateTransition

    public static StateTransition createStateTransition(State state, String next)
    Create a new state `StateTransition` specification with a wildcard pattern that matches all outcomes.
    Parameters:
      `state` - the `State` used to generate the outcome for this transition
      `next` - the name of the next `State` to execute
    Returns:
      `StateTransition` that was created.

  - ### createStateTransition

    public static StateTransition createStateTransition(State state, @Nullable String pattern, @Nullable String next)
    Create a new `StateTransition` specification from one `State` to another (by name).
    Parameters:
      `state` - the `State` used to generate the outcome for this transition
      `pattern` - the pattern to match in the exit status of the `State` (can be `null`)
      `next` - the name of the next `State` to execute (can be `null`)
    Returns:
      `StateTransition` that was created.

  - ### getState

    public State getState()
    Public getter for the State.
    Returns:
      the State

  - ### getNext

    public String getNext()
    Public getter for the next State name.
    Returns:
      the next

  - ### matches

    public boolean matches(String status)
    Check if the provided status matches the pattern, signalling that the next State should be executed.
    Parameters:
      `status` - the status to compare
    Returns:
      true if the pattern matches this status

  - ### isEnd

    public boolean isEnd()
    Check for a special next State signalling the end of a job.
    Returns:
      true if this transition goes nowhere (there is no next)

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`