Apply modernizations 30/84930/2
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 6 Oct 2019 16:41:47 +0000 (18:41 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 7 Oct 2019 05:59:48 +0000 (07:59 +0200)
Replace Guava constructs with their Java 8 equivalents.

Change-Id: Idfba9bbba34620fa9d40d611f76632b28dbf55eb
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/mdsal-netconf-ssh/src/main/java/org/opendaylight/netconf/ssh/RemoteNetconfCommand.java
netconf/mdsal-netconf-ssh/src/main/java/org/opendaylight/netconf/ssh/SshProxyServerConfiguration.java
netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/ConnectionNotificationTopicRegistration.java
netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSource.java
netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceManager.java
netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceRegistration.java
netconf/yanglib/src/main/java/org/opendaylight/yanglib/impl/YangLibServiceImpl.java
restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/patch/PatchContext.java
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/FakeImportedModule.java
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/streams/listeners/AbstractQueryParams.java
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/streams/listeners/NotificationListenerAdapter.java

index 36313786b16b82552822c193d5b3ed9a06609375..b342bf7fd7a03874c962258d3ba18536d1b9a59c 100644 (file)
@@ -7,7 +7,8 @@
  */
 package org.opendaylight.netconf.ssh;
 
-import com.google.common.base.Preconditions;
+import static java.util.Objects.requireNonNull;
+
 import io.netty.bootstrap.Bootstrap;
 import io.netty.channel.Channel;
 import io.netty.channel.ChannelFuture;
@@ -122,9 +123,8 @@ public class RemoteNetconfCommand implements AsyncCommand, SessionAware {
             } else {
                 LOG.warn("Unable to establish internal connection to netconf server for client: {}",
                         getClientAddress());
-                Preconditions.checkNotNull(callback, "Exit callback must be set");
-                callback.onExit(1, "Unable to establish internal connection to netconf server for client: "
-                        + getClientAddress());
+                requireNonNull(callback, "Exit callback must be set").onExit(1,
+                    "Unable to establish internal connection to netconf server for client: " + getClientAddress());
             }
         });
     }
index 16ecfc536920e43a5e1741cb9c33dbfba06e0f42..12d56568064d1c44635972f262b0491819344407 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.ssh;
 
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkArgument;
+import static java.util.Objects.requireNonNull;
+
 import io.netty.channel.local.LocalAddress;
 import java.net.InetSocketAddress;
 import java.util.Optional;
@@ -27,12 +28,12 @@ public final class SshProxyServerConfiguration {
     SshProxyServerConfiguration(final InetSocketAddress bindingAddress, final LocalAddress localAddress,
                                 final AuthProvider authenticator, final PublickeyAuthenticator publickeyAuthenticator,
                                 final KeyPairProvider keyPairProvider, final int idleTimeout) {
-        this.bindingAddress = Preconditions.checkNotNull(bindingAddress);
-        this.localAddress = Preconditions.checkNotNull(localAddress);
-        this.authenticator = Preconditions.checkNotNull(authenticator);
-        this.keyPairProvider = Preconditions.checkNotNull(keyPairProvider);
+        this.bindingAddress = requireNonNull(bindingAddress);
+        this.localAddress = requireNonNull(localAddress);
+        this.authenticator = requireNonNull(authenticator);
+        this.keyPairProvider = requireNonNull(keyPairProvider);
         // Idle timeout cannot be disabled in the sshd by using =< 0 value
-        Preconditions.checkArgument(idleTimeout > 0, "Idle timeout has to be > 0");
+        checkArgument(idleTimeout > 0, "Idle timeout has to be > 0");
         this.idleTimeout = idleTimeout;
         this.publickeyAuthenticator = Optional.ofNullable(publickeyAuthenticator);
     }
index acf72e79186548d4a055032366fb6acf0dd9b203..ba61ce67181b06622f29166e756afda3282b5800 100644 (file)
@@ -7,7 +7,8 @@
  */
 package org.opendaylight.netconf.messagebus.eventsources.netconf;
 
-import com.google.common.base.Preconditions;
+import static java.util.Objects.requireNonNull;
+
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Optional;
@@ -50,7 +51,7 @@ class ConnectionNotificationTopicRegistration extends NotificationTopicRegistrat
                                             final DOMNotificationListener domNotificationListener) {
         super(NotificationSourceType.ConnectionStatusChange, sourceName,
                 EVENT_SOURCE_STATUS_PATH.getLastComponent().getNamespace().toString());
-        this.domNotificationListener = Preconditions.checkNotNull(domNotificationListener);
+        this.domNotificationListener = requireNonNull(domNotificationListener);
         LOG.info("Connection notification source has been initialized.");
         setActive(true);
         setReplaySupported(false);
index c4f8d406d748aa55f1f8d795bb32586135619a1f..b0362de2209401303d92431e0d0a3a9c53f02326 100644 (file)
@@ -8,8 +8,8 @@
 package org.opendaylight.netconf.messagebus.eventsources.netconf;
 
 import static com.google.common.util.concurrent.Futures.immediateFuture;
+import static java.util.Objects.requireNonNull;
 
-import com.google.common.base.Preconditions;
 import com.google.common.collect.ArrayListMultimap;
 import com.google.common.collect.Maps;
 import com.google.common.collect.Multimap;
@@ -106,8 +106,8 @@ public class NetconfEventSource implements EventSource, DOMNotificationListener
                               final NetconfEventSourceMount mount,
                               final DOMNotificationPublishService publishService) {
         this.mount = mount;
-        this.urnPrefixToStreamMap = Preconditions.checkNotNull(streamMap);
-        this.domPublish = Preconditions.checkNotNull(publishService);
+        this.urnPrefixToStreamMap = requireNonNull(streamMap);
+        this.domPublish = requireNonNull(publishService);
         this.initializeNotificationTopicRegistrationList();
 
         LOG.info("NetconfEventSource [{}] created.", mount.getNodeId());
@@ -169,7 +169,7 @@ public class NetconfEventSource implements EventSource, DOMNotificationListener
     private synchronized ListenableFuture<RpcResult<JoinTopicOutput>> registerTopic(
             final TopicId topicId,
             final List<SchemaPath> notificationsToSubscribe) {
-        Preconditions.checkNotNull(notificationsToSubscribe);
+        requireNonNull(notificationsToSubscribe);
         LOG.debug("Join topic {} - register", topicId);
         JoinTopicStatus joinTopicStatus = JoinTopicStatus.Down;
 
index 4877a735b14edbc1e16c0931ff52a511f85a7c8f..46331c54c36498a89798cc90394f1222a744f6e9 100644 (file)
@@ -7,7 +7,9 @@
  */
 package org.opendaylight.netconf.messagebus.eventsources.netconf;
 
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Verify.verifyNotNull;
+import static java.util.Objects.requireNonNull;
+
 import java.util.Collection;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
@@ -57,22 +59,17 @@ public final class NetconfEventSourceManager implements DataTreeChangeListener<N
                                      final DOMNotificationPublishService domPublish,
                                      final DOMMountPointService domMount,
                                      final EventSourceRegistry eventSourceRegistry) {
-        Preconditions.checkNotNull(dataBroker);
-        Preconditions.checkNotNull(domPublish);
-        Preconditions.checkNotNull(domMount);
-        Preconditions.checkNotNull(eventSourceRegistry);
-        this.dataBroker = dataBroker;
-        this.domMounts = domMount;
-        this.publishService = domPublish;
-        this.eventSourceRegistry = eventSourceRegistry;
+        this.dataBroker = requireNonNull(dataBroker);
+        this.domMounts = requireNonNull(domMount);
+        this.publishService = requireNonNull(domPublish);
+        this.eventSourceRegistry = requireNonNull(eventSourceRegistry);
     }
 
     /**
      * Invoked by blueprint.
      */
     public void initialize() {
-        Preconditions.checkNotNull(dataBroker);
-        listenerRegistration = dataBroker.registerDataTreeChangeListener(DataTreeIdentifier.create(
+        listenerRegistration = verifyNotNull(dataBroker).registerDataTreeChangeListener(DataTreeIdentifier.create(
                 LogicalDatastoreType.OPERATIONAL, NETCONF_DEVICE_PATH), this);
         LOG.info("NetconfEventSourceManager initialized.");
     }
@@ -98,13 +95,12 @@ public final class NetconfEventSourceManager implements DataTreeChangeListener<N
     }
 
     private void nodeCreated(final InstanceIdentifier<?> key, final Node node) {
-        Preconditions.checkNotNull(key);
         if (!validateNode(node)) {
-            LOG.warn("NodeCreated event : Node [{}] is null or not valid.", key.toString());
+            LOG.warn("NodeCreated event : Node [{}] is null or not valid.", key);
             return;
         }
-        LOG.info("Netconf event source [{}] is creating...", key.toString());
-        NetconfEventSourceRegistration nesr = NetconfEventSourceRegistration.create(key, node, this);
+        LOG.info("Netconf event source [{}] is creating...", key);
+        NetconfEventSourceRegistration nesr = NetconfEventSourceRegistration.create(requireNonNull(key), node, this);
         if (nesr != null) {
             NetconfEventSourceRegistration nesrOld = registrationMap.put(key, nesr);
             if (nesrOld != null) {
@@ -114,9 +110,8 @@ public final class NetconfEventSourceManager implements DataTreeChangeListener<N
     }
 
     private void nodeRemoved(final InstanceIdentifier<?> key) {
-        Preconditions.checkNotNull(key);
-        LOG.info("Netconf event source [{}] is removing...", key.toString());
-        NetconfEventSourceRegistration nesr = registrationMap.remove(key);
+        LOG.info("Netconf event source [{}] is removing...", key);
+        NetconfEventSourceRegistration nesr = registrationMap.remove(requireNonNull(key));
         if (nesr != null) {
             nesr.close();
         }
index 2ae032288b8901207c5858ed75aaec3d342ad778..34848b94c3dc3cb6eeb4eee257d139f02863e87a 100644 (file)
@@ -7,7 +7,9 @@
  */
 package org.opendaylight.netconf.messagebus.eventsources.netconf;
 
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkState;
+import static java.util.Objects.requireNonNull;
+
 import java.util.List;
 import java.util.Optional;
 import org.opendaylight.controller.messagebus.spi.EventSourceRegistration;
@@ -47,9 +49,9 @@ public final class NetconfEventSourceRegistration implements AutoCloseable {
 
     public static NetconfEventSourceRegistration create(final InstanceIdentifier<?> instanceIdent, final Node node,
                                                         final NetconfEventSourceManager netconfEventSourceManager) {
-        Preconditions.checkNotNull(instanceIdent);
-        Preconditions.checkNotNull(node);
-        Preconditions.checkNotNull(netconfEventSourceManager);
+        requireNonNull(instanceIdent);
+        requireNonNull(node);
+        requireNonNull(netconfEventSourceManager);
         if (!isEventSource(node)) {
             return null;
         }
@@ -110,8 +112,8 @@ public final class NetconfEventSourceRegistration implements AutoCloseable {
     }
 
     private void changeStatus(final ConnectionStatus newStatus) {
-        Preconditions.checkNotNull(newStatus);
-        Preconditions.checkState(this.currentNetconfConnStatus != null);
+        requireNonNull(newStatus);
+        checkState(this.currentNetconfConnStatus != null);
         if (!checkConnectionStatusType(newStatus)) {
             throw new IllegalStateException("Unknown new Netconf Connection Status");
         }
index d856ac7bdb5f62b083602d4a449d8cbbea4a46f6..185f1ea3863bd2cbd6a40af8e90b6d00cbfa9aeb 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.yanglib.impl;
 
-import com.google.common.base.Preconditions;
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.io.ByteStreams;
 import com.google.common.util.concurrent.ListenableFuture;
 import java.io.IOException;
@@ -32,12 +32,11 @@ public class YangLibServiceImpl implements YangLibService {
     private final SchemaRepository schemaRepository;
 
     public YangLibServiceImpl(final SchemaRepository schemaRepository) {
-        this.schemaRepository = schemaRepository;
+        this.schemaRepository = requireNonNull(schemaRepository);
     }
 
     @Override
     public String getSchema(final String name, final String revision) {
-        Preconditions.checkNotNull(schemaRepository, "Schema repository is not initialized");
         LOG.debug("Attempting load for schema source {}:{}", name, revision);
         final SourceIdentifier sourceId = RevisionSourceIdentifier.create(name,
             revision.isEmpty() ? null : Revision.of(revision));
index 5e867c0838a995f275ba3275b786ea8054e3ecf3..bf1c7a2c32e0080b8afe68c2fb5e7360d28af27e 100644 (file)
@@ -5,25 +5,24 @@
  * 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.restconf.common.patch;
 
-import com.google.common.base.Preconditions;
+import static java.util.Objects.requireNonNull;
+
 import java.util.List;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
 
 public class PatchContext {
-
     private final InstanceIdentifierContext<? extends SchemaNode> context;
     private final List<PatchEntity> data;
     private final String patchId;
 
     public PatchContext(final InstanceIdentifierContext<? extends SchemaNode> context,
                         final List<PatchEntity> data, final String patchId) {
-        this.context = Preconditions.checkNotNull(context);
-        this.data = Preconditions.checkNotNull(data);
-        this.patchId = Preconditions.checkNotNull(patchId);
+        this.context = requireNonNull(context);
+        this.data = requireNonNull(data);
+        this.patchId = requireNonNull(patchId);
     }
 
     public InstanceIdentifierContext<? extends SchemaNode> getInstanceIdentifierContext() {
index d5d43e7af0442f39cf9496da1d516864a98524d0..85ea4e41165749307e1529c0472dfa4a8b6ef53a 100644 (file)
@@ -7,7 +7,8 @@
  */
 package org.opendaylight.netconf.sal.restconf.impl;
 
-import com.google.common.base.Preconditions;
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.collect.ForwardingObject;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
@@ -41,7 +42,7 @@ final class FakeImportedModule extends ForwardingObject implements Module {
     private final Module delegate;
 
     FakeImportedModule(final Module delegate) {
-        this.delegate = Preconditions.checkNotNull(delegate);
+        this.delegate = requireNonNull(delegate);
     }
 
     @Override
index 40770f2732f5a08467e3158b91bcd1c1eea88f40..4327578d87db207b49eda14ad54662faa1d63cdb 100644 (file)
@@ -7,8 +7,9 @@
  */
 package org.opendaylight.netconf.sal.streams.listeners;
 
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Preconditions;
 import java.io.StringReader;
 import java.time.Instant;
 import java.util.Optional;
@@ -74,7 +75,7 @@ abstract class AbstractQueryParams extends AbstractNotificationsData {
     @SuppressWarnings("checkstyle:hiddenField")
     public void setQueryParams(final Instant start, final Optional<Instant> stop, final Optional<String> filter,
                                final boolean leafNodesOnly) {
-        this.start = Preconditions.checkNotNull(start);
+        this.start = requireNonNull(start);
         this.stop = stop.orElse(null);
         this.filter = filter.orElse(null);
         this.leafNodesOnly = leafNodesOnly;
index c131237cb7e11d75ce3c988f89c110814f14fc5e..2f1da2b09cf5605e4adf5f0eb99a6cf0247edebe 100644 (file)
@@ -7,8 +7,10 @@
  */
 package org.opendaylight.netconf.sal.streams.listeners;
 
+import static com.google.common.base.Preconditions.checkArgument;
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Preconditions;
 import com.google.gson.JsonObject;
 import com.google.gson.JsonParser;
 import java.io.IOException;
@@ -61,9 +63,9 @@ public class NotificationListenerAdapter extends AbstractCommonSubscriber implem
     NotificationListenerAdapter(final SchemaPath path, final String streamName, final String outputType,
             final ControllerContext controllerContext) {
         register(this);
-        this.outputType = Preconditions.checkNotNull(outputType);
-        this.path = Preconditions.checkNotNull(path);
-        Preconditions.checkArgument(streamName != null && !streamName.isEmpty());
+        this.outputType = requireNonNull(outputType);
+        this.path = requireNonNull(path);
+        checkArgument(streamName != null && !streamName.isEmpty());
         this.streamName = streamName;
         this.controllerContext = controllerContext;
     }