|
@@ -9,25 +9,29 @@ import java.util.*;
|
9
|
9
|
*/
|
10
|
10
|
public class Food {
|
11
|
11
|
|
12
|
|
- private Map<Spice, Integer> spices;
|
|
12
|
+ private List<Spice> spiceList;
|
|
13
|
+ private Map<Class<? extends Spice>, Integer> spices;
|
13
|
14
|
|
14
|
15
|
public Food() {
|
15
|
|
- this.spices = new TreeMap<>();
|
|
16
|
+ this.spiceList = new ArrayList<>();
|
|
17
|
+ this.spices = new LinkedHashMap<>();
|
16
|
18
|
}
|
17
|
19
|
|
18
|
20
|
public List<Spice> getAllSpices() {
|
19
|
|
- return new ArrayList<>(spices.keySet());
|
|
21
|
+ return spiceList;
|
20
|
22
|
}
|
21
|
23
|
|
22
|
|
- public <SpiceType extends Class<? extends Spice>> Map<SpiceType, Integer> getSpiceCount() {
|
23
|
|
- return null;
|
|
24
|
+ public Map<Class<? extends Spice>, Integer> getSpiceCount() {
|
|
25
|
+ return spices;
|
24
|
26
|
}
|
25
|
27
|
|
26
|
28
|
public void applySpice(Spice spice) {
|
27
|
|
- if (!spices.containsKey(spice)) {
|
28
|
|
- spices.put(spice, 1);
|
|
29
|
+ spiceList.add(spice);
|
|
30
|
+
|
|
31
|
+ if (!spices.containsKey(spice.getClass())) {
|
|
32
|
+ spices.put(spice.getClass(), 1);
|
29
|
33
|
} else {
|
30
|
|
- spices.put(spice, spices.get(spice) + 1);
|
|
34
|
+ spices.put(spice.getClass(), spices.get(spice.getClass()) + 1);
|
31
|
35
|
}
|
32
|
36
|
}
|
33
|
37
|
|