|
@@ -7,27 +7,37 @@ import java.util.*;
|
7
|
7
|
/**
|
8
|
8
|
* @author leon on 27/12/2018.
|
9
|
9
|
*/
|
10
|
|
-public class Food {
|
|
10
|
+public class Food {
|
|
11
|
+
|
|
12
|
+ public Food(){
|
|
13
|
+
|
|
14
|
+ }
|
|
15
|
+
|
|
16
|
+ ArrayList<Spice> spices= new ArrayList<>();
|
11
|
17
|
|
12
|
|
- Map<Spice, Integer> spiceCount = new LinkedHashMap<>();
|
13
|
18
|
|
14
|
19
|
public List<Spice> getAllSpices() {
|
15
|
|
- Set<Spice> spicekeys = spiceCount.keySet();
|
16
|
|
- List<Spice> result = new ArrayList<>();
|
17
|
|
- result.addAll(spicekeys);
|
18
|
|
- return result;
|
|
20
|
+ return spices;
|
19
|
21
|
}
|
20
|
22
|
|
|
23
|
+
|
21
|
24
|
public <SpiceType extends Class<? extends Spice>> Map<SpiceType, Integer> getSpiceCount() {
|
22
|
|
-
|
|
25
|
+ LinkedHashMap<SpiceType, Integer> spiceCount = new LinkedHashMap<>();
|
|
26
|
+ for (Spice s : spices) {
|
|
27
|
+ spiceCount.put((SpiceType) s.getClass(), s.getSpiciness());
|
|
28
|
+ }
|
|
29
|
+ for (Spice s : spices) {
|
|
30
|
+ s.setSpiciness(0);
|
|
31
|
+ }
|
|
32
|
+ return spiceCount;
|
23
|
33
|
}
|
24
|
34
|
|
|
35
|
+
|
|
36
|
+
|
25
|
37
|
public void applySpice(Spice spice) {
|
26
|
|
- if(spiceCount.containsKey(spice)) {
|
27
|
|
- spiceCount.replace(spice, spiceCount.get(spice) + 1);
|
28
|
|
- } else {
|
29
|
|
- spiceCount.put(spice, 1);
|
|
38
|
+ if(!spices.contains(spice)){
|
|
39
|
+ spices.add(spice);
|
30
|
40
|
}
|
31
|
|
-
|
|
41
|
+ spice.setSpiciness(spice.getSpiciness()+1);
|
32
|
42
|
}
|
33
|
43
|
}
|