Use a switch expression to dispatch keys 62/104162/1
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 14 Feb 2023 09:15:40 +0000 (10:15 +0100)
committerRobert Varga <nite@hq.sk>
Tue, 14 Feb 2023 18:20:06 +0000 (18:20 +0000)
This makes the code flow more obvious.

Change-Id: I112da7aa2d1950e45bad8bac3e87126c47300f86
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 0ca412d7387be08bc904fc5f2cc96c9f2001204f)

aaa-encrypt-service/api/src/main/java/org/opendaylight/aaa/encrypt/PKIUtil.java

index 282cb4ee752bfb47debc0db1594f76346180b036..97c5b067a87c377b49664487c1a02330904bac59 100644 (file)
@@ -104,19 +104,12 @@ public class PKIUtil {
         pos = 0;
 
         String type = decodeType();
-        if (type.equals(KEY_TYPE_RSA)) {
-            return decodeAsRSA();
-        }
-
-        if (type.equals(KEY_TYPE_DSA)) {
-            return decodeAsDSA();
-        }
-
-        if (type.equals(KEY_TYPE_ECDSA)) {
-            return decodeAsECDSA();
-        }
-
-        throw new IllegalArgumentException("Unknown decode key type " + type + " in " + keyLine);
+        return switch (type) {
+            case KEY_TYPE_RSA -> decodeAsRSA();
+            case KEY_TYPE_DSA -> decodeAsDSA();
+            case KEY_TYPE_ECDSA -> decodeAsECDSA();
+            default -> throw new IllegalArgumentException("Unknown decode key type " + type + " in " + keyLine);
+        };
     }
 
     @SuppressWarnings("AbbreviationAsWordInName")