Use switch expression for EventFormatterFactory selection 09/103109/1
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 6 Nov 2022 18:45:58 +0000 (19:45 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Sun, 6 Nov 2022 18:45:58 +0000 (19:45 +0100)
Useing a switch expression removes the unhandled case, promoting to a
compile-time error if things do not match up.

Change-Id: I8688e4bc76419194cb0d910105ff0733cd6d118f
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/ListenerAdapter.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/NotificationListenerAdapter.java

index b438f36b0223c50b501916933b8b4a412c40d7c3..4177ca19a67318316a9a49aa9265c4971dba5d3d 100644 (file)
@@ -48,14 +48,10 @@ public class ListenerAdapter extends AbstractCommonSubscriber<YangInstanceIdenti
     }
 
     private static DataTreeCandidateFormatterFactory getFormatterFactory(final NotificationOutputType outputType) {
-        switch (outputType) {
-            case JSON:
-                return JSON_FORMATTER_FACTORY;
-            case XML:
-                return XMLDataTreeCandidateFormatter.FACTORY;
-            default:
-                throw new IllegalArgumentException("Unsupported outputType" + outputType);
-        }
+        return switch (outputType) {
+            case JSON -> JSON_FORMATTER_FACTORY;
+            case XML -> XMLDataTreeCandidateFormatter.FACTORY;
+        };
     }
 
     @Override
index 5f43481862a82f478b325cb7e6802cca4a2ab2bb..120ac8d78ebad10de0a78d7a2416cb93f30b41f1 100644 (file)
@@ -40,14 +40,10 @@ public final class NotificationListenerAdapter extends AbstractCommonSubscriber<
     }
 
     private static NotificationFormatterFactory getFormatterFactory(final NotificationOutputType outputType) {
-        switch (outputType) {
-            case JSON:
-                return JSON_FORMATTER_FACTORY;
-            case XML:
-                return XMLNotificationFormatter.FACTORY;
-            default:
-                throw new IllegalArgumentException("Unsupported outputType " + outputType);
-        }
+        return switch (outputType) {
+            case JSON -> JSON_FORMATTER_FACTORY;
+            case XML -> XMLNotificationFormatter.FACTORY;
+        };
     }
 
     @Override