-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameInventoryKernel.java
More file actions
90 lines (83 loc) · 2.95 KB
/
Copy pathGameInventoryKernel.java
File metadata and controls
90 lines (83 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package components.gameinventory;
import components.standard.Standard;
/**
* {@code GameInventoryKernel} kernel interface for the {@code GameInventory}
* component type.
*
* <p>
* A {@code GameInventory} models a finite collection of named items, each
* associated with a positive integer quantity. An item is considered present in
* the inventory only when its quantity is greater than zero.
* </p>
*
* @mathmodel type GameInventory is modeled by
* finite partial function (String -> int)
* where for every key k in domain(this), this[k] > 0
* @initially |this| = 0
*
* @iterator provides a {@code String} iterator over the names of all items
* currently in this inventory in no particular order; each item name
* appears exactly once
*/
public interface GameInventoryKernel
extends Standard<GameInventory>, Iterable<String> {
/**
* Adds {@code quantity} of {@code item} to {@code this}.
*
* <p>
* If {@code item} is already present, its existing quantity is increased by
* {@code quantity}. Otherwise, {@code item} is added as a new entry with
* the given quantity.
* </p>
*
* @param item
* the name of the item to add
* @param quantity
* the number of {@code item} to add
* @updates this
* @requires |item| > 0 and quantity > 0
* @ensures this[item] = #this[item] + quantity
* and for all k /= item in domain(#this), this[k] = #this[k]
*/
void addItem(String item, int quantity);
/**
* Removes {@code quantity} of {@code item} from {@code this}.
*
* <p>
* If removing exactly {@code quantity} reduces the item's total to zero,
* the entry is removed entirely from the inventory.
* </p>
*
* @param item
* the name of the item to remove
* @param quantity
* the number of {@code item} to remove
* @updates this
* @requires |item| > 0 and quantity > 0 and quantity <= this[item]
* @ensures if #this[item] = quantity then item is not in domain(this)
* else this[item] = #this[item] - quantity
* and for all k /= item in domain(#this), this[k] = #this[k]
*/
void removeItem(String item, int quantity);
/**
* Reports the quantity of {@code item} in {@code this}.
*
* @param item
* the name of the item to look up
* @return the quantity of {@code item} in {@code this}, or 0 if
* {@code item} is not present
* @restores this
* @requires |item| > 0
* @ensures getQuantity =
* (item is in domain(this) ? this[item] : 0)
*/
int getQuantity(String item);
/**
* Reports the number of distinct item types in {@code this}.
*
* @return the number of distinct item names currently in {@code this}
* @restores this
* @ensures size = |domain(this)|
*/
int size();
}