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