MCPcopy Index your code
hub / github.com/BruceEckel/OnJava8-Examples / Category

Enum Category

enums/VendingMachine.java:12–31  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10import java.util.stream.*;
11
12enum 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
33public class VendingMachine {
34 private static State state = State.RESTING;

Callers

nothing calls this directly

Calls 1

putMethod · 0.45

Tested by

no test coverage detected