Use instanceof pattern in netconf-impl
[netconf.git] / netconf / netconf-impl / src / main / java / org / opendaylight / netconf / impl / NetconfServerSession.java
index df7dcd1900763f243227cb3a19242ada030f8c70..a9cb3eb4f773321d2180581ae2ceeb1280b7fab1 100644 (file)
@@ -82,7 +82,7 @@ public final class NetconfServerSession extends AbstractNetconfSession<NetconfSe
     @Override
     protected void sessionUp() {
         checkState(loginTime == null, "Session is already up");
-        this.loginTime = Instant.now().atZone(ZoneId.systemDefault());
+        loginTime = Instant.now().atZone(ZoneId.systemDefault());
         super.sessionUp();
     }
 
@@ -91,15 +91,15 @@ public final class NetconfServerSession extends AbstractNetconfSession<NetconfSe
      * Suitable for close rpc that needs to send ok response before the session is closed.
      */
     public void delayedClose() {
-        this.delayedClose = true;
+        delayedClose = true;
     }
 
     @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) {
@@ -149,15 +149,12 @@ public final class NetconfServerSession extends AbstractNetconfSession<NetconfSe
                 .build();
     }
 
-    private static Class<? extends Transport> getTransportForString(final String transport) {
-        switch (transport) {
-            case "ssh":
-                return NetconfSsh.class;
-            case "tcp":
-                return NetconfTcp.class;
-            default:
-                throw new IllegalArgumentException("Unknown transport type " + transport);
-        }
+    private static Transport getTransportForString(final String transport) {
+        return switch (transport) {
+            case "ssh" -> NetconfSsh.VALUE;
+            case "tcp" -> NetconfTcp.VALUE;
+            default -> throw new IllegalArgumentException("Unknown transport type " + transport);
+        };
     }
 
     @Override