Class TransitionConditionPackager

java.lang.Object
io.github.jspinak.brobot.navigation.transition.TransitionConditionPackager

@Component public class TransitionConditionPackager extends Object
Converts various transition types into executable BooleanSupplier functions.

TransitionConditionPackager serves as an adapter that unifies different transition implementations (JavaStateTransition and ActionDefinitionStateTransition) into a common executable format. This allows the transition execution engine to work with transitions regardless of whether they're defined in code or through declarative action definitions.

Key responsibilities:

  • Type Adaptation: Converts StateTransition implementations to BooleanSupplier
  • Action Execution: Orchestrates multi-step ActionDefinitions
  • Success Evaluation: Determines overall success based on final step
  • Sequential Processing: Executes action steps in order without conditional logic

ActionDefinition execution strategy:

  1. Execute all steps except the last one (side effects only)
  2. Execute the final step and evaluate its success
  3. Return the success of only the final step
  4. This assumes no conditional logic between steps

Design assumptions for ActionDefinitions:

  • Steps are independent - no step depends on previous step's success
  • All steps should execute regardless of individual failures
  • Only the final step determines overall transition success
  • Intermediate steps are for setup or side effects

Example ActionDefinition pattern:

 Step 1: Click "Open Menu" button (setup action)
 Step 2: Click "Settings" option (navigation action)
 Step 3: Find "Settings Page" header (verification action)

 Only Step 3's success determines if transition succeeded
 

Integration with transition types:

  • JavaStateTransition: Simply extracts existing BooleanSupplier
  • ActionDefinitionStateTransition: Builds BooleanSupplier from action steps
  • Future Types: Can be extended for new transition implementations

In the model-based approach, this packager enables seamless integration of different automation styles - from programmatic transitions written in Java to declarative workflows defined through visual tools. This flexibility allows teams to choose the most appropriate representation for each transition while maintaining a unified execution model.

Since:
1.0
See Also:
  • Constructor Details

    • TransitionConditionPackager

      public TransitionConditionPackager(Action action)
  • Method Details

    • toBooleanSupplier

      public BooleanSupplier toBooleanSupplier(StateTransition transition)
      Converts a StateTransition to an executable BooleanSupplier.

      Handles polymorphic dispatch based on transition type:

      • JavaStateTransition: Extracts existing function
      • ActionDefinition-based: Builds function from steps
      Parameters:
      transition - StateTransition to convert
      Returns:
      BooleanSupplier that executes the transition logic
      Throws:
      IllegalArgumentException - if transition type is unsupported
    • toBooleanSupplier

      public BooleanSupplier toBooleanSupplier(TaskSequence actionDefinition)
      Converts an ActionDefinition into an executable BooleanSupplier.

      Creates a function that executes all action steps sequentially, with only the final step's success determining the overall result. This design supports multi-step transitions where intermediate steps perform setup or navigation actions, and the final step verifies arrival at the target state.

      Execution behavior:

      • All steps execute regardless of individual success/failure
      • No conditional logic between steps
      • Only the last step's success is evaluated
      • Empty definitions return false

      Example usage pattern:

       ActionDefinition transition = new ActionDefinition();
       transition.addStep(click("Menu"));      // Setup - success ignored
       transition.addStep(click("Settings"));  // Navigate - success ignored
       transition.addStep(find("SettingsPage")); // Verify - determines success
       
      Parameters:
      actionDefinition - Definition containing ordered action steps
      Returns:
      BooleanSupplier that executes all steps and returns final step success
    • getAsBoolean

      public boolean getAsBoolean(StateTransition transition)
      Executes a transition and returns its success status.

      Convenience method that converts and immediately executes a transition. Useful when you need a one-time execution without storing the supplier.

      Parameters:
      transition - StateTransition to execute
      Returns:
      true if transition succeeded, false otherwise
      See Also: