File tree 1 file changed +13
-15
lines changed
src/test/java/com/macasaet 1 file changed +13
-15
lines changed Original file line number Diff line number Diff line change @@ -83,18 +83,19 @@ public Shape beats() {
83
83
};
84
84
85
85
public static Shape forChar (final int c ) {
86
- switch (c ) {
86
+ return switch (c ) {
87
87
case 'X' :
88
88
case 'A' :
89
- return Shape .Rock ;
89
+ yield Shape .Rock ;
90
90
case 'Y' :
91
91
case 'B' :
92
- return Shape .Paper ;
92
+ yield Shape .Paper ;
93
93
case 'Z' :
94
94
case 'C' :
95
- return Shape .Scissors ;
96
- }
97
- throw new IllegalArgumentException ();
95
+ yield Shape .Scissors ;
96
+ default :
97
+ throw new IllegalArgumentException ("Invalid shape: " + c );
98
+ };
98
99
}
99
100
100
101
/**
@@ -134,15 +135,12 @@ public Shape respond(Shape opponent) {
134
135
};
135
136
136
137
public static ResponseStrategy forChar (final char c ) {
137
- switch (c ) {
138
- case 'X' :
139
- return Lose ;
140
- case 'Y' :
141
- return Draw ;
142
- case 'Z' :
143
- return Win ;
144
- }
145
- throw new IllegalArgumentException ();
138
+ return switch (c ) {
139
+ case 'X' -> Lose ;
140
+ case 'Y' -> Draw ;
141
+ case 'Z' -> Win ;
142
+ default -> throw new IllegalArgumentException ("Invalid strategy: " + c );
143
+ };
146
144
}
147
145
148
146
public abstract Shape respond (final Shape opponent );
You can’t perform that action at this time.
0 commit comments