aboutsummaryrefslogtreecommitdiff
path: root/src/esieequest/model/items/Inventory.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/esieequest/model/items/Inventory.java')
-rw-r--r--src/esieequest/model/items/Inventory.java125
1 files changed, 0 insertions, 125 deletions
diff --git a/src/esieequest/model/items/Inventory.java b/src/esieequest/model/items/Inventory.java
deleted file mode 100644
index 6091872..0000000
--- a/src/esieequest/model/items/Inventory.java
+++ /dev/null
@@ -1,125 +0,0 @@
1package esieequest.model.items;
2
3import java.util.HashMap;
4import java.util.Set;
5
6import esieequest.controller.Utils;
7
8/**
9 * An inventory containing Items referred by their names.
10 *
11 * @author Pacien TRAN-GIRARD
12 */
13public class Inventory {
14
15 private final HashMap<String, Item> items;
16
17 public Inventory() {
18 this.items = new HashMap<String, Item>();
19 }
20
21 /**
22 * Returns an item from the inventory, without removing it.
23 *
24 * @param itemName
25 * the item's name
26 *
27 * @return the item
28 */
29 public Item getItem(final String itemName) {
30 return this.items.get(itemName);
31 }
32
33 /**
34 * Takes (returns and removes) an item from the inventory.
35 *
36 * @param itemName
37 * the item's name
38 *
39 * @return the item
40 */
41 public Item takeItem(final String itemName) {
42 final Item item = this.items.get(itemName);
43 this.items.remove(itemName);
44 return item;
45 }
46
47 /**
48 * Tells if the inventory contains a given item by its name.
49 *
50 * @param itemName
51 * the item's name
52 *
53 * @return the existence of the item
54 */
55 public boolean containsItem(final String itemName) {
56 return this.items.get(itemName) != null;
57 }
58
59 /**
60 * Tells if the inventory contains a given item.
61 *
62 * @param item
63 * the item
64 *
65 * @return the existence of the item
66 */
67 public boolean containsItem(final Item item) {
68 return this.items.containsValue(item);
69 }
70
71 /**
72 * Puts an item in the inventory.
73 *
74 * @param itemName
75 * the item's name
76 * @param item
77 * the item
78 */
79 public void putItem(final String itemName, final Item item) {
80 this.items.put(itemName, item);
81 }
82
83 /**
84 * Returns a set of item names contained in the inventory.
85 *
86 * @return a set of item names
87 */
88 public Set<String> getItemList() {
89 return this.items.keySet();
90 }
91
92 /**
93 * Lists all items names contained in the inventory in a String.
94 *
95 * @return the list of items
96 */
97 public String listItems() {
98 return Utils.list(this.items.keySet(), "Items:", "No items here.");
99 }
100
101 /**
102 * Returns the weight of the given item referred by its name.
103 *
104 * @param itemName
105 * the item's name
106 * @return the weight of the item
107 */
108 public int getItemWeight(final String itemName) {
109 return this.items.get(itemName).getWeight();
110 }
111
112 /**
113 * Returns the sum of the weight of all the items.
114 *
115 * @return the total weight
116 */
117 public int getTotalWeight() {
118 int totalWeight = 0;
119 for (final Item item : this.items.values()) {
120 totalWeight += item.getWeight();
121 }
122 return totalWeight;
123 }
124
125}