Skip to content

Commit 062b98a

Browse files
cheng102ejiejc1sureshanaparti
authored
fix: clean magic value, and update if-else to switch (#8848)
* fix: clean magic value, and update if-else to switch * fix: return the (String args[]) * review --------- Co-authored-by: jiejc1 <jiejc1@lenovo.com> Co-authored-by: Suresh Kumar Anaparti <sureshkumar.anaparti@gmail.com>
1 parent 75db42b commit 062b98a

File tree

1 file changed

+20
-14
lines changed
  • services/console-proxy/rdpconsole/src/main/java/common

1 file changed

+20
-14
lines changed

services/console-proxy/rdpconsole/src/main/java/common/Client.java

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ private void help() {
210210
public void runClient(String[] args) {
211211

212212
try {
213-
214213
Protocol protocol = parseOptions(args);
215214
if (protocol == Protocol.NONE)
216215
return;
@@ -299,21 +298,28 @@ private Element setMainElementAndAddressBasedOnProtocol(Protocol protocol, SSLSt
299298

300299
private Protocol parseOptions(String[] args) {
301300
String protocolName = (args.length > 0) ? args[0] : "";
302-
Protocol protocol = Protocol.NONE;
301+
Protocol protocol;
303302

304303
Option[] options;
305-
if (protocolName.equals("vnc")) {
306-
protocol = Protocol.VNC;
307-
options = join(commonOptions, vncOptions);
308-
} else if (protocolName.equals("rdp")) {
309-
protocol = Protocol.RDP;
310-
options = join(commonOptions, rdpOptions);
311-
} else if (protocolName.equals("hyperv")) {
312-
protocol = Protocol.HYPERV;
313-
options = join(commonOptions, hyperVOptions);
314-
} else {
315-
help();
316-
return Protocol.NONE;
304+
try {
305+
protocol = Protocol.valueOf(protocolName);
306+
} catch (IllegalArgumentException e) {
307+
protocol = Protocol.NONE;
308+
}
309+
310+
switch (protocol) {
311+
case VNC:
312+
options = join(commonOptions, vncOptions);
313+
break;
314+
case RDP:
315+
options = join(commonOptions, rdpOptions);
316+
break;
317+
case HYPERV:
318+
options = join(commonOptions, hyperVOptions);
319+
break;
320+
default:
321+
help();
322+
return Protocol.NONE;
317323
}
318324

319325
// Parse all options for given protocol

0 commit comments

Comments
 (0)