|
@@ -5,62 +5,118 @@ public class Inventory {
|
5
|
5
|
private Item[] items;
|
6
|
6
|
|
7
|
7
|
public Inventory(Item[] items) {
|
8
|
|
- super();
|
9
|
8
|
this.items = items;
|
10
|
9
|
}
|
11
|
10
|
|
12
|
|
-
|
13
|
11
|
public void updateQuality() {
|
14
|
|
- for (int i = 0; i < items.length; i++) {
|
15
|
|
- if (!items[i].getName().equals("Aged Brie")
|
16
|
|
- && !items[i].getName().equals("Backstage passes to a TAFKAL80ETC concert")) {
|
17
|
|
- if (items[i].getQuality() > 0) {
|
18
|
|
- if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
|
19
|
|
- items[i].setQuality(items[i].getQuality() - 1);
|
20
|
|
- }
|
21
|
|
- }
|
22
|
|
- } else {
|
23
|
|
- if (items[i].getQuality() < 50) {
|
24
|
|
- items[i].setQuality(items[i].getQuality() + 1);
|
25
|
|
-
|
26
|
|
- if (items[i].getName() == "Backstage passes to a TAFKAL80ETC concert") {
|
27
|
|
- if (items[i].getSellIn() < 11) {
|
28
|
|
- if (items[i].getQuality() < 50) {
|
29
|
|
- items[i].setQuality(items[i].getQuality() + 1);
|
30
|
|
- }
|
31
|
|
- }
|
32
|
|
-
|
33
|
|
- if (items[i].getSellIn() < 6) {
|
34
|
|
- if (items[i].getQuality() < 50) {
|
35
|
|
- items[i].setQuality(items[i].getQuality() + 1);
|
36
|
|
- }
|
37
|
|
- }
|
38
|
|
- }
|
39
|
|
- }
|
|
12
|
+ for (Item item : items) {
|
|
13
|
+ ItemCategory category = categorize(item);
|
|
14
|
+ category.updateOneItem(item, this);
|
|
15
|
+ }
|
|
16
|
+ }
|
|
17
|
+
|
|
18
|
+ private ItemCategory categorize(Item item) {
|
|
19
|
+ if (item.getName().equals("Sulfuras, Hand of Ragnaros"))
|
|
20
|
+ return new Legendary();
|
|
21
|
+ if (item.getName().equals("Aged Brie"))
|
|
22
|
+ return new Cheese();
|
|
23
|
+ if (item.getName().equals("Backstage passes to a TAFKAL80ETC concert"))
|
|
24
|
+ return new BackstagePass();
|
|
25
|
+ if(item.getName().startsWith("Conjured"))
|
|
26
|
+ return new Conjured();
|
|
27
|
+ return new ItemCategory();
|
|
28
|
+ }
|
|
29
|
+
|
|
30
|
+ private boolean hasExpired(Item item) {
|
|
31
|
+ return item.getSellIn() < 0;
|
|
32
|
+ }
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+ private class ItemCategory {
|
|
36
|
+ protected void incrementQuality(Item item) {
|
|
37
|
+ if (item.getQuality() < 50) {
|
|
38
|
+ item.setQuality(item.getQuality() + 1);
|
|
39
|
+ }
|
|
40
|
+ }
|
|
41
|
+
|
|
42
|
+ protected void decrementQuality(Item item) {
|
|
43
|
+ if (item.getQuality() > 0) {
|
|
44
|
+ item.setQuality(item.getQuality() - 1);
|
|
45
|
+ }
|
|
46
|
+ }
|
|
47
|
+
|
|
48
|
+ protected void updateExpired(Item item) {
|
|
49
|
+ decrementQuality(item);
|
|
50
|
+ }
|
|
51
|
+
|
|
52
|
+ protected void updateSellIn(Item item) {
|
|
53
|
+ item.setSellIn(item.getSellIn() - 1);
|
|
54
|
+
|
|
55
|
+ }
|
|
56
|
+
|
|
57
|
+ protected void updateQuality(Item item) {
|
|
58
|
+ decrementQuality(item);
|
|
59
|
+ }
|
|
60
|
+
|
|
61
|
+ protected void updateOneItem(Item item, Inventory inventory) {
|
|
62
|
+ updateQuality(item);
|
|
63
|
+
|
|
64
|
+ updateSellIn(item);
|
|
65
|
+
|
|
66
|
+ if (inventory.hasExpired(item)) {
|
|
67
|
+ updateExpired(item);
|
40
|
68
|
}
|
|
69
|
+ }
|
|
70
|
+ }
|
|
71
|
+
|
|
72
|
+ private class Legendary extends ItemCategory {
|
|
73
|
+ protected void updateExpired(Item item) {}
|
|
74
|
+
|
|
75
|
+ protected void updateSellIn(Item item) {}
|
|
76
|
+
|
|
77
|
+ protected void updateQuality(Item item) {}
|
|
78
|
+ }
|
|
79
|
+
|
|
80
|
+ private class Cheese extends ItemCategory {
|
|
81
|
+ protected void updateExpired(Item item) {
|
|
82
|
+ incrementQuality(item);
|
|
83
|
+ }
|
41
|
84
|
|
42
|
|
- if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
|
43
|
|
- items[i].setSellIn(items[i].getSellIn() - 1);
|
|
85
|
+ protected void updateQuality(Item item) {
|
|
86
|
+ incrementQuality(item);
|
|
87
|
+
|
|
88
|
+ }
|
|
89
|
+ }
|
|
90
|
+
|
|
91
|
+ private class BackstagePass extends ItemCategory {
|
|
92
|
+ protected void updateExpired(Item item) {
|
|
93
|
+ item.setQuality(0);
|
|
94
|
+ }
|
|
95
|
+
|
|
96
|
+ protected void updateQuality(Item item) {
|
|
97
|
+ incrementQuality(item);
|
|
98
|
+
|
|
99
|
+ if (item.getSellIn() < 11) {
|
|
100
|
+ incrementQuality(item);
|
44
|
101
|
}
|
45
|
102
|
|
46
|
|
- if (items[i].getSellIn() < 0) {
|
47
|
|
- if (!items[i].getName().equals("Aged Brie")) {
|
48
|
|
- if (!items[i].getName().equals("Backstage passes to a TAFKAL80ETC concert")) {
|
49
|
|
- if (items[i].getQuality() > 0) {
|
50
|
|
- if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
|
51
|
|
- items[i].setQuality(items[i].getQuality() - 1);
|
52
|
|
- }
|
53
|
|
- }
|
54
|
|
- } else {
|
55
|
|
- items[i].setQuality(items[i].getQuality()
|
56
|
|
- - items[i].getQuality());
|
57
|
|
- }
|
58
|
|
- } else {
|
59
|
|
- if (items[i].getQuality() < 50) {
|
60
|
|
- items[i].setQuality(items[i].getQuality() + 1);
|
61
|
|
- }
|
62
|
|
- }
|
|
103
|
+ if (item.getSellIn() < 6) {
|
|
104
|
+ incrementQuality(item);
|
63
|
105
|
}
|
|
106
|
+
|
64
|
107
|
}
|
65
|
108
|
}
|
|
109
|
+
|
|
110
|
+ private class Conjured extends ItemCategory {
|
|
111
|
+ protected void updateExpired(Item item) {
|
|
112
|
+ decrementQuality(item);
|
|
113
|
+ decrementQuality(item);
|
|
114
|
+ }
|
|
115
|
+
|
|
116
|
+ protected void updateQuality(Item item) {
|
|
117
|
+ decrementQuality(item);
|
|
118
|
+ decrementQuality(item);
|
|
119
|
+ }
|
|
120
|
+
|
|
121
|
+ }
|
66
|
122
|
}
|