Class BuyPlan

java.lang.Object
privbot.hooks.shop.BuyPlan

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

Quantities are a top-up target: a line is satisfied when the inventory holds at least quantity of the item, regardless of how many clicks were dispatched. Progress is therefore always measured against a live inventory count, which makes the plan self-correcting when a click is dropped and idempotent when the action is re-run inside a rule loop.

A line may also be skipped when it cannot be fulfilled (not stocked, out of stock, purchase refused). Skipping retires the line from the work queue but does not mark it satisfied — isComplete(java.util.function.ToIntFunction<java.lang.String>) still reports false, so partial success is never silently swallowed.

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

  • Constructor Details

  • Method Details

    • parseLines

      public static List<BuyPlan.Line> parseLines(String text)
      Parses a free-form item list into buy lines.

      Delegates to ItemLines.parse(java.lang.String) — the same text means the same thing whether the items are being bought or withdrawn, so there is one parser. Kept here as the shop's entry point so existing callers and tests are unaffected.

      Returns:
      never null; blank entries are dropped
    • lines

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

      public static int remaining(BuyPlan.Line line, int have)
      Units still needed to reach the line's target. Never negative.
    • 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, BuyPlan.Skip reason)
      Retires a line that cannot be fulfilled. Out-of-range indices are ignored.
    • isComplete

      public boolean isComplete(ToIntFunction<String> inventoryCount)
      True only when every line's inventory target is met, skipped or not.
    • shortfallReport

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