From 64489187dfaa2fb9947da41b35727fef248a1a0d Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Sun, 6 Oct 2019 18:41:47 +0200 Subject: [PATCH] Apply modernizations Replace Guava constructs with their Java 8 equivalents. Change-Id: Idfba9bbba34620fa9d40d611f76632b28dbf55eb Signed-off-by: Robert Varga --- .../netconf/ssh/RemoteNetconfCommand.java | 8 ++--- .../ssh/SshProxyServerConfiguration.java | 15 ++++----- ...nnectionNotificationTopicRegistration.java | 5 +-- .../netconf/NetconfEventSource.java | 8 ++--- .../netconf/NetconfEventSourceManager.java | 31 ++++++++----------- .../NetconfEventSourceRegistration.java | 14 +++++---- .../yanglib/impl/YangLibServiceImpl.java | 7 ++--- .../restconf/common/patch/PatchContext.java | 11 +++---- .../sal/restconf/impl/FakeImportedModule.java | 5 +-- .../listeners/AbstractQueryParams.java | 5 +-- .../NotificationListenerAdapter.java | 10 +++--- 11 files changed, 60 insertions(+), 59 deletions(-) diff --git a/netconf/mdsal-netconf-ssh/src/main/java/org/opendaylight/netconf/ssh/RemoteNetconfCommand.java b/netconf/mdsal-netconf-ssh/src/main/java/org/opendaylight/netconf/ssh/RemoteNetconfCommand.java index 36313786b1..b342bf7fd7 100644 --- a/netconf/mdsal-netconf-ssh/src/main/java/org/opendaylight/netconf/ssh/RemoteNetconfCommand.java +++ b/netconf/mdsal-netconf-ssh/src/main/java/org/opendaylight/netconf/ssh/RemoteNetconfCommand.java @@ -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()); } }); } diff --git a/netconf/mdsal-netconf-ssh/src/main/java/org/opendaylight/netconf/ssh/SshProxyServerConfiguration.java b/netconf/mdsal-netconf-ssh/src/main/java/org/opendaylight/netconf/ssh/SshProxyServerConfiguration.java index 16ecfc5369..12d5656806 100644 --- a/netconf/mdsal-netconf-ssh/src/main/java/org/opendaylight/netconf/ssh/SshProxyServerConfiguration.java +++ b/netconf/mdsal-netconf-ssh/src/main/java/org/opendaylight/netconf/ssh/SshProxyServerConfiguration.java @@ -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); } diff --git a/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/ConnectionNotificationTopicRegistration.java b/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/ConnectionNotificationTopicRegistration.java index acf72e7918..ba61ce6718 100644 --- a/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/ConnectionNotificationTopicRegistration.java +++ b/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/ConnectionNotificationTopicRegistration.java @@ -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); diff --git a/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSource.java b/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSource.java index c4f8d406d7..b0362de220 100644 --- a/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSource.java +++ b/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSource.java @@ -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> registerTopic( final TopicId topicId, final List notificationsToSubscribe) { - Preconditions.checkNotNull(notificationsToSubscribe); + requireNonNull(notificationsToSubscribe); LOG.debug("Join topic {} - register", topicId); JoinTopicStatus joinTopicStatus = JoinTopicStatus.Down; diff --git a/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceManager.java b/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceManager.java index 4877a735b1..46331c54c3 100644 --- a/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceManager.java +++ b/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceManager.java @@ -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 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 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(); } diff --git a/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceRegistration.java b/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceRegistration.java index 2ae032288b..34848b94c3 100644 --- a/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceRegistration.java +++ b/netconf/messagebus-netconf/src/main/java/org/opendaylight/netconf/messagebus/eventsources/netconf/NetconfEventSourceRegistration.java @@ -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"); } diff --git a/netconf/yanglib/src/main/java/org/opendaylight/yanglib/impl/YangLibServiceImpl.java b/netconf/yanglib/src/main/java/org/opendaylight/yanglib/impl/YangLibServiceImpl.java index d856ac7bdb..185f1ea386 100644 --- a/netconf/yanglib/src/main/java/org/opendaylight/yanglib/impl/YangLibServiceImpl.java +++ b/netconf/yanglib/src/main/java/org/opendaylight/yanglib/impl/YangLibServiceImpl.java @@ -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)); diff --git a/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/patch/PatchContext.java b/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/patch/PatchContext.java index 5e867c0838..bf1c7a2c32 100644 --- a/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/patch/PatchContext.java +++ b/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/patch/PatchContext.java @@ -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 context; private final List data; private final String patchId; public PatchContext(final InstanceIdentifierContext context, final List 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 getInstanceIdentifierContext() { diff --git a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/FakeImportedModule.java b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/FakeImportedModule.java index d5d43e7af0..85ea4e4116 100644 --- a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/FakeImportedModule.java +++ b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/FakeImportedModule.java @@ -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 diff --git a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/streams/listeners/AbstractQueryParams.java b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/streams/listeners/AbstractQueryParams.java index 40770f2732..4327578d87 100644 --- a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/streams/listeners/AbstractQueryParams.java +++ b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/streams/listeners/AbstractQueryParams.java @@ -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 stop, final Optional 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; diff --git a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/streams/listeners/NotificationListenerAdapter.java b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/streams/listeners/NotificationListenerAdapter.java index c131237cb7..2f1da2b09c 100644 --- a/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/streams/listeners/NotificationListenerAdapter.java +++ b/restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/streams/listeners/NotificationListenerAdapter.java @@ -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; } -- 2.36.6