Record Class IfElsePlan<C>

java.lang.Object
java.lang.Record
dev.engine_room.flywheel.lib.task.IfElsePlan<C>
Type Parameters:
C - The type of the context object.
Record Components:
condition - The condition to branch on.
onTrue - The plan to execute if the condition is true.
onFalse - The plan to execute if the condition is false.
All Implemented Interfaces:
Plan<C>, SimplyComposedPlan<C>

public record IfElsePlan<C>(BooleanSupplierWithContext<C> condition, Plan<C> onTrue, Plan<C> onFalse) extends Record implements SimplyComposedPlan<C>
Executes one plan or another, depending on a dynamically evaluated condition.
  • Constructor Details

    • IfElsePlan

      public IfElsePlan(BooleanSupplierWithContext<C> condition, Plan<C> onTrue, Plan<C> onFalse)
      Creates an instance of a IfElsePlan record class.
      Parameters:
      condition - the value for the condition record component
      onTrue - the value for the onTrue record component
      onFalse - the value for the onFalse record component
  • Method Details

    • on

      public static <C> IfElsePlan.Builder<C> on(BooleanSupplierWithContext<C> condition)
    • on

      public static <C> IfElsePlan.Builder<C> on(BooleanSupplierWithContext.Ignored<C> condition)
    • execute

      public void execute(TaskExecutor taskExecutor, C context, Runnable onCompletion)
      Description copied from interface: Plan
      Submit this plan for execution.

      You must call onCompletion.run() when the plan has completed execution.

      Specified by:
      execute in interface Plan<C>
      Parameters:
      taskExecutor - The executor to use for submitting tasks.
      context - An arbitrary context object that the plan wants to use at runtime.
      onCompletion - A callback to run when the plan has completed execution, useful for chaining plans.
    • toString

      public final 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
    • equals

      public final 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.
    • condition

      public BooleanSupplierWithContext<C> condition()
      Returns the value of the condition record component.
      Returns:
      the value of the condition record component
    • onTrue

      public Plan<C> onTrue()
      Returns the value of the onTrue record component.
      Returns:
      the value of the onTrue record component
    • onFalse

      public Plan<C> onFalse()
      Returns the value of the onFalse record component.
      Returns:
      the value of the onFalse record component