Package games.stendhal.server.util
Class ItemCollection
- All Implemented Interfaces:
Serializable
,Cloneable
,Map<String,Integer>
,NavigableMap<String,Integer>
,SortedMap<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
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object>
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Construct an ItemCollection from a quest state string in the form "item1=n1;item2=n2;...".void
addFromQuestStateString(String str, int position)
Construct an ItemCollection from a quest state string in the form "item1=n1;item2=n2;...".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,...".void
addFromString(String str)
Adds a list of items from a comma separated string.void
Add the specified amount of items to the collection.boolean
removeItem(String itemName, int amount)
Remove the specified amount of items from the collection.Return the items as quest state string.toStringForQuestState(boolean commaString)
Methods inherited from class java.util.TreeMap
ceilingEntry, ceilingKey, clear, clone, comparator, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, descendingKeySet, descendingMap, entrySet, firstEntry, firstKey, floorEntry, floorKey, forEach, get, headMap, headMap, higherEntry, higherKey, keySet, lastEntry, lastKey, lowerEntry, lowerKey, merge, navigableKeySet, pollFirstEntry, pollLastEntry, put, putAll, putIfAbsent, remove, replace, replace, replaceAll, size, subMap, subMap, tailMap, tailMap, values
Methods inherited from class java.util.AbstractMap
equals, hashCode, isEmpty, toString
-
Constructor Details
-
ItemCollection
public ItemCollection()
-
-
Method Details
-
addFromQuestStateString
Construct an ItemCollection from a quest state string in the form "item1=n1;item2=n2;...".- Parameters:
str
- Quest state string.
-
addFromQuestStateString
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
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
- Iftrue
, string will be parsed using "," instead of ";".
-
addFromString
Adds a list of items from a comma separated string.- Parameters:
str
- Comma-separate string to parse.
-
toStringForQuestState
Return the items as quest state string.- Returns:
- semicolon separated states list
-
toStringForQuestState
-
removeItem
Remove the specified amount of items from the collection.- Parameters:
itemName
-amount
-- Returns:
- true if amount has been updated
-
addItem
Add the specified amount of items to the collection.- Parameters:
itemName
-amount
-
-
toStringList
- Returns:
- a String list containing the items in the format "n item".
-
toStringListWithHash
- Returns:
- a String list containing the items in the format "n #item, ...".
-