| 10 | import java.util.stream.*; |
| 11 | |
| 12 | enum Category { |
| 13 | MONEY(Input.NICKEL, Input.DIME, |
| 14 | Input.QUARTER, Input.DOLLAR), |
| 15 | ITEM_SELECTION(Input.TOOTHPASTE, Input.CHIPS, |
| 16 | Input.SODA, Input.SOAP), |
| 17 | QUIT_TRANSACTION(Input.ABORT_TRANSACTION), |
| 18 | SHUT_DOWN(Input.STOP); |
| 19 | private Input[] values; |
| 20 | Category(Input... types) { values = types; } |
| 21 | private static EnumMap<Input,Category> categories = |
| 22 | new EnumMap<>(Input.class); |
| 23 | static { |
| 24 | for(Category c : Category.class.getEnumConstants()) |
| 25 | for(Input type : c.values) |
| 26 | categories.put(type, c); |
| 27 | } |
| 28 | public static Category categorize(Input input) { |
| 29 | return categories.get(input); |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | public class VendingMachine { |
| 34 | private static State state = State.RESTING; |