1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.surefire.api.booter;
20
21 import java.util.Objects;
22
23 import static java.util.Objects.requireNonNull;
24 import static org.apache.maven.surefire.shared.utils.StringUtils.isBlank;
25
26
27
28
29
30
31
32 public final class Command {
33 public static final Command TEST_SET_FINISHED = new Command(MasterProcessCommand.TEST_SET_FINISHED);
34 public static final Command SKIP_SINCE_NEXT_TEST = new Command(MasterProcessCommand.SKIP_SINCE_NEXT_TEST);
35 public static final Command NOOP = new Command(MasterProcessCommand.NOOP);
36 public static final Command BYE_ACK = new Command(MasterProcessCommand.BYE_ACK);
37
38 private final MasterProcessCommand command;
39 private final String data;
40
41 public Command(MasterProcessCommand command, String data) {
42 this.command = requireNonNull(command);
43 this.data = data;
44 }
45
46 public Command(MasterProcessCommand command) {
47 this(command, null);
48 }
49
50 public static Command toShutdown(Shutdown shutdownType) {
51 return new Command(MasterProcessCommand.SHUTDOWN, shutdownType.name());
52 }
53
54 public static Command toRunClass(String runClass) {
55 return new Command(MasterProcessCommand.RUN_CLASS, runClass);
56 }
57
58 public MasterProcessCommand getCommandType() {
59 return command;
60 }
61
62 public String getData() {
63 return data;
64 }
65
66
67
68
69
70 public Shutdown toShutdownData() {
71 if (command != MasterProcessCommand.SHUTDOWN) {
72 throw new IllegalStateException("expected MasterProcessCommand.SHUTDOWN");
73 }
74 return isBlank(data) ? Shutdown.DEFAULT : Shutdown.valueOf(data);
75 }
76
77 @Override
78 public boolean equals(Object o) {
79 if (this == o) {
80 return true;
81 }
82
83 if (o == null || getClass() != o.getClass()) {
84 return false;
85 }
86
87 Command arg = (Command) o;
88
89 return command == arg.command && Objects.equals(data, arg.data);
90 }
91
92 @Override
93 public int hashCode() {
94 int result = command.hashCode();
95 result = 31 * result + (data != null ? data.hashCode() : 0);
96 return result;
97 }
98 }