Class ItemCollection

java.lang.Object
java.util.AbstractMap<K,​V>
java.util.TreeMap<String,​Integer>
games.stendhal.server.util.ItemCollection
All Implemented Interfaces:
Serializable, Cloneable, Map<String,​Integer>, NavigableMap<String,​Integer>, SortedMap<String,​Integer>

public class ItemCollection extends TreeMap<String,​Integer>
ItemCollection is a collection of items with associated amount. It can be constructed from a semicolon-separated quest state string. Item names and amounts are separated by equal signs, so the format is: item1=5;item2=1;C=3;D=1
Author:
Martin Fuchs
See Also:
Serialized Form
  • Constructor Details

    • ItemCollection

      public ItemCollection()
  • Method Details

    • addFromQuestStateString

      public void addFromQuestStateString(String str)
      Construct an ItemCollection from a quest state string in the form "item1=n1;item2=n2;...".
      Parameters:
      str - Quest state string.
    • addFromQuestStateString

      public void addFromQuestStateString(String str, int position)
      Construct an ItemCollection from a quest state string in the form "item1=n1;item2=n2;...".
      Parameters:
      str - Quest state string.
      position - Index of item list in quest state string.
    • addFromQuestStateString

      public void addFromQuestStateString(String str, int position, boolean invert)
      Construct an ItemCollection from a quest state string in the form "item1=n1;item2=n2;..." or "item1=n1,item2=n2,...".
      Parameters:
      str - Quest state string.
      position - Index of item list in quest state string.
      invert - If true, string will be parsed using "," instead of ";".
    • addFromString

      public void addFromString(String str)
      Adds a list of items from a comma separated string.
      Parameters:
      str - Comma-separate string to parse.
    • toStringForQuestState

      public String toStringForQuestState()
      Return the items as quest state string.
      Returns:
      semicolon separated states list
    • toStringForQuestState

      public String toStringForQuestState(boolean commaString)
    • removeItem

      public boolean removeItem(String itemName, int amount)
      Remove the specified amount of items from the collection.
      Parameters:
      itemName -
      amount -
      Returns:
      true if amount has been updated
    • addItem

      public void addItem(String itemName, int amount)
      Add the specified amount of items to the collection.
      Parameters:
      itemName -
      amount -
    • toStringList

      public List<String> toStringList()
      Returns:
      a String list containing the items in the format "n item".
    • toStringListWithHash

      public List<String> toStringListWithHash()
      Returns:
      a String list containing the items in the format "n #item, ...".