Class ItemLines

java.lang.Object
privbot.hooks.container.ItemLines

public final class ItemLines extends Object
A list of (item, quantity) pairs, and the parser that reads one from user text.

Extracted from BuyPlan once withdrawing needed the same thing. Both a shop purchase and a bank withdrawal are "get me N of each of these", and the awkward part — deciding where the name ends and the quantity begins — is worth having exactly one tested copy of.

  • Method Details

    • parse

      public static List<ItemLines.Line> parse(String text)
      Parses a free-form item list. Entries are separated by newlines or commas; a missing quantity defaults to 1.

      A quantity is a run of digits marked with an x, on either side of the name and either way round: Shark x10, Shark 10x, 10x Shark. The x may be capital and may have spaces around it.

      Only Name x10 used to be understood. Larupia fur 20x left nothing after the final x, so no quantity was split off and the whole entry became the item name; the shop sold nothing called that, every attempt ended NOT_SOLD_HERE, and a buy flow retried it for minutes next to a shop that sold Larupia fur to a hand click. Every form someone would naturally type is read now, and anything else still falls back to "the whole entry is the name".

      Names are protected by requiring the digits and the x to stand together as their own token: Rune axe, Box trap and 3rd age amulet stay whole.

      Returns:
      never null; blank entries are dropped
    • remaining

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