Class WithdrawPlan

java.lang.Object
privbot.hooks.bank.WithdrawPlan

public final class WithdrawPlan extends Object
Tracks progress through a list of (item, quantity) withdraw lines.

Quantities are a top-up target: a line is satisfied when the inventory holds at least quantity of the item, however many clicks that took. Progress is measured against a live inventory count, so a dropped click self-corrects and re-running the action inside a loop does not stack withdrawals.

A line may be skipped when it cannot be fulfilled. Skipping retires it from the work queue without marking it satisfied, so isComplete(java.util.function.ToIntFunction<java.lang.String>) still reports false and partial success is never silently swallowed.

WithdrawPlan.Skip.INVENTORY_FULL retires one line, not the run. Free slots are shared, so a full pack is usually terminal — but not always: a later line for something a stack is already held of needs no new slot and can still succeed. Ending the whole plan on the first full-pack line would silently drop those, so each line gets its own answer.

Pure logic: no client access, fully unit-testable.

  • Field Details

    • ALL

      public static final int ALL
      A quantity at or above this means "all of it", matching the GUI's 0-or-blank convention.
      See Also:
  • Constructor Details

  • Method Details

    • parseLines

      public static List<WithdrawPlan.Line> parseLines(String text)
      Parses a free-form item list, e.g. "Shark x10, Prayer potion(4) x4, Rune axe".
      Returns:
      never null; blank entries are dropped
    • lines

      public List<WithdrawPlan.Line> lines()
    • remaining

      public static int remaining(WithdrawPlan.Line line, int have)
      Units still needed to reach the line's target. Never negative.

      An all line always reports work outstanding — it has no numeric target to compare against — so callers must retire it through markSatisfied(int) instead.

    • activeLine

      public int activeLine(ToIntFunction<String> inventoryCount)
      Returns:
      index of the first line that is neither satisfied nor skipped, or -1 when nothing actionable remains
    • skip

      public void skip(int lineIndex, WithdrawPlan.Skip reason)
      Retires a line that cannot be fulfilled. Out-of-range indices are ignored.
    • markSatisfied

      public void markSatisfied(int lineIndex)
      Retires an all line as done. Out-of-range indices are ignored.
    • isComplete

      public boolean isComplete(ToIntFunction<String> inventoryCount)
      True only when every line reached its target — numerically, or marked done for an all-line.
    • shortfallReport

      public String shortfallReport(ToIntFunction<String> inventoryCount)
      Human-readable summary of every line that fell short, e.g. "Shark 3/10 (INVENTORY_FULL); Coal 0/5 (NOT_IN_BANK)".
      Returns:
      empty string when all lines are satisfied