Clean up ApiPathParser.URL_FACTORY 25/106825/1
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 5 Jul 2023 20:33:53 +0000 (22:33 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 5 Jul 2023 20:42:20 +0000 (22:42 +0200)
Use a switch expression and guarantee a @NonNull result.

Change-Id: I8a53c1b358f739aa8f4efeb9d36641a3039145cc
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
protocol/restconf-api/src/main/java/org/opendaylight/restconf/api/ApiPathParser.java

index ce6f68aad4b5016ab52f43c3a95b10a855eedcf5..0f6d0496954af8e2705d8e819ddd2c3ea67afb4a 100644 (file)
@@ -66,35 +66,36 @@ class ApiPathParser {
         }
     }
 
-    private static final Supplier<org.opendaylight.restconf.api.ApiPathParser> URL_FACTORY;
+    private static final Supplier<@NonNull ApiPathParser> URL_FACTORY;
 
     static {
         // Select the correct parser implementation where consecutive slashes are concerned. We default to lenient
         // interpretation and treat them as a single slash, but allow this to be overridden through a system property.
         final String prop = System.getProperty("org.opendaylight.restconf.url.consecutive-slashes", "reject");
         final String treatment;
-        switch (prop) {
-            case "allow":
+        URL_FACTORY = switch (prop) {
+            case "allow" -> {
                 treatment = "are treated as a single slash";
-                URL_FACTORY = Lenient::new;
-                break;
-            case "debug":
+                yield Lenient::new;
+            }
+            case "debug" -> {
                 treatment = "are treated as a single slash and will be logged";
-                URL_FACTORY = () -> new Logging(LOG::debug);
-                break;
-            case "warn":
+                yield () -> new Logging(LOG::debug);
+            }
+            case "warn" -> {
                 treatment = "are treated as a single slash and will be warned about";
-                URL_FACTORY = () -> new Logging(LOG::warn);
-                break;
-            case "reject":
+                yield () -> new Logging(LOG::warn);
+            }
+            case "reject" -> {
                 treatment = "will be rejected";
-                URL_FACTORY = ApiPathParser::new;
-                break;
-            default:
+                yield ApiPathParser::new;
+            }
+            default -> {
                 LOG.warn("Unknown property value '{}', assuming 'reject'", prop);
                 treatment = "will be rejected";
-                URL_FACTORY = ApiPathParser::new;
-        }
+                yield ApiPathParser::new;
+            }
+        };
 
         LOG.info("Consecutive slashes in REST URLs {}", treatment);
     }