Use instanceof pattern in netconf-impl 27/101727/2
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 4 Jul 2022 20:35:13 +0000 (22:35 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 5 Jul 2022 02:12:30 +0000 (04:12 +0200)
We can reduce verbosity by using a pattern match, use it.

Change-Id: Id92bda676d8c02f5670ae1aeacb526e20e6af03b
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/NetconfServerSession.java
netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/NetconfServerSessionNegotiator.java
netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/osgi/NetconfOperationRouterImpl.java

index 19601fcdca2be75f467c55c2039b8328bd4bb87f..a9cb3eb4f773321d2180581ae2ceeb1280b7fab1 100644 (file)
@@ -97,9 +97,9 @@ public final class NetconfServerSession extends AbstractNetconfSession<NetconfSe
     @Override
     public ChannelFuture sendMessage(final NetconfMessage netconfMessage) {
         final ChannelFuture channelFuture = super.sendMessage(netconfMessage);
-        if (netconfMessage instanceof NetconfNotification) {
+        if (netconfMessage instanceof NetconfNotification notification) {
             outNotification++;
-            sessionListener.onNotification(this, (NetconfNotification) netconfMessage);
+            sessionListener.onNotification(this, notification);
         }
         // delayed close was set, close after the message was sent
         if (delayedClose) {
index 4af12fe78dad387b68207121602530bab13cc2bc..75ca014aac9877666ed21e478b21ee3241711bd2 100644 (file)
@@ -66,12 +66,11 @@ public final class NetconfServerSessionNegotiator
      * @return Two values - port and host of socket address
      */
     protected static Map.Entry<String, String> getHostName(final SocketAddress socketAddress) {
-        if (socketAddress instanceof InetSocketAddress) {
-            final var inetSocketAddress = (InetSocketAddress) socketAddress;
+        if (socketAddress instanceof InetSocketAddress inetSocketAddress) {
             return new SimpleImmutableEntry<>(Integer.toString(inetSocketAddress.getPort()),
                     inetSocketAddress.getHostString());
-        } else if (socketAddress instanceof LocalAddress) {
-            return new SimpleImmutableEntry<>(UNKNOWN, ((LocalAddress) socketAddress).id());
+        } else if (socketAddress instanceof LocalAddress localAddress) {
+            return new SimpleImmutableEntry<>(UNKNOWN, localAddress.id());
         } else {
             return new SimpleImmutableEntry<>(UNKNOWN, UNKNOWN);
         }
index 3aa1c7107243a89c3a1a92ff3e15131eb2ec3a09..b1ab4b26de966af71f94fdeb8019d8eed1ebf04e 100644 (file)
@@ -150,11 +150,11 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter {
 
         for (final NetconfOperation netconfOperation : allNetconfOperations) {
             final HandlingPriority handlingPriority = netconfOperation.canHandle(message);
-            if (netconfOperation instanceof DefaultNetconfOperation) {
-                ((DefaultNetconfOperation) netconfOperation).setNetconfSession(session);
+            if (netconfOperation instanceof DefaultNetconfOperation defaultOperation) {
+                defaultOperation.setNetconfSession(session);
             }
-            if (netconfOperation instanceof SessionAwareNetconfOperation) {
-                ((SessionAwareNetconfOperation) netconfOperation).setSession(session);
+            if (netconfOperation instanceof SessionAwareNetconfOperation sessionAwareOperation) {
+                sessionAwareOperation.setSession(session);
             }
             if (!handlingPriority.equals(HandlingPriority.CANNOT_HANDLE)) {