From ab42fe7a71790596125986630dd119dffc668ec5 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Fri, 29 Jul 2022 18:10:55 +0200 Subject: [PATCH 1/1] Use switch expression in FramingMechanismHandlerFactory Switch expressions are exhaustive, which is exactly what we want to do here. Change-Id: I32312c9ee8ac0f4e5da919b2b1d384a37cbadaad Signed-off-by: Robert Varga --- .../handler/FramingMechanismHandlerFactory.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/FramingMechanismHandlerFactory.java b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/FramingMechanismHandlerFactory.java index b233ff9365..5e16c00f23 100644 --- a/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/FramingMechanismHandlerFactory.java +++ b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/FramingMechanismHandlerFactory.java @@ -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 createHandler(FramingMechanism framingMechanism) { + public static MessageToByteEncoder 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(); + }; } } -- 2.36.6