Clean up SslHandlerFactoryImpl a bit 28/102328/2
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 9 Sep 2022 12:03:17 +0000 (14:03 +0200)
committerRobert Varga <nite@hq.sk>
Mon, 12 Sep 2022 15:27:05 +0000 (15:27 +0000)
Use an instanceof pattern and if/else chain instead of a checkArgument.
Also prefer Set.of().

Change-Id: I643fd75bd5191f1f9d9f434844d1b0e924433ad2
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/util/SslHandlerFactoryImpl.java

index 5e8453373978cb2702de41e7b72aa46a31c4aaeb..6165869eed50d6778befa6f59f6c387b9f1695b8 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.netconf.sal.connect.util;
 
-import static com.google.common.base.Preconditions.checkArgument;
 import static java.util.Objects.requireNonNull;
 
 import com.google.common.collect.Sets;
@@ -15,7 +14,6 @@ import io.netty.handler.ssl.SslHandler;
 import java.io.IOException;
 import java.security.GeneralSecurityException;
 import java.security.KeyStore;
-import java.util.Collections;
 import java.util.Set;
 import javax.net.ssl.KeyManagerFactory;
 import javax.net.ssl.SSLContext;
@@ -42,11 +40,11 @@ public final class SslHandlerFactoryImpl implements SslHandlerFactory {
 
     @Override
     public SslHandler createSslHandler() {
-        return createSslHandler(Collections.emptySet());
+        return createSslHandler(Set.of());
     }
 
     @Override
-    public SslHandler createSslHandler(Set<String> allowedKeys) {
+    public SslHandler createSslHandler(final Set<String> allowedKeys) {
         try {
             final KeyStore keyStore = keystoreAdapter.getJavaKeyStore(allowedKeys);
 
@@ -64,14 +62,14 @@ public final class SslHandlerFactoryImpl implements SslHandlerFactory {
 
             final String[] engineProtocols = engine.getSupportedProtocols();
             final String[] enabledProtocols;
-            if (specification != null) {
-                checkArgument(specification instanceof TlsCase, "Cannot get TLS specification from: %s", specification);
-
+            if (specification instanceof TlsCase tlsSpecification) {
                 final Set<String> protocols = Sets.newHashSet(engineProtocols);
-                protocols.removeAll(((TlsCase)specification).getTls().getExcludedVersions());
+                protocols.removeAll(tlsSpecification.getTls().getExcludedVersions());
                 enabledProtocols = protocols.toArray(new String[0]);
-            } else {
+            } else if (specification == null) {
                 enabledProtocols = engineProtocols;
+            } else {
+                throw new IllegalArgumentException("Cannot get TLS specification from: " + specification);
             }
 
             engine.setEnabledProtocols(enabledProtocols);