Use switch expression in FramingMechanismHandlerFactory 20/101920/2
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 29 Jul 2022 16:10:55 +0000 (18:10 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 29 Jul 2022 16:43:45 +0000 (18:43 +0200)
Switch expressions are exhaustive, which is exactly what we want to
do here.

Change-Id: I32312c9ee8ac0f4e5da919b2b1d384a37cbadaad
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/FramingMechanismHandlerFactory.java

index b233ff9365d84a011dc1901a0ec9cdcbeba7f602..5e16c00f2360cd9e7dc59202fb0231eab8551f54 100644 (file)
@@ -5,7 +5,6 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.netconf.nettyutil.handler;
 
 import io.netty.buffer.ByteBuf;
@@ -15,19 +14,17 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public final class FramingMechanismHandlerFactory {
-
     private static final Logger LOG = LoggerFactory.getLogger(FramingMechanismHandlerFactory.class);
 
     private FramingMechanismHandlerFactory() {
         // not called - private constructor for utility class
     }
 
-    public static MessageToByteEncoder<ByteBuf> createHandler(FramingMechanism framingMechanism) {
+    public static MessageToByteEncoder<ByteBuf> createHandler(final FramingMechanism framingMechanism) {
         LOG.debug("{} framing mechanism was selected.", framingMechanism);
-        if (framingMechanism == FramingMechanism.EOM) {
-            return new EOMFramingMechanismEncoder();
-        } else {
-            return new ChunkedFramingMechanismEncoder();
-        }
+        return switch (framingMechanism) {
+            case CHUNK -> new ChunkedFramingMechanismEncoder();
+            case EOM -> new EOMFramingMechanismEncoder();
+        };
     }
 }