Use Object.requireNonNull 60/84160/6
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 3 Sep 2019 07:21:19 +0000 (09:21 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 3 Sep 2019 18:17:58 +0000 (20:17 +0200)
modernizer is pointing out these users, fix them up.

Change-Id: I67dba53d79ef24d464bb5e54685152d182fbbdb3
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
35 files changed:
netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/MdsalNetconfOperationServiceFactory.java
netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/get/FilterContentValidatorTest.java
netconf/mdsal-netconf-notification/src/main/java/org/opendaylight/netconf/mdsal/notification/impl/NetconfNotificationManager.java
netconf/mdsal-netconf-notification/src/main/java/org/opendaylight/netconf/mdsal/notification/impl/ops/CreateSubscription.java
netconf/mdsal-netconf-notification/src/main/java/org/opendaylight/netconf/mdsal/notification/impl/ops/NotificationsTransformUtil.java
netconf/mdsal-netconf-notification/src/test/java/org/opendaylight/netconf/mdsal/notification/impl/CapabilityChangeNotificationProducerTest.java
netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/DocumentedException.java
netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/messages/NetconfHelloMessageAdditionalHeader.java
netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/SimpleNetconfClientSessionListener.java
netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/conf/NetconfClientConfiguration.java
netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/conf/NetconfReconnectingClientConfiguration.java
netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/NetconfServerSessionNegotiatorFactoryBuilder.java
netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/mapping/operations/DefaultCloseSession.java
netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/osgi/NetconfOperationRouterImpl.java
netconf/netconf-impl/src/test/java/org/opendaylight/netconf/impl/ConcurrentClientsTest.java
netconf/netconf-impl/src/test/java/org/opendaylight/netconf/impl/osgi/NetconfOperationRouterImplTest.java
netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/AbstractNetconfDispatcher.java
netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/NetconfSessionPromise.java
netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/NeverReconnectStrategy.java
netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/ReconnectImmediatelyStrategy.java
netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/ReconnectPromise.java
netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/TimedReconnectStrategy.java
netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/ssh/client/AsyncSshHandler.java
netconf/netconf-notifications-api/src/main/java/org/opendaylight/netconf/notifications/NetconfNotification.java
netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/NodeContainerProxy.java
netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/test/XmlFileLoader.java
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/DeviceActionFactoryImpl.java
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/NetconfDeviceBuilder.java
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/NotificationHandler.java
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/listener/NetconfSessionPreferences.java
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalProvider.java
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceTopologyAdapter.java
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/util/NetconfBaseOps.java
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/util/NetconfTopologyRPCProvider.java
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/util/RemoteDeviceId.java

index 829f66bb4257697a1da73fd1b3d28fae6a03bef9..1c39f54caa76f8428a4bbca728223430b92dde82 100644 (file)
@@ -7,7 +7,9 @@
  */
 package org.opendaylight.netconf.mdsal.connector;
 
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkState;
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.io.CharStreams;
 import java.io.IOException;
 import java.io.InputStream;
@@ -61,7 +63,7 @@ public class MdsalNetconfOperationServiceFactory implements NetconfOperationServ
 
         this.rootSchemaSourceProviderDependency = schemaService.getExtensions()
                 .getInstance(DOMYangTextSourceProvider.class);
-        this.currentSchemaContext = new CurrentSchemaContext(Preconditions.checkNotNull(schemaService),
+        this.currentSchemaContext = new CurrentSchemaContext(requireNonNull(schemaService),
                 rootSchemaSourceProviderDependency);
         this.netconfOperationServiceFactoryListener = netconfOperationServiceFactoryListener;
         this.netconfOperationServiceFactoryListener.onAddNetconfOperationServiceFactory(this);
@@ -69,7 +71,7 @@ public class MdsalNetconfOperationServiceFactory implements NetconfOperationServ
 
     @Override
     public MdsalNetconfOperationService createService(final String netconfSessionIdForReporting) {
-        Preconditions.checkState(dataBroker != null, "MD-SAL provider not yet initialized");
+        checkState(dataBroker != null, "MD-SAL provider not yet initialized");
         return new MdsalNetconfOperationService(currentSchemaContext, netconfSessionIdForReporting, dataBroker,
                 rpcService);
     }
index 04a3a1414cbab3527945cee77f056c29cc9b32fc..3b493d27825a8d00202c4a0e9408bce3d1297f8f 100644 (file)
@@ -7,10 +7,10 @@
  */
 package org.opendaylight.netconf.mdsal.connector.ops.get;
 
+import static java.util.Objects.requireNonNull;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 
-import com.google.common.base.Preconditions;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
@@ -142,7 +142,7 @@ public class FilterContentValidatorTest {
         try {
             return QName.create(input);
         } catch (IllegalArgumentException e) {
-            return QName.create(Preconditions.checkNotNull(prev), input);
+            return QName.create(requireNonNull(prev), input);
         }
     }
 }
index b7df2d720e56899c510266d8b5b02a747bb6fa72..bd54b4c5c6503367a5a193b08b18516f6db8a29f 100644 (file)
@@ -7,7 +7,10 @@
  */
 package org.opendaylight.netconf.mdsal.notification.impl;
 
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkState;
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.collect.HashMultimap;
 import com.google.common.collect.HashMultiset;
 import com.google.common.collect.Lists;
@@ -98,8 +101,8 @@ public class NetconfNotificationManager implements NetconfNotificationCollector,
     public synchronized NotificationListenerRegistration registerNotificationListener(
             final StreamNameType stream,
             final NetconfNotificationListener listener) {
-        Preconditions.checkNotNull(stream);
-        Preconditions.checkNotNull(listener);
+        requireNonNull(stream);
+        requireNonNull(listener);
 
         LOG.trace("Notification listener registered for stream: {}", stream);
 
@@ -165,8 +168,7 @@ public class NetconfNotificationManager implements NetconfNotificationCollector,
 
     @Override
     public synchronized NotificationPublisherRegistration registerNotificationPublisher(final Stream stream) {
-        Preconditions.checkNotNull(stream);
-        final StreamNameType streamName = stream.getName();
+        final StreamNameType streamName = requireNonNull(stream).getName();
 
         LOG.debug("Notification publisher registered for stream: {}", streamName);
         if (LOG.isTraceEnabled()) {
@@ -251,8 +253,8 @@ public class NetconfNotificationManager implements NetconfNotificationCollector,
 
         @Override
         public void onNotification(final StreamNameType stream, final NetconfNotification notification) {
-            Preconditions.checkState(baseListener != null, "Already closed");
-            Preconditions.checkArgument(stream.equals(registeredStream));
+            checkState(baseListener != null, "Already closed");
+            checkArgument(stream.equals(registeredStream));
             baseListener.onNotification(stream, notification);
         }
     }
index 710dcdf007302fd9d144fc525f72f04b79a4cfbc..3f3d14ed96fabe49f555dbd3ee7be59fa640b810 100644 (file)
@@ -7,7 +7,9 @@
  */
 package org.opendaylight.netconf.mdsal.notification.impl.ops;
 
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkArgument;
+import static java.util.Objects.requireNonNull;
+
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
@@ -67,16 +69,16 @@ public class CreateSubscription extends AbstractSingletonNetconfOperation
         // Replay not supported
         final Optional<XmlElement> startTime =
                 operationElement.getOnlyChildElementWithSameNamespaceOptionally("startTime");
-        Preconditions.checkArgument(!startTime.isPresent(), "StartTime element not yet supported");
+        checkArgument(!startTime.isPresent(), "StartTime element not yet supported");
 
         // Stop time not supported
         final Optional<XmlElement> stopTime =
                 operationElement.getOnlyChildElementWithSameNamespaceOptionally("stopTime");
-        Preconditions.checkArgument(!stopTime.isPresent(), "StopTime element not yet supported");
+        checkArgument(!stopTime.isPresent(), "StopTime element not yet supported");
 
         final StreamNameType streamNameType = parseStreamIfPresent(operationElement);
 
-        Preconditions.checkNotNull(netconfSession);
+        requireNonNull(netconfSession);
         // Premature streams are allowed (meaning listener can register even if no provider is available yet)
         if (!notifications.isStreamAvailable(streamNameType)) {
             LOG.warn("Registering premature stream {}. No publisher available yet for session {}", streamNameType,
index c146200e9906b4fa6a02b5f4603d6a430b612e84..f54bc811de7ccff55577ea0d68bc82bcb339cfc3 100644 (file)
@@ -7,7 +7,9 @@
  */
 package org.opendaylight.netconf.mdsal.notification.impl.ops;
 
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkState;
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.collect.Collections2;
 import com.google.common.collect.Iterables;
 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
@@ -42,12 +44,10 @@ public final class NotificationsTransformUtil {
         moduleInfoBackedContext.addModuleInfos(Collections.singletonList(org.opendaylight.yang.gen.v1.urn.ietf.params
                 .xml.ns.yang.ietf.netconf.notifications.rev120206.$YangModuleInfoImpl.getInstance()));
         final Optional<SchemaContext> schemaContextOptional = moduleInfoBackedContext.tryToCreateSchemaContext();
-        Preconditions.checkState(schemaContextOptional.isPresent());
+        checkState(schemaContextOptional.isPresent());
         NOTIFICATIONS_SCHEMA_CTX = schemaContextOptional.get();
 
-        CREATE_SUBSCRIPTION_RPC = Preconditions.checkNotNull(findCreateSubscriptionRpc());
-
-        Preconditions.checkNotNull(CREATE_SUBSCRIPTION_RPC);
+        CREATE_SUBSCRIPTION_RPC = requireNonNull(findCreateSubscriptionRpc());
 
         CODEC_REGISTRY = new BindingNormalizedNodeCodecRegistry(BindingRuntimeContext.create(moduleInfoBackedContext,
                 NOTIFICATIONS_SCHEMA_CTX));
index aeb97e4f06b4d234ed59ae994db599abd57f8f76..828739b8f7daeb92ce513edba496c6a5b2af7ef0 100644 (file)
@@ -14,8 +14,8 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 
 import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import org.junit.Before;
@@ -79,7 +79,7 @@ public class CapabilityChangeNotificationProducerTest {
         final List<Uri> newCapabilitiesList =
                 Lists.newArrayList(new Uri("newCapability"), new Uri("createdCapability"));
         Capabilities newCapabilities = new CapabilitiesBuilder().setCapability(newCapabilitiesList).build();
-        Map<InstanceIdentifier<?>, DataObject> createdData = Maps.newHashMap();
+        Map<InstanceIdentifier<?>, DataObject> createdData = new HashMap<>();
         createdData.put(capabilitiesIdentifier, newCapabilities);
         verifyDataTreeChange(DataObjectModification.ModificationType.WRITE, null, newCapabilities,
                 changedCapabilitesFrom(newCapabilitiesList, Collections.emptyList()));
index 15d4dfe443882b280f9a6f83db4d4db93b3ea9d5..907fd2fb5d2b86c65072ce5c472c41c726010a95 100644 (file)
@@ -5,13 +5,12 @@
  * 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.api;
 
+import static java.util.Objects.requireNonNull;
 import static org.opendaylight.netconf.api.xml.XmlNetconfConstants.RPC_REPLY_KEY;
 import static org.opendaylight.netconf.api.xml.XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0;
 
-import com.google.common.base.Preconditions;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
@@ -68,7 +67,7 @@ public class DocumentedException extends Exception {
         private final String typeValue;
 
         ErrorType(final String typeValue) {
-            this.typeValue = Preconditions.checkNotNull(typeValue);
+            this.typeValue = requireNonNull(typeValue);
         }
 
         public String getTypeValue() {
@@ -134,7 +133,7 @@ public class DocumentedException extends Exception {
         private final String severityValue;
 
         ErrorSeverity(final String severityValue) {
-            this.severityValue = Preconditions.checkNotNull(severityValue);
+            this.severityValue = requireNonNull(severityValue);
         }
 
         public String getSeverityValue() {
index 5db8a6c811d247c34d78d751e822cabeda1b9f58..17374ead4d12ded4afc136ff7bdb96774091cf20 100644 (file)
@@ -5,10 +5,11 @@
  * 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.api.messages;
 
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkArgument;
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.net.InetAddresses;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -38,8 +39,8 @@ public class NetconfHelloMessageAdditionalHeader {
     private final String transport;
     private final String sessionIdentifier;
 
-    public NetconfHelloMessageAdditionalHeader(String userName, String hostAddress, String port,
-                                               String transport, String sessionIdentifier) {
+    public NetconfHelloMessageAdditionalHeader(final String userName, final String hostAddress, final String port,
+                                               final String transport, final String sessionIdentifier) {
         this.userName = userName;
         this.hostAddress = hostAddress;
         this.port = port;
@@ -71,11 +72,11 @@ public class NetconfHelloMessageAdditionalHeader {
      * Format additional header into a string suitable as a prefix for netconf hello message.
      */
     public String toFormattedString() {
-        Preconditions.checkNotNull(userName);
-        Preconditions.checkNotNull(hostAddress);
-        Preconditions.checkNotNull(port);
-        Preconditions.checkNotNull(transport);
-        Preconditions.checkNotNull(sessionIdentifier);
+        requireNonNull(userName);
+        requireNonNull(hostAddress);
+        requireNonNull(port);
+        requireNonNull(transport);
+        requireNonNull(sessionIdentifier);
         return "[" + userName + SC + hostAddress + ":" + port + SC + transport + SC + sessionIdentifier + SC + "]"
                 + System.lineSeparator();
     }
@@ -101,16 +102,16 @@ public class NetconfHelloMessageAdditionalHeader {
     /**
      * Parse additional header from a formatted string.
      */
-    public static NetconfHelloMessageAdditionalHeader fromString(String additionalHeader) {
+    public static NetconfHelloMessageAdditionalHeader fromString(final String additionalHeader) {
         String additionalHeaderTrimmed = additionalHeader.trim();
         Matcher matcher = PATTERN.matcher(additionalHeaderTrimmed);
         Matcher matcher2 = CUSTOM_HEADER_PATTERN.matcher(additionalHeaderTrimmed);
-        Preconditions.checkArgument(matcher.matches(), "Additional header in wrong format %s, expected %s",
+        checkArgument(matcher.matches(), "Additional header in wrong format %s, expected %s",
                 additionalHeaderTrimmed, PATTERN);
 
         String username = matcher.group("username");
         String address = matcher.group("address");
-        Preconditions.checkArgument(InetAddresses.isInetAddress(address));
+        checkArgument(InetAddresses.isInetAddress(address));
         String port = matcher.group("port");
         String transport = matcher.group("transport");
         String sessionIdentifier = "client";
@@ -119,5 +120,4 @@ public class NetconfHelloMessageAdditionalHeader {
         }
         return new NetconfHelloMessageAdditionalHeader(username, address, port, transport, sessionIdentifier);
     }
-
 }
index 14b2bdf98028ec8000d503857eb4b6209f90a808..0390e637fa970068ca220b558dc6667e573806aa 100644 (file)
@@ -7,7 +7,8 @@
  */
 package org.opendaylight.netconf.client;
 
-import com.google.common.base.Preconditions;
+import static java.util.Objects.requireNonNull;
+
 import io.netty.util.concurrent.Future;
 import io.netty.util.concurrent.GlobalEventExecutor;
 import io.netty.util.concurrent.Promise;
@@ -26,8 +27,8 @@ public class SimpleNetconfClientSessionListener implements NetconfClientSessionL
         private final NetconfMessage request;
 
         RequestEntry(final Promise<NetconfMessage> future, final NetconfMessage request) {
-            this.promise = Preconditions.checkNotNull(future);
-            this.request = Preconditions.checkNotNull(request);
+            this.promise = requireNonNull(future);
+            this.request = requireNonNull(request);
         }
     }
 
@@ -57,7 +58,7 @@ public class SimpleNetconfClientSessionListener implements NetconfClientSessionL
     @Override
     @SuppressWarnings("checkstyle:hiddenField")
     public final synchronized void onSessionUp(final NetconfClientSession clientSession) {
-        this.clientSession = Preconditions.checkNotNull(clientSession);
+        this.clientSession = requireNonNull(clientSession);
         LOG.debug("Client session {} went up", clientSession);
         dispatchRequest();
     }
index 9ad03b915df50926539f5391e1f9cdefe346fd43..ded37caef21a9833fcc264b5bd401fd55b98c550 100644 (file)
@@ -7,9 +7,10 @@
  */
 package org.opendaylight.netconf.client.conf;
 
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.base.MoreObjects;
 import com.google.common.base.MoreObjects.ToStringHelper;
-import com.google.common.base.Preconditions;
 import java.net.InetSocketAddress;
 import java.util.List;
 import java.util.Optional;
@@ -96,8 +97,7 @@ public class NetconfClientConfiguration {
     }
 
     private void validateConfiguration() {
-        Preconditions.checkNotNull(clientProtocol, " ");
-        switch (clientProtocol) {
+        switch (requireNonNull(clientProtocol)) {
             case TLS:
                 validateTlsConfiguration();
                 validateTcpConfiguration();
@@ -115,19 +115,19 @@ public class NetconfClientConfiguration {
     }
 
     protected void validateTlsConfiguration() {
-        Preconditions.checkNotNull(sslHandlerFactory, "sslHandlerFactory");
+        requireNonNull(sslHandlerFactory, "sslHandlerFactory");
     }
 
     protected void validateSshConfiguration() {
-        Preconditions.checkNotNull(authHandler, "authHandler");
+        requireNonNull(authHandler, "authHandler");
     }
 
     protected void validateTcpConfiguration() {
-        Preconditions.checkNotNull(address, "address");
-        Preconditions.checkNotNull(clientProtocol, "clientProtocol");
-        Preconditions.checkNotNull(connectionTimeoutMillis, "connectionTimeoutMillis");
-        Preconditions.checkNotNull(sessionListener, "sessionListener");
-        Preconditions.checkNotNull(reconnectStrategy, "reconnectStrategy");
+        requireNonNull(address, "address");
+        requireNonNull(clientProtocol, "clientProtocol");
+        requireNonNull(connectionTimeoutMillis, "connectionTimeoutMillis");
+        requireNonNull(sessionListener, "sessionListener");
+        requireNonNull(reconnectStrategy, "reconnectStrategy");
     }
 
     @Override
index c43cd2d2b96d1454f5bbbd237221865f21b5547d..c69f023da7a4f8a919818c3204948c4b027cea44 100644 (file)
@@ -7,8 +7,9 @@
  */
 package org.opendaylight.netconf.client.conf;
 
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.base.MoreObjects.ToStringHelper;
-import com.google.common.base.Preconditions;
 import java.net.InetSocketAddress;
 import java.util.List;
 import org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader;
@@ -43,7 +44,7 @@ public final class NetconfReconnectingClientConfiguration extends NetconfClientC
     }
 
     private void validateReconnectConfiguration() {
-        Preconditions.checkNotNull(connectStrategyFactory);
+        requireNonNull(connectStrategyFactory);
     }
 
     @Override
index a46ed9a4bf373870118a50228f87630a22ebce46..cfbb7481ed8b0e5416f550a0ba5e085fce7fa50f 100644 (file)
@@ -5,10 +5,11 @@
  * 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.impl;
 
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkArgument;
+import static java.util.Objects.requireNonNull;
+
 import io.netty.util.Timer;
 import java.util.Set;
 import org.opendaylight.netconf.api.monitoring.NetconfMonitoringService;
@@ -66,13 +67,14 @@ public class NetconfServerSessionNegotiatorFactoryBuilder {
 
 
     private void validate() {
-        Preconditions.checkNotNull(timer, "timer not initialized");
-        Preconditions.checkNotNull(aggregatedOpService, "NetconfOperationServiceFactory not initialized");
-        Preconditions.checkNotNull(idProvider, "SessionIdProvider not initialized");
-        Preconditions.checkArgument(connectionTimeoutMillis > 0, "connection time out <=0");
-        Preconditions.checkNotNull(monitoringService, "NetconfMonitoringService not initialized");
+        requireNonNull(timer, "timer not initialized");
+        requireNonNull(aggregatedOpService, "NetconfOperationServiceFactory not initialized");
+        requireNonNull(idProvider, "SessionIdProvider not initialized");
+        checkArgument(connectionTimeoutMillis > 0, "connection time out <=0");
+        requireNonNull(monitoringService, "NetconfMonitoringService not initialized");
 
-        baseCapabilities = (baseCapabilities == null) ? NetconfServerSessionNegotiatorFactory
-                .DEFAULT_BASE_CAPABILITIES : baseCapabilities;
+        if (baseCapabilities == null) {
+            baseCapabilities = NetconfServerSessionNegotiatorFactory.DEFAULT_BASE_CAPABILITIES;
+        }
     }
 }
index 5a5ae1cc43d837253c03637015975ac172f5f36b..2b30c0951b09fb4a85cf8bb189dd681476fc7789 100644 (file)
@@ -7,7 +7,8 @@
  */
 package org.opendaylight.netconf.impl.mapping.operations;
 
-import com.google.common.base.Preconditions;
+import static java.util.Objects.requireNonNull;
+
 import java.util.Collections;
 import org.opendaylight.netconf.api.DocumentedException;
 import org.opendaylight.netconf.api.xml.XmlElement;
@@ -48,7 +49,7 @@ public class DefaultCloseSession extends AbstractSingletonNetconfOperation imple
             throws DocumentedException {
         try {
             sessionResources.close();
-            Preconditions.checkNotNull(session, "Session was not set").delayedClose();
+            requireNonNull(session, "Session was not set").delayedClose();
             LOG.info("Session {} closing", session.getSessionId());
         } catch (final Exception e) {
             throw new DocumentedException("Unable to properly close session "
index 6eda367bd53180fcae166df813ff13813358aac3..9defc2e8346be5febc99db95b5385f6a5d4e2760 100644 (file)
@@ -7,7 +7,9 @@
  */
 package org.opendaylight.netconf.impl.osgi;
 
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkState;
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.collect.ImmutableSet;
 import java.util.Collection;
 import java.util.Collections;
@@ -40,7 +42,7 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter {
 
     public NetconfOperationRouterImpl(final NetconfOperationService netconfOperationServiceSnapshot,
                                       final NetconfMonitoringService netconfMonitoringService, final String sessionId) {
-        this.netconfOperationServiceSnapshot = Preconditions.checkNotNull(netconfOperationServiceSnapshot);
+        this.netconfOperationServiceSnapshot = requireNonNull(netconfOperationServiceSnapshot);
 
         final Set<NetconfOperation> ops = new HashSet<>();
         ops.add(new DefaultCloseSession(sessionId, this));
@@ -56,7 +58,7 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter {
     @Override
     public Document onNetconfMessage(final Document message, final NetconfServerSession session) throws
             DocumentedException {
-        Preconditions.checkNotNull(allNetconfOperations, "Operation router was not initialized properly");
+        requireNonNull(allNetconfOperations, "Operation router was not initialized properly");
 
         final NetconfOperationExecution netconfOperationExecution;
         try {
@@ -141,7 +143,7 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter {
             }
             if (!handlingPriority.equals(HandlingPriority.CANNOT_HANDLE)) {
 
-                Preconditions.checkState(!sortedPriority.containsKey(handlingPriority),
+                checkState(!sortedPriority.containsKey(handlingPriority),
                         "Multiple %s available to handle message %s with priority %s, %s and %s",
                         NetconfOperation.class.getName(), message, handlingPriority, netconfOperation, sortedPriority
                                 .get(handlingPriority));
index 0462214578593409fa474e69dcc082d2558edff3..1a4e4c319eb047fbaf4b79bfb9fa9bf89d323de6 100644 (file)
@@ -5,18 +5,16 @@
  * 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.impl;
 
-import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Preconditions.checkState;
+import static java.util.Objects.requireNonNull;
 import static org.junit.Assert.assertEquals;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Lists;
 import com.google.common.collect.Sets;
 import com.google.common.io.ByteStreams;
 import io.netty.channel.ChannelFuture;
@@ -29,6 +27,7 @@ import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.net.InetSocketAddress;
 import java.net.Socket;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
@@ -91,7 +90,8 @@ public class ConcurrentClientsTest {
     private final Class<? extends Runnable> clientRunnable;
     private final Set<String> serverCaps;
 
-    public ConcurrentClientsTest(int nettyThreads, Class<? extends Runnable> clientRunnable, Set<String> serverCaps) {
+    public ConcurrentClientsTest(final int nettyThreads, final Class<? extends Runnable> clientRunnable,
+            final Set<String> serverCaps) {
         this.nettyThreads = nettyThreads;
         this.clientRunnable = clientRunnable;
         this.serverCaps = serverCaps;
@@ -198,7 +198,7 @@ public class ConcurrentClientsTest {
     @Test(timeout = CONCURRENCY * 1000)
     public void testConcurrentClients() throws Exception {
 
-        List<Future<?>> futures = Lists.newArrayListWithCapacity(CONCURRENCY);
+        List<Future<?>> futures = new ArrayList<>(CONCURRENCY);
 
         for (int i = 0; i < CONCURRENCY; i++) {
             futures.add(clientExecutor.submit(getInstanceOfClientRunnable()));
@@ -244,7 +244,7 @@ public class ConcurrentClientsTest {
         private final AtomicLong counter = new AtomicLong();
 
         @Override
-        public HandlingPriority canHandle(Document message) {
+        public HandlingPriority canHandle(final Document message) {
             return XmlUtil.toString(message).contains(NetconfStartExiMessage.START_EXI)
                     ? HandlingPriority.CANNOT_HANDLE :
                     HandlingPriority.HANDLE_WITH_MAX_PRIORITY;
@@ -252,8 +252,8 @@ public class ConcurrentClientsTest {
 
         @SuppressWarnings("checkstyle:IllegalCatch")
         @Override
-        public Document handle(Document requestMessage, NetconfOperationChainedExecution subsequentOperation)
-                throws DocumentedException {
+        public Document handle(final Document requestMessage,
+                final NetconfOperationChainedExecution subsequentOperation) throws DocumentedException {
             try {
                 LOG.info("Handling netconf message from test {}", XmlUtil.toString(requestMessage));
                 counter.getAndIncrement();
@@ -290,7 +290,7 @@ public class ConcurrentClientsTest {
         }
 
         @Override
-        public NetconfOperationService createService(String netconfSessionIdForReporting) {
+        public NetconfOperationService createService(final String netconfSessionIdForReporting) {
             return new NetconfOperationService() {
 
                 @Override
@@ -321,10 +321,10 @@ public class ConcurrentClientsTest {
         }
 
         private void run2() throws Exception {
-            InputStream clientHello = checkNotNull(XmlFileLoader
-                    .getResourceAsStream("netconfMessages/client_hello.xml"));
-            final InputStream getConfig =
-                    checkNotNull(XmlFileLoader.getResourceAsStream("netconfMessages/getConfig.xml"));
+            InputStream clientHello = requireNonNull(XmlFileLoader.getResourceAsStream(
+                "netconfMessages/client_hello.xml"));
+            final InputStream getConfig = requireNonNull(XmlFileLoader.getResourceAsStream(
+                "netconfMessages/getConfig.xml"));
 
             Socket clientSocket = new Socket(NETCONF_ADDRESS.getHostString(), NETCONF_ADDRESS.getPort());
             DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
@@ -373,7 +373,7 @@ public class ConcurrentClientsTest {
                 NetconfMessage result = netconfClient.sendRequest(getMessage).get();
                 LOG.info("Client with session id {}: got result {}", sessionId, result);
 
-                Preconditions.checkState(NetconfMessageUtil.isErrorMessage(result) == false,
+                checkState(NetconfMessageUtil.isErrorMessage(result) == false,
                         "Received error response: " + XmlUtil.toString(result.getDocument()) + " to request: "
                                 + XmlUtil.toString(getMessage.getDocument()));
 
index a59c257635ea14447e6a2ba787de12c24cc44862..21c375830a7aaecae9a545e2ef05c6937fd8d550 100644 (file)
@@ -77,7 +77,7 @@ public class NetconfOperationRouterImplTest {
         doNothing().when(operationService).close();
 
         operationRouter = new NetconfOperationRouterImpl(operationService, null, "session-1");
-        doReturn(Collections.EMPTY_SET).when(operationService2).getNetconfOperations();
+        doReturn(Collections.emptySet()).when(operationService2).getNetconfOperations();
         emptyOperationRouter = new NetconfOperationRouterImpl(operationService2, null, "session-1");
     }
 
index 7997095850c9a2890420e46bb972fa00440bde23..c4e3b479789b0f3b13e991dda1a3ebf0d1e5027e 100644 (file)
@@ -7,7 +7,8 @@
  */
 package org.opendaylight.netconf.nettyutil;
 
-import com.google.common.base.Preconditions;
+import static java.util.Objects.requireNonNull;
+
 import io.netty.bootstrap.Bootstrap;
 import io.netty.bootstrap.ServerBootstrap;
 import io.netty.buffer.PooledByteBufAllocator;
@@ -73,9 +74,9 @@ public abstract class AbstractNetconfDispatcher<S extends NetconfSession, L exte
 
     protected AbstractNetconfDispatcher(final EventExecutor executor, final EventLoopGroup bossGroup,
             final EventLoopGroup workerGroup) {
-        this.bossGroup = Preconditions.checkNotNull(bossGroup);
-        this.workerGroup = Preconditions.checkNotNull(workerGroup);
-        this.executor = Preconditions.checkNotNull(executor);
+        this.bossGroup = requireNonNull(bossGroup);
+        this.workerGroup = requireNonNull(workerGroup);
+        this.executor = requireNonNull(executor);
     }
 
 
index 91d0ba99d526589baeb998ec11fdb4355a203a48..d32b2488385cae24872d2db67abb4be450195b8d 100644 (file)
@@ -7,7 +7,9 @@
  */
 package org.opendaylight.netconf.nettyutil;
 
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkState;
+import static java.util.Objects.requireNonNull;
+
 import io.netty.bootstrap.Bootstrap;
 import io.netty.channel.ChannelFuture;
 import io.netty.channel.ChannelFutureListener;
@@ -36,9 +38,9 @@ final class NetconfSessionPromise<S extends NetconfSession> extends DefaultPromi
     NetconfSessionPromise(final EventExecutor executor, final InetSocketAddress address,
             final ReconnectStrategy strategy, final Bootstrap bootstrap) {
         super(executor);
-        this.strategy = Preconditions.checkNotNull(strategy);
-        this.address = Preconditions.checkNotNull(address);
-        this.bootstrap = Preconditions.checkNotNull(bootstrap);
+        this.strategy = requireNonNull(strategy);
+        this.address = requireNonNull(address);
+        this.bootstrap = requireNonNull(bootstrap);
     }
 
     @SuppressWarnings("checkstyle:illegalCatch")
@@ -87,7 +89,7 @@ final class NetconfSessionPromise<S extends NetconfSession> extends DefaultPromi
                 LOG.debug("Promise {} connection resolved", NetconfSessionPromise.this);
 
                 // Triggered when a connection attempt is resolved.
-                Preconditions.checkState(NetconfSessionPromise.this.pending.equals(cf));
+                checkState(NetconfSessionPromise.this.pending.equals(cf));
 
                 /*
                  * The promise we gave out could have been cancelled,
@@ -124,7 +126,7 @@ final class NetconfSessionPromise<S extends NetconfSession> extends DefaultPromi
             public void operationComplete(final Future<Void> sf) {
                 synchronized (NetconfSessionPromise.this) {
                     // Triggered when a connection attempt is to be made.
-                    Preconditions.checkState(NetconfSessionPromise.this.pending.equals(sf));
+                    checkState(NetconfSessionPromise.this.pending.equals(sf));
 
                     /*
                      * The promise we gave out could have been cancelled,
index d59a36f952bf423795f66938ca5b35dd244bcf14..f3a46ba3af7f0028b139d21baaa1f1989a09d411 100644 (file)
@@ -7,7 +7,9 @@
  */
 package org.opendaylight.netconf.nettyutil;
 
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkArgument;
+import static java.util.Objects.requireNonNull;
+
 import io.netty.util.concurrent.EventExecutor;
 import io.netty.util.concurrent.Future;
 
@@ -20,8 +22,8 @@ public final class NeverReconnectStrategy implements ReconnectStrategy {
     private final int timeout;
 
     public NeverReconnectStrategy(final EventExecutor executor, final int timeout) {
-        Preconditions.checkArgument(timeout >= 0);
-        this.executor = Preconditions.checkNotNull(executor);
+        checkArgument(timeout >= 0);
+        this.executor = requireNonNull(executor);
         this.timeout = timeout;
     }
 
index 98756e06eebb7fb63405cd40b1a0b7b2994518ab..da0c5e5fc123b0ea57bcb17f67be44f23ebf16a2 100644 (file)
@@ -7,7 +7,9 @@
  */
 package org.opendaylight.netconf.nettyutil;
 
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkArgument;
+import static java.util.Objects.requireNonNull;
+
 import io.netty.util.concurrent.EventExecutor;
 import io.netty.util.concurrent.Future;
 import org.slf4j.Logger;
@@ -24,8 +26,8 @@ public final class ReconnectImmediatelyStrategy implements ReconnectStrategy {
     private final int timeout;
 
     public ReconnectImmediatelyStrategy(final EventExecutor executor, final int timeout) {
-        Preconditions.checkArgument(timeout >= 0);
-        this.executor = Preconditions.checkNotNull(executor);
+        checkArgument(timeout >= 0);
+        this.executor = requireNonNull(executor);
         this.timeout = timeout;
     }
 
index 696d9f7ad02587e934ba19c95c2c72c12d1d149e..52fbf291b156f85710691598cbf1a3305cdbe705 100644 (file)
@@ -7,7 +7,8 @@
  */
 package org.opendaylight.netconf.nettyutil;
 
-import com.google.common.base.Preconditions;
+import static java.util.Objects.requireNonNull;
+
 import io.netty.bootstrap.Bootstrap;
 import io.netty.channel.ChannelHandlerContext;
 import io.netty.channel.ChannelInboundHandlerAdapter;
@@ -37,10 +38,10 @@ final class ReconnectPromise<S extends NetconfSession, L extends NetconfSessionL
             final Bootstrap bootstrap, final AbstractNetconfDispatcher.PipelineInitializer<S> initializer) {
         super(executor);
         this.bootstrap = bootstrap;
-        this.initializer = Preconditions.checkNotNull(initializer);
-        this.dispatcher = Preconditions.checkNotNull(dispatcher);
-        this.address = Preconditions.checkNotNull(address);
-        this.strategyFactory = Preconditions.checkNotNull(connectStrategyFactory);
+        this.initializer = requireNonNull(initializer);
+        this.dispatcher = requireNonNull(dispatcher);
+        this.address = requireNonNull(address);
+        this.strategyFactory = requireNonNull(connectStrategyFactory);
     }
 
     synchronized void connect() {
@@ -74,14 +75,14 @@ final class ReconnectPromise<S extends NetconfSession, L extends NetconfSessionL
      *         Connection refused, Negotiation failed
      */
     private synchronized boolean isInitialConnectFinished() {
-        Preconditions.checkNotNull(pending);
+        requireNonNull(pending);
         return pending.isDone() && pending.isSuccess();
     }
 
     @Override
     public synchronized boolean cancel(final boolean mayInterruptIfRunning) {
         if (super.cancel(mayInterruptIfRunning)) {
-            Preconditions.checkNotNull(pending);
+            requireNonNull(pending);
             this.pending.cancel(mayInterruptIfRunning);
             return true;
         }
index 68c4fd72a54f17e64337dbe66f2acae5368350ea..895ebb22a0aa357af7440b3f7e0c5bae3e1f50ae 100644 (file)
@@ -7,7 +7,10 @@
  */
 package org.opendaylight.netconf.nettyutil;
 
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkState;
+import static java.util.Objects.requireNonNull;
+
 import io.netty.util.concurrent.EventExecutor;
 import io.netty.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
@@ -64,10 +67,10 @@ public final class TimedReconnectStrategy implements ReconnectStrategy {
 
     public TimedReconnectStrategy(final EventExecutor executor, final int connectTime, final long minSleep,
             final double sleepFactor, final Long maxSleep, final Long maxAttempts, final Long deadline) {
-        Preconditions.checkArgument(maxSleep == null || minSleep <= maxSleep);
-        Preconditions.checkArgument(sleepFactor >= 1);
-        Preconditions.checkArgument(connectTime >= 0);
-        this.executor = Preconditions.checkNotNull(executor);
+        checkArgument(maxSleep == null || minSleep <= maxSleep);
+        checkArgument(sleepFactor >= 1);
+        checkArgument(connectTime >= 0);
+        this.executor = requireNonNull(executor);
         this.deadline = deadline;
         this.maxAttempts = maxAttempts;
         this.minSleep = minSleep;
@@ -81,7 +84,7 @@ public final class TimedReconnectStrategy implements ReconnectStrategy {
         LOG.debug("Connection attempt failed", cause);
 
         // Check if a reconnect attempt is scheduled
-        Preconditions.checkState(!this.scheduled);
+        checkState(!this.scheduled);
 
         // Get a stable 'now' time for deadline calculations
         final long now = System.nanoTime();
@@ -130,7 +133,7 @@ public final class TimedReconnectStrategy implements ReconnectStrategy {
         // Schedule a task for the right time. It will also clear the flag.
         return this.executor.schedule(() -> {
             synchronized (TimedReconnectStrategy.this) {
-                Preconditions.checkState(TimedReconnectStrategy.this.scheduled);
+                checkState(TimedReconnectStrategy.this.scheduled);
                 TimedReconnectStrategy.this.scheduled = false;
             }
 
@@ -140,7 +143,7 @@ public final class TimedReconnectStrategy implements ReconnectStrategy {
 
     @Override
     public synchronized void reconnectSuccessful() {
-        Preconditions.checkState(!this.scheduled);
+        checkState(!this.scheduled);
         this.attempts = 0;
     }
 
index 15882ded63ec8d1acfdf09f0f9284e5d59a65f8e..0017eff749043fb399edfbf32143dce8aee89fa0 100644 (file)
@@ -5,10 +5,10 @@
  * 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.ssh.client;
 
-import com.google.common.base.Preconditions;
+import static java.util.Objects.requireNonNull;
+
 import io.netty.channel.ChannelHandlerContext;
 import io.netty.channel.ChannelOutboundHandlerAdapter;
 import io.netty.channel.ChannelPromise;
@@ -78,8 +78,8 @@ public class AsyncSshHandler extends ChannelOutboundHandlerAdapter {
      */
     public AsyncSshHandler(final AuthenticationHandler authenticationHandler,
                            final SshClient sshClient) {
-        this.authenticationHandler = Preconditions.checkNotNull(authenticationHandler);
-        this.sshClient = Preconditions.checkNotNull(sshClient);
+        this.authenticationHandler = requireNonNull(authenticationHandler);
+        this.sshClient = requireNonNull(sshClient);
     }
 
     public static AsyncSshHandler createForNetconfSubsystem(final AuthenticationHandler authenticationHandler) {
index 87de89a5dba7f94488b6ebae6fdafd69923aa874..9d2248e27a4904e9de3cc0f9f69f2560009ab547 100644 (file)
@@ -5,10 +5,10 @@
  * 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.notifications;
 
-import com.google.common.base.Preconditions;
+import static java.util.Objects.requireNonNull;
+
 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.text.ParsePosition;
 import java.time.Instant;
@@ -197,8 +197,8 @@ public final class NetconfNotification extends NetconfMessage {
     }
 
     private static Document wrapNotification(final Document notificationContent, final Date eventTime) {
-        Preconditions.checkNotNull(notificationContent);
-        Preconditions.checkNotNull(eventTime);
+        requireNonNull(notificationContent);
+        requireNonNull(eventTime);
 
         final Element baseNotification = notificationContent.getDocumentElement();
         final Element entireNotification = notificationContent.createElementNS(NOTIFICATION_NAMESPACE, NOTIFICATION);
index 3154b370f42024c5ee9ff43445427685bad4ec61..3db43872191ddc94077f49cedf1894759776e363 100644 (file)
@@ -7,7 +7,8 @@
  */
 package org.opendaylight.netconf.util;
 
-import com.google.common.base.Preconditions;
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
 import java.util.Collection;
@@ -43,7 +44,7 @@ public final class NodeContainerProxy implements ContainerSchemaNode {
     public NodeContainerProxy(final QName qualifiedName, final Map<QName, DataSchemaNode> childNodes,
                               final Set<AugmentationSchemaNode> availableAugmentations) {
         this.availableAugmentations = availableAugmentations;
-        this.childNodes = Preconditions.checkNotNull(childNodes, "childNodes");
+        this.childNodes = requireNonNull(childNodes, "childNodes");
         this.qualifiedName = qualifiedName;
     }
 
index e21820839cae162070720f615ea4026c88a649a9..2d7737af27bdaf85c601dc73cb040810f734a182 100644 (file)
@@ -5,10 +5,10 @@
  * 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.util.test;
 
-import com.google.common.base.Preconditions;
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.io.ByteSource;
 import java.io.IOException;
 import java.io.InputStream;
@@ -21,7 +21,6 @@ import org.w3c.dom.Element;
 import org.xml.sax.SAXException;
 
 public final class XmlFileLoader {
-
     private XmlFileLoader() {
 
     }
@@ -44,7 +43,7 @@ public final class XmlFileLoader {
     public static Document xmlFileToDocument(final String fileName) throws IOException, SAXException,
             ParserConfigurationException {
         try (InputStream resourceAsStream = XmlFileLoader.class.getClassLoader().getResourceAsStream(fileName)) {
-            Preconditions.checkNotNull(resourceAsStream, fileName);
+            requireNonNull(resourceAsStream, fileName);
             final Document doc = XmlUtil.readXmlToDocument(resourceAsStream);
             return doc;
         }
@@ -52,7 +51,7 @@ public final class XmlFileLoader {
 
     public static String fileToString(final String fileName) throws IOException {
         try (InputStream resourceAsStream = XmlFileLoader.class.getClassLoader().getResourceAsStream(fileName)) {
-            Preconditions.checkNotNull(resourceAsStream);
+            requireNonNull(resourceAsStream);
             return new ByteSource() {
                 @Override
                 public InputStream openStream() {
index e217eec8f17e9827f472c61be61515a05a3b3dc7..8874abb0a7b7cdfd83a64effab4452c5f0e29d45 100644 (file)
@@ -8,7 +8,8 @@
 
 package org.opendaylight.netconf.sal.connect.netconf;
 
-import com.google.common.base.Preconditions;
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.collect.ClassToInstanceMap;
 import com.google.common.collect.ImmutableClassToInstanceMap;
 import com.google.common.util.concurrent.Futures;
@@ -47,9 +48,9 @@ public class DeviceActionFactoryImpl implements DeviceActionFactory {
             @Override
             public ListenableFuture<? extends DOMActionResult> invokeAction(final SchemaPath schemaPath,
                     final DOMDataTreeIdentifier dataTreeIdentifier, final ContainerNode input) {
-                Preconditions.checkNotNull(schemaPath);
-                Preconditions.checkNotNull(dataTreeIdentifier);
-                Preconditions.checkNotNull(input);
+                requireNonNull(schemaPath);
+                requireNonNull(dataTreeIdentifier);
+                requireNonNull(input);
 
                 final ListenableFuture<RpcResult<NetconfMessage>> actionResultFuture = listener.sendRequest(
                         messageTransformer.toActionRequest(schemaPath, dataTreeIdentifier, input), input.getNodeType());
index 9d262568e95853a71f391316ed8547e93ea7186b..7ed01542597ce229f21b5bb78ba6334cc67f634d 100644 (file)
@@ -5,10 +5,10 @@
  * 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.sal.connect.netconf;
 
-import com.google.common.base.Preconditions;
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.util.concurrent.ListeningExecutorService;
 import io.netty.util.concurrent.EventExecutor;
 import org.opendaylight.netconf.sal.connect.api.DeviceActionFactory;
@@ -86,9 +86,9 @@ public class NetconfDeviceBuilder {
     }
 
     private void validation() {
-        Preconditions.checkNotNull(this.id, "RemoteDeviceId is not initialized");
-        Preconditions.checkNotNull(this.salFacade, "RemoteDeviceHandler is not initialized");
-        Preconditions.checkNotNull(this.globalProcessingExecutor, "ExecutorService is not initialized");
-        Preconditions.checkNotNull(this.schemaResourcesDTO, "SchemaResourceDTO is not initialized");
+        requireNonNull(this.id, "RemoteDeviceId is not initialized");
+        requireNonNull(this.salFacade, "RemoteDeviceHandler is not initialized");
+        requireNonNull(this.globalProcessingExecutor, "ExecutorService is not initialized");
+        requireNonNull(this.schemaResourcesDTO, "SchemaResourceDTO is not initialized");
     }
 }
index cf8d0aefb1558d56d6e2a65cb2ce52289319ac73..ce63849affb1a01b101d0386ee0d68880301b233 100644 (file)
@@ -7,7 +7,10 @@
  */
 package org.opendaylight.netconf.sal.connect.netconf;
 
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Preconditions.checkState;
+import static java.util.Objects.requireNonNull;
+
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Optional;
@@ -36,8 +39,8 @@ final class NotificationHandler {
     private MessageTransformer<NetconfMessage> messageTransformer;
 
     NotificationHandler(final RemoteDeviceHandler<?> salFacade, final RemoteDeviceId id) {
-        this.salFacade = Preconditions.checkNotNull(salFacade);
-        this.id = Preconditions.checkNotNull(id);
+        this.salFacade = requireNonNull(salFacade);
+        this.id = requireNonNull(id);
     }
 
     synchronized void handleNotification(final NetconfMessage notification) {
@@ -53,7 +56,7 @@ final class NotificationHandler {
      * @param transformer Message transformer
      */
     synchronized void onRemoteSchemaUp(final MessageTransformer<NetconfMessage> transformer) {
-        this.messageTransformer = Preconditions.checkNotNull(transformer);
+        this.messageTransformer = requireNonNull(transformer);
 
         passNotifications = true;
 
@@ -65,14 +68,12 @@ final class NotificationHandler {
     }
 
     private DOMNotification transformNotification(final NetconfMessage cachedNotification) {
-        final DOMNotification parsedNotification = messageTransformer.toNotification(cachedNotification);
-        Preconditions.checkNotNull(
-                parsedNotification, "%s: Unable to parse received notification: %s", id, cachedNotification);
-        return parsedNotification;
+        return checkNotNull(messageTransformer.toNotification(cachedNotification),
+            "%s: Unable to parse received notification: %s", id, cachedNotification);
     }
 
     private void queueNotification(final NetconfMessage notification) {
-        Preconditions.checkState(!passNotifications);
+        checkState(!passNotifications);
 
         LOG.debug("{}: Caching notification {}, remote schema not yet fully built", id, notification);
         if (LOG.isTraceEnabled()) {
index dcff0f294b65791c5394fac8d13ead94913c8b02..341d30220081180f51e654dc41e718446633d476 100644 (file)
@@ -5,12 +5,12 @@
  * 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.sal.connect.netconf.listener;
 
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.base.MoreObjects;
 import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
 import com.google.common.base.Predicate;
 import com.google.common.base.Splitter;
 import com.google.common.base.Strings;
@@ -63,8 +63,8 @@ public final class NetconfSessionPreferences {
 
     NetconfSessionPreferences(final Map<String, CapabilityOrigin> nonModuleCaps,
                               final Map<QName, CapabilityOrigin> moduleBasedCaps) {
-        this.nonModuleCaps = Preconditions.checkNotNull(nonModuleCaps);
-        this.moduleBasedCaps = Preconditions.checkNotNull(moduleBasedCaps);
+        this.nonModuleCaps = requireNonNull(nonModuleCaps);
+        this.moduleBasedCaps = requireNonNull(moduleBasedCaps);
     }
 
     public Set<QName> getModuleBasedCaps() {
index 7b578a35dcd980aa8c4cdba5991ad651dac9f306..d6b6354a3ece4476c4803beb92a739ea20486e9b 100644 (file)
@@ -7,7 +7,10 @@
  */
 package org.opendaylight.netconf.sal.connect.netconf.sal;
 
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Preconditions.checkState;
+import static java.util.Objects.requireNonNull;
+
 import org.opendaylight.mdsal.binding.api.DataBroker;
 import org.opendaylight.mdsal.binding.api.Transaction;
 import org.opendaylight.mdsal.binding.api.TransactionChain;
@@ -63,25 +66,25 @@ public class NetconfDeviceSalProvider implements AutoCloseable {
         mountInstance = new MountInstance(mountService, id);
         this.dataBroker = dataBroker;
         if (dataBroker != null) {
-            txChain = Preconditions.checkNotNull(dataBroker).createTransactionChain(transactionChainListener);
+            txChain = requireNonNull(dataBroker).createTransactionChain(transactionChainListener);
             topologyDatastoreAdapter = new NetconfDeviceTopologyAdapter(id, txChain);
         }
     }
 
     public MountInstance getMountInstance() {
-        Preconditions.checkState(mountInstance != null,
-                "%s: Mount instance was not initialized by sal. Cannot get mount instance", id);
+        checkState(mountInstance != null, "%s: Mount instance was not initialized by sal. Cannot get mount instance",
+                id);
         return mountInstance;
     }
 
     public NetconfDeviceTopologyAdapter getTopologyDatastoreAdapter() {
-        Preconditions.checkState(topologyDatastoreAdapter != null,
+        checkState(topologyDatastoreAdapter != null,
                 "%s: Sal provider %s was not initialized by sal. Cannot get topology datastore adapter", id);
         return topologyDatastoreAdapter;
     }
 
     private void resetTransactionChainForAdapaters() {
-        txChain = Preconditions.checkNotNull(dataBroker).createTransactionChain(transactionChainListener);
+        txChain = requireNonNull(dataBroker).createTransactionChain(transactionChainListener);
 
         topologyDatastoreAdapter.setTxChain(txChain);
 
@@ -110,8 +113,8 @@ public class NetconfDeviceSalProvider implements AutoCloseable {
         private ObjectRegistration<DOMMountPoint> topologyRegistration;
 
         MountInstance(final DOMMountPointService mountService, final RemoteDeviceId id) {
-            this.mountService = Preconditions.checkNotNull(mountService);
-            this.id = Preconditions.checkNotNull(id);
+            this.mountService = requireNonNull(mountService);
+            this.id = requireNonNull(id);
         }
 
         public void onTopologyDeviceConnected(final SchemaContext initialCtx,
@@ -123,8 +126,8 @@ public class NetconfDeviceSalProvider implements AutoCloseable {
         public synchronized void onTopologyDeviceConnected(final SchemaContext initialCtx,
                 final DOMDataBroker broker, final DOMRpcService rpc,
                 final NetconfDeviceNotificationService newNotificationService, final DOMActionService deviceAction) {
-            Preconditions.checkNotNull(mountService, "Closed");
-            Preconditions.checkState(topologyRegistration == null, "Already initialized");
+            requireNonNull(mountService, "Closed");
+            checkState(topologyRegistration == null, "Already initialized");
 
             final DOMMountPointService.DOMMountPointBuilder mountBuilder =
                     mountService.createMountPoint(id.getTopologyPath());
@@ -166,9 +169,8 @@ public class NetconfDeviceSalProvider implements AutoCloseable {
         }
 
         public synchronized void publish(final DOMNotification domNotification) {
-            Preconditions.checkNotNull(notificationService, "Device not set up yet, cannot handle notification {}",
-                    domNotification);
-            notificationService.publishNotification(domNotification);
+            checkNotNull(notificationService, "Device not set up yet, cannot handle notification %s", domNotification)
+                .publishNotification(domNotification);
         }
     }
 
index 202517fb14d5c98b9950f016dacac6d6190ab494..d945986b44dfd90717d41a4cc99b65c1c2bb4335 100644 (file)
@@ -7,7 +7,8 @@
  */
 package org.opendaylight.netconf.sal.connect.netconf.sal;
 
-import com.google.common.base.Preconditions;
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.MoreExecutors;
 import java.util.ArrayList;
@@ -62,7 +63,7 @@ public class NetconfDeviceTopologyAdapter implements AutoCloseable {
 
     NetconfDeviceTopologyAdapter(final RemoteDeviceId id, final TransactionChain txChain) {
         this.id = id;
-        this.txChain = Preconditions.checkNotNull(txChain);
+        this.txChain = requireNonNull(txChain);
 
         this.networkTopologyPath = InstanceIdentifier.builder(NetworkTopology.class).build();
         this.topologyListPath = networkTopologyPath
@@ -266,6 +267,6 @@ public class NetconfDeviceTopologyAdapter implements AutoCloseable {
     }
 
     public void setTxChain(final TransactionChain txChain) {
-        this.txChain = Preconditions.checkNotNull(txChain);
+        this.txChain = requireNonNull(txChain);
     }
 }
index ecbe6fa6a929af59a6b46ad36291066a7b65def1..01dc488bb32dfb6f29f6a6091738e31693c3d9bf 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.netconf.sal.connect.netconf.util;
 
+import static com.google.common.base.Preconditions.checkArgument;
+import static java.util.Objects.requireNonNull;
 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.EDIT_CONTENT_NODEID;
 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_CANDIDATE_QNAME;
 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.NETCONF_COPY_CONFIG_NODEID;
@@ -32,7 +34,6 @@ import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTr
 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.toFilterStructure;
 import static org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil.toId;
 
-import com.google.common.base.Preconditions;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
@@ -83,8 +84,8 @@ public final class NetconfBaseOps {
     }
 
     public ListenableFuture<DOMRpcResult> lock(final FutureCallback<DOMRpcResult> callback, final QName datastore) {
-        Preconditions.checkNotNull(callback);
-        Preconditions.checkNotNull(datastore);
+        requireNonNull(callback);
+        requireNonNull(datastore);
 
         final ListenableFuture<DOMRpcResult> future = rpc.invokeRpc(NETCONF_LOCK_PATH, getLockContent(datastore));
         Futures.addCallback(future, callback, MoreExecutors.directExecutor());
@@ -106,8 +107,8 @@ public final class NetconfBaseOps {
     }
 
     public ListenableFuture<DOMRpcResult> unlock(final FutureCallback<DOMRpcResult> callback, final QName datastore) {
-        Preconditions.checkNotNull(callback);
-        Preconditions.checkNotNull(datastore);
+        requireNonNull(callback);
+        requireNonNull(datastore);
 
         final ListenableFuture<DOMRpcResult> future = rpc.invokeRpc(NETCONF_UNLOCK_PATH, getUnLockContent(datastore));
         Futures.addCallback(future, callback, MoreExecutors.directExecutor());
@@ -129,7 +130,7 @@ public final class NetconfBaseOps {
     }
 
     public ListenableFuture<DOMRpcResult> discardChanges(final FutureCallback<DOMRpcResult> callback) {
-        Preconditions.checkNotNull(callback);
+        requireNonNull(callback);
 
         final ListenableFuture<DOMRpcResult> future = rpc.invokeRpc(NETCONF_DISCARD_CHANGES_PATH, null);
         Futures.addCallback(future, callback, MoreExecutors.directExecutor());
@@ -137,7 +138,7 @@ public final class NetconfBaseOps {
     }
 
     public ListenableFuture<DOMRpcResult> commit(final FutureCallback<DOMRpcResult> callback) {
-        Preconditions.checkNotNull(callback);
+        requireNonNull(callback);
 
         final ListenableFuture<DOMRpcResult> future = rpc.invokeRpc(NetconfMessageTransformUtil.NETCONF_COMMIT_PATH,
             NetconfMessageTransformUtil.COMMIT_RPC_CONTENT);
@@ -146,11 +147,10 @@ public final class NetconfBaseOps {
     }
 
     public ListenableFuture<DOMRpcResult> validate(final FutureCallback<DOMRpcResult> callback, final QName datastore) {
-        Preconditions.checkNotNull(callback);
-        Preconditions.checkNotNull(datastore);
+        requireNonNull(callback);
 
         final ListenableFuture<DOMRpcResult> future = rpc.invokeRpc(NetconfMessageTransformUtil.NETCONF_VALIDATE_PATH,
-            getValidateContent(datastore));
+            getValidateContent(requireNonNull(datastore)));
         Futures.addCallback(future, callback, MoreExecutors.directExecutor());
         return future;
     }
@@ -165,12 +165,10 @@ public final class NetconfBaseOps {
 
     public ListenableFuture<DOMRpcResult> copyConfig(final FutureCallback<DOMRpcResult> callback,
                                                      final QName source, final QName target) {
-        Preconditions.checkNotNull(callback);
-        Preconditions.checkNotNull(source);
-        Preconditions.checkNotNull(target);
+        requireNonNull(callback);
 
         final ListenableFuture<DOMRpcResult> future = rpc.invokeRpc(NETCONF_COPY_CONFIG_PATH,
-            getCopyConfigContent(source, target));
+            getCopyConfigContent(requireNonNull(source), requireNonNull(target)));
         Futures.addCallback(future, callback, MoreExecutors.directExecutor());
         return future;
     }
@@ -181,8 +179,8 @@ public final class NetconfBaseOps {
 
     public ListenableFuture<DOMRpcResult> getConfig(final FutureCallback<DOMRpcResult> callback, final QName datastore,
                                                     final Optional<YangInstanceIdentifier> filterPath) {
-        Preconditions.checkNotNull(callback);
-        Preconditions.checkNotNull(datastore);
+        requireNonNull(callback);
+        requireNonNull(datastore);
 
         final ListenableFuture<DOMRpcResult> future;
         if (isFilterPresent(filterPath)) {
@@ -213,7 +211,7 @@ public final class NetconfBaseOps {
     private ListenableFuture<Optional<NormalizedNode<?, ?>>> extractData(
             final Optional<YangInstanceIdentifier> path, final ListenableFuture<DOMRpcResult> configRunning) {
         return Futures.transform(configRunning, result -> {
-            Preconditions.checkArgument(result.getErrors().isEmpty(), "Unable to read data: %s, errors: %s", path,
+            checkArgument(result.getErrors().isEmpty(), "Unable to read data: %s, errors: %s", path,
                 result.getErrors());
             final DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?> dataNode =
                     ((ContainerNode) result.getResult()).getChild(NetconfMessageTransformUtil.NETCONF_DATA_NODEID)
@@ -234,7 +232,7 @@ public final class NetconfBaseOps {
 
     public ListenableFuture<DOMRpcResult> get(final FutureCallback<DOMRpcResult> callback,
                                               final Optional<YangInstanceIdentifier> filterPath) {
-        Preconditions.checkNotNull(callback);
+        requireNonNull(callback);
 
         final ListenableFuture<DOMRpcResult> future = rpc.invokeRpc(NETCONF_GET_PATH, isFilterPresent(filterPath)
             ? NetconfMessageTransformUtil.wrap(NETCONF_GET_NODEID, toFilterStructure(filterPath.get(), schemaContext))
@@ -275,12 +273,10 @@ public final class NetconfBaseOps {
             final FutureCallback<? super DOMRpcResult> callback, final QName datastore,
             final DataContainerChild<?, ?> editStructure, final Optional<ModifyAction> modifyAction,
             final boolean rollback) {
-        Preconditions.checkNotNull(editStructure);
-        Preconditions.checkNotNull(callback);
-        Preconditions.checkNotNull(datastore);
+        requireNonNull(callback);
 
         final ListenableFuture<DOMRpcResult> future = rpc.invokeRpc(NETCONF_EDIT_CONFIG_PATH,
-                getEditConfigContent(datastore, editStructure, modifyAction, rollback));
+                getEditConfigContent(requireNonNull(datastore), requireNonNull(editStructure), modifyAction, rollback));
 
         Futures.addCallback(future, callback, MoreExecutors.directExecutor());
         return future;
index 6499f54dd01c0b800f4b424ca98f8f0e05b0d45e..98eeb7d9fe97b5f2c82a5fd07e1188f2d207b329 100644 (file)
@@ -7,8 +7,9 @@
  */
 package org.opendaylight.netconf.sal.connect.util;
 
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Preconditions;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.MoreExecutors;
@@ -56,9 +57,9 @@ public class NetconfTopologyRPCProvider implements NetconfNodeTopologyService {
                                       final AAAEncryptionService encryptionService,
                                       final String topologyId) {
         this.dataBroker = dataBroker;
-        this.encryptionService = Preconditions.checkNotNull(encryptionService);
+        this.encryptionService = requireNonNull(encryptionService);
         this.topologyPath = InstanceIdentifier.builder(NetworkTopology.class)
-                .child(Topology.class, new TopologyKey(new TopologyId(Preconditions.checkNotNull(topologyId)))).build();
+                .child(Topology.class, new TopologyKey(new TopologyId(requireNonNull(topologyId)))).build();
     }
 
     @Override
index 796ec2f8ba052f4d132e7cf0e1ce96bfce5917b3..39b4f9bf9ca1bd388ac6b2ac24aedac99710b5de 100644 (file)
@@ -7,7 +7,8 @@
  */
 package org.opendaylight.netconf.sal.connect.util;
 
-import com.google.common.base.Preconditions;
+import static java.util.Objects.requireNonNull;
+
 import java.net.InetSocketAddress;
 import java.util.Objects;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Host;
@@ -46,7 +47,7 @@ public final class RemoteDeviceId {
     private Host host;
 
     private RemoteDeviceId(final String name) {
-        this.name = Preconditions.checkNotNull(name);
+        this.name = requireNonNull(name);
         this.topologyPath = DEFAULT_TOPOLOGY_NODE
                 .node(NodeIdentifierWithPredicates.of(Node.QNAME, NODE_ID_QNAME, name));
         this.key = new NodeKey(new NodeId(name));