Record Class ForEachSlicePlan<T,C>

java.lang.Object
java.lang.Record
dev.engine_room.flywheel.lib.task.ForEachSlicePlan<T,C>
Type Parameters:
T - The type of the list elements.
C - The type of the context object.
Record Components:
listSupplier - A supplier of the list to iterate over.
action - The action to perform on each sub list.
All Implemented Interfaces:
Plan<C>, SimplyComposedPlan<C>

public record ForEachSlicePlan<T,C>(SupplierWithContext<C,List<T>> listSupplier, ConsumerWithContext<List<T>,C> action) extends Record implements SimplyComposedPlan<C>
A plan that executes code over many slices of a provided list.

The size of the slice is dynamically determined based on the number of available threads.

  • Constructor Details

  • Method Details

    • of

      public static <T, C> ForEachSlicePlan<T,C> of(SupplierWithContext<C,List<T>> iterable, ConsumerWithContext<List<T>,C> forEach)
    • of

      public static <T, C> ForEachSlicePlan<T,C> of(SupplierWithContext<C,List<T>> iterable, ConsumerWithContext.Ignored<List<T>,C> forEach)
    • of

      public static <T, C> ForEachSlicePlan<T,C> of(SupplierWithContext.Ignored<C,List<T>> iterable, ConsumerWithContext<List<T>,C> forEach)
    • of

      public static <T, C> ForEachSlicePlan<T,C> of(SupplierWithContext.Ignored<C,List<T>> iterable, ConsumerWithContext.Ignored<List<T>,C> forEach)
    • 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<T>
      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.
    • listSupplier

      public SupplierWithContext<C,List<T>> listSupplier()
      Returns the value of the listSupplier record component.
      Returns:
      the value of the listSupplier record component
    • action

      public ConsumerWithContext<List<T>,C> action()
      Returns the value of the action record component.
      Returns:
      the value of the action record component