From 79cc8f59db4b2b9e5d475d2324520ae259025660 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Tue, 3 Sep 2019 09:21:19 +0200 Subject: [PATCH] Use Object.requireNonNull modernizer is pointing out these users, fix them up. Change-Id: I67dba53d79ef24d464bb5e54685152d182fbbdb3 Signed-off-by: Robert Varga --- .../MdsalNetconfOperationServiceFactory.java | 8 ++-- .../ops/get/FilterContentValidatorTest.java | 4 +- .../impl/NetconfNotificationManager.java | 16 ++++---- .../impl/ops/CreateSubscription.java | 10 +++-- .../impl/ops/NotificationsTransformUtil.java | 10 ++--- ...abilityChangeNotificationProducerTest.java | 4 +- .../netconf/api/DocumentedException.java | 7 ++-- .../NetconfHelloMessageAdditionalHeader.java | 26 ++++++------ .../SimpleNetconfClientSessionListener.java | 9 +++-- .../conf/NetconfClientConfiguration.java | 20 +++++----- ...etconfReconnectingClientConfiguration.java | 5 ++- ...ServerSessionNegotiatorFactoryBuilder.java | 20 +++++----- .../operations/DefaultCloseSession.java | 5 ++- .../impl/osgi/NetconfOperationRouterImpl.java | 10 +++-- .../netconf/impl/ConcurrentClientsTest.java | 30 +++++++------- .../osgi/NetconfOperationRouterImplTest.java | 2 +- .../nettyutil/AbstractNetconfDispatcher.java | 9 +++-- .../nettyutil/NetconfSessionPromise.java | 14 ++++--- .../nettyutil/NeverReconnectStrategy.java | 8 ++-- .../ReconnectImmediatelyStrategy.java | 8 ++-- .../netconf/nettyutil/ReconnectPromise.java | 15 +++---- .../nettyutil/TimedReconnectStrategy.java | 19 +++++---- .../handler/ssh/client/AsyncSshHandler.java | 8 ++-- .../notifications/NetconfNotification.java | 8 ++-- .../netconf/util/NodeContainerProxy.java | 5 ++- .../netconf/util/test/XmlFileLoader.java | 9 ++--- .../netconf/DeviceActionFactoryImpl.java | 9 +++-- .../connect/netconf/NetconfDeviceBuilder.java | 12 +++--- .../connect/netconf/NotificationHandler.java | 19 ++++----- .../listener/NetconfSessionPreferences.java | 8 ++-- .../netconf/sal/NetconfDeviceSalProvider.java | 28 +++++++------ .../sal/NetconfDeviceTopologyAdapter.java | 7 ++-- .../connect/netconf/util/NetconfBaseOps.java | 40 +++++++++---------- .../util/NetconfTopologyRPCProvider.java | 7 ++-- .../sal/connect/util/RemoteDeviceId.java | 5 ++- 35 files changed, 225 insertions(+), 199 deletions(-) diff --git a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/MdsalNetconfOperationServiceFactory.java b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/MdsalNetconfOperationServiceFactory.java index 829f66bb42..1c39f54caa 100644 --- a/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/MdsalNetconfOperationServiceFactory.java +++ b/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/MdsalNetconfOperationServiceFactory.java @@ -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); } diff --git a/netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/get/FilterContentValidatorTest.java b/netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/get/FilterContentValidatorTest.java index 04a3a1414c..3b493d2782 100644 --- a/netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/get/FilterContentValidatorTest.java +++ b/netconf/mdsal-netconf-connector/src/test/java/org/opendaylight/netconf/mdsal/connector/ops/get/FilterContentValidatorTest.java @@ -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); } } } diff --git a/netconf/mdsal-netconf-notification/src/main/java/org/opendaylight/netconf/mdsal/notification/impl/NetconfNotificationManager.java b/netconf/mdsal-netconf-notification/src/main/java/org/opendaylight/netconf/mdsal/notification/impl/NetconfNotificationManager.java index b7df2d720e..bd54b4c5c6 100644 --- a/netconf/mdsal-netconf-notification/src/main/java/org/opendaylight/netconf/mdsal/notification/impl/NetconfNotificationManager.java +++ b/netconf/mdsal-netconf-notification/src/main/java/org/opendaylight/netconf/mdsal/notification/impl/NetconfNotificationManager.java @@ -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); } } diff --git a/netconf/mdsal-netconf-notification/src/main/java/org/opendaylight/netconf/mdsal/notification/impl/ops/CreateSubscription.java b/netconf/mdsal-netconf-notification/src/main/java/org/opendaylight/netconf/mdsal/notification/impl/ops/CreateSubscription.java index 710dcdf007..3f3d14ed96 100644 --- a/netconf/mdsal-netconf-notification/src/main/java/org/opendaylight/netconf/mdsal/notification/impl/ops/CreateSubscription.java +++ b/netconf/mdsal-netconf-notification/src/main/java/org/opendaylight/netconf/mdsal/notification/impl/ops/CreateSubscription.java @@ -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 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 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, diff --git a/netconf/mdsal-netconf-notification/src/main/java/org/opendaylight/netconf/mdsal/notification/impl/ops/NotificationsTransformUtil.java b/netconf/mdsal-netconf-notification/src/main/java/org/opendaylight/netconf/mdsal/notification/impl/ops/NotificationsTransformUtil.java index c146200e99..f54bc811de 100644 --- a/netconf/mdsal-netconf-notification/src/main/java/org/opendaylight/netconf/mdsal/notification/impl/ops/NotificationsTransformUtil.java +++ b/netconf/mdsal-netconf-notification/src/main/java/org/opendaylight/netconf/mdsal/notification/impl/ops/NotificationsTransformUtil.java @@ -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 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)); diff --git a/netconf/mdsal-netconf-notification/src/test/java/org/opendaylight/netconf/mdsal/notification/impl/CapabilityChangeNotificationProducerTest.java b/netconf/mdsal-netconf-notification/src/test/java/org/opendaylight/netconf/mdsal/notification/impl/CapabilityChangeNotificationProducerTest.java index aeb97e4f06..828739b8f7 100644 --- a/netconf/mdsal-netconf-notification/src/test/java/org/opendaylight/netconf/mdsal/notification/impl/CapabilityChangeNotificationProducerTest.java +++ b/netconf/mdsal-netconf-notification/src/test/java/org/opendaylight/netconf/mdsal/notification/impl/CapabilityChangeNotificationProducerTest.java @@ -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 newCapabilitiesList = Lists.newArrayList(new Uri("newCapability"), new Uri("createdCapability")); Capabilities newCapabilities = new CapabilitiesBuilder().setCapability(newCapabilitiesList).build(); - Map, DataObject> createdData = Maps.newHashMap(); + Map, DataObject> createdData = new HashMap<>(); createdData.put(capabilitiesIdentifier, newCapabilities); verifyDataTreeChange(DataObjectModification.ModificationType.WRITE, null, newCapabilities, changedCapabilitesFrom(newCapabilitiesList, Collections.emptyList())); diff --git a/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/DocumentedException.java b/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/DocumentedException.java index 15d4dfe443..907fd2fb5d 100644 --- a/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/DocumentedException.java +++ b/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/DocumentedException.java @@ -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() { diff --git a/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/messages/NetconfHelloMessageAdditionalHeader.java b/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/messages/NetconfHelloMessageAdditionalHeader.java index 5db8a6c811..17374ead4d 100644 --- a/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/messages/NetconfHelloMessageAdditionalHeader.java +++ b/netconf/netconf-api/src/main/java/org/opendaylight/netconf/api/messages/NetconfHelloMessageAdditionalHeader.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.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); } - } diff --git a/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/SimpleNetconfClientSessionListener.java b/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/SimpleNetconfClientSessionListener.java index 14b2bdf980..0390e637fa 100644 --- a/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/SimpleNetconfClientSessionListener.java +++ b/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/SimpleNetconfClientSessionListener.java @@ -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 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(); } diff --git a/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/conf/NetconfClientConfiguration.java b/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/conf/NetconfClientConfiguration.java index 9ad03b915d..ded37caef2 100644 --- a/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/conf/NetconfClientConfiguration.java +++ b/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/conf/NetconfClientConfiguration.java @@ -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 diff --git a/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/conf/NetconfReconnectingClientConfiguration.java b/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/conf/NetconfReconnectingClientConfiguration.java index c43cd2d2b9..c69f023da7 100644 --- a/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/conf/NetconfReconnectingClientConfiguration.java +++ b/netconf/netconf-client/src/main/java/org/opendaylight/netconf/client/conf/NetconfReconnectingClientConfiguration.java @@ -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 diff --git a/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/NetconfServerSessionNegotiatorFactoryBuilder.java b/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/NetconfServerSessionNegotiatorFactoryBuilder.java index a46ed9a4bf..cfbb7481ed 100644 --- a/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/NetconfServerSessionNegotiatorFactoryBuilder.java +++ b/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/NetconfServerSessionNegotiatorFactoryBuilder.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.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; + } } } diff --git a/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/mapping/operations/DefaultCloseSession.java b/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/mapping/operations/DefaultCloseSession.java index 5a5ae1cc43..2b30c0951b 100644 --- a/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/mapping/operations/DefaultCloseSession.java +++ b/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/mapping/operations/DefaultCloseSession.java @@ -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 " diff --git a/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/osgi/NetconfOperationRouterImpl.java b/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/osgi/NetconfOperationRouterImpl.java index 6eda367bd5..9defc2e834 100644 --- a/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/osgi/NetconfOperationRouterImpl.java +++ b/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/osgi/NetconfOperationRouterImpl.java @@ -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 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)); diff --git a/netconf/netconf-impl/src/test/java/org/opendaylight/netconf/impl/ConcurrentClientsTest.java b/netconf/netconf-impl/src/test/java/org/opendaylight/netconf/impl/ConcurrentClientsTest.java index 0462214578..1a4e4c319e 100644 --- a/netconf/netconf-impl/src/test/java/org/opendaylight/netconf/impl/ConcurrentClientsTest.java +++ b/netconf/netconf-impl/src/test/java/org/opendaylight/netconf/impl/ConcurrentClientsTest.java @@ -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 clientRunnable; private final Set serverCaps; - public ConcurrentClientsTest(int nettyThreads, Class clientRunnable, Set serverCaps) { + public ConcurrentClientsTest(final int nettyThreads, final Class clientRunnable, + final Set 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> futures = Lists.newArrayListWithCapacity(CONCURRENCY); + List> 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())); diff --git a/netconf/netconf-impl/src/test/java/org/opendaylight/netconf/impl/osgi/NetconfOperationRouterImplTest.java b/netconf/netconf-impl/src/test/java/org/opendaylight/netconf/impl/osgi/NetconfOperationRouterImplTest.java index a59c257635..21c375830a 100644 --- a/netconf/netconf-impl/src/test/java/org/opendaylight/netconf/impl/osgi/NetconfOperationRouterImplTest.java +++ b/netconf/netconf-impl/src/test/java/org/opendaylight/netconf/impl/osgi/NetconfOperationRouterImplTest.java @@ -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"); } diff --git a/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/AbstractNetconfDispatcher.java b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/AbstractNetconfDispatcher.java index 7997095850..c4e3b47978 100644 --- a/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/AbstractNetconfDispatcher.java +++ b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/AbstractNetconfDispatcher.java @@ -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 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 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 extends DefaultPromi public void operationComplete(final Future 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, diff --git a/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/NeverReconnectStrategy.java b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/NeverReconnectStrategy.java index d59a36f952..f3a46ba3af 100644 --- a/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/NeverReconnectStrategy.java +++ b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/NeverReconnectStrategy.java @@ -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; } diff --git a/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/ReconnectImmediatelyStrategy.java b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/ReconnectImmediatelyStrategy.java index 98756e06ee..da0c5e5fc1 100644 --- a/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/ReconnectImmediatelyStrategy.java +++ b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/ReconnectImmediatelyStrategy.java @@ -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; } diff --git a/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/ReconnectPromise.java b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/ReconnectPromise.java index 696d9f7ad0..52fbf291b1 100644 --- a/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/ReconnectPromise.java +++ b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/ReconnectPromise.java @@ -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 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= 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; } diff --git a/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/ssh/client/AsyncSshHandler.java b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/ssh/client/AsyncSshHandler.java index 15882ded63..0017eff749 100644 --- a/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/ssh/client/AsyncSshHandler.java +++ b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/ssh/client/AsyncSshHandler.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.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) { diff --git a/netconf/netconf-notifications-api/src/main/java/org/opendaylight/netconf/notifications/NetconfNotification.java b/netconf/netconf-notifications-api/src/main/java/org/opendaylight/netconf/notifications/NetconfNotification.java index 87de89a5db..9d2248e27a 100644 --- a/netconf/netconf-notifications-api/src/main/java/org/opendaylight/netconf/notifications/NetconfNotification.java +++ b/netconf/netconf-notifications-api/src/main/java/org/opendaylight/netconf/notifications/NetconfNotification.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.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); diff --git a/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/NodeContainerProxy.java b/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/NodeContainerProxy.java index 3154b370f4..3db4387219 100644 --- a/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/NodeContainerProxy.java +++ b/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/NodeContainerProxy.java @@ -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 childNodes, final Set availableAugmentations) { this.availableAugmentations = availableAugmentations; - this.childNodes = Preconditions.checkNotNull(childNodes, "childNodes"); + this.childNodes = requireNonNull(childNodes, "childNodes"); this.qualifiedName = qualifiedName; } diff --git a/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/test/XmlFileLoader.java b/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/test/XmlFileLoader.java index e21820839c..2d7737af27 100644 --- a/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/test/XmlFileLoader.java +++ b/netconf/netconf-util/src/test/java/org/opendaylight/netconf/util/test/XmlFileLoader.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.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() { diff --git a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/DeviceActionFactoryImpl.java b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/DeviceActionFactoryImpl.java index e217eec8f1..8874abb0a7 100644 --- a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/DeviceActionFactoryImpl.java +++ b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/DeviceActionFactoryImpl.java @@ -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 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> actionResultFuture = listener.sendRequest( messageTransformer.toActionRequest(schemaPath, dataTreeIdentifier, input), input.getNodeType()); diff --git a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/NetconfDeviceBuilder.java b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/NetconfDeviceBuilder.java index 9d262568e9..7ed0154259 100644 --- a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/NetconfDeviceBuilder.java +++ b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/NetconfDeviceBuilder.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.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"); } } diff --git a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/NotificationHandler.java b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/NotificationHandler.java index cf8d0aefb1..ce63849aff 100644 --- a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/NotificationHandler.java +++ b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/NotificationHandler.java @@ -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 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 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()) { diff --git a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/listener/NetconfSessionPreferences.java b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/listener/NetconfSessionPreferences.java index dcff0f294b..341d302200 100644 --- a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/listener/NetconfSessionPreferences.java +++ b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/listener/NetconfSessionPreferences.java @@ -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 nonModuleCaps, final Map moduleBasedCaps) { - this.nonModuleCaps = Preconditions.checkNotNull(nonModuleCaps); - this.moduleBasedCaps = Preconditions.checkNotNull(moduleBasedCaps); + this.nonModuleCaps = requireNonNull(nonModuleCaps); + this.moduleBasedCaps = requireNonNull(moduleBasedCaps); } public Set getModuleBasedCaps() { diff --git a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalProvider.java b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalProvider.java index 7b578a35dc..d6b6354a3e 100644 --- a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalProvider.java +++ b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalProvider.java @@ -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 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); } } diff --git a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceTopologyAdapter.java b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceTopologyAdapter.java index 202517fb14..d945986b44 100644 --- a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceTopologyAdapter.java +++ b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceTopologyAdapter.java @@ -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); } } diff --git a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/util/NetconfBaseOps.java b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/util/NetconfBaseOps.java index ecbe6fa6a9..01dc488bb3 100644 --- a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/util/NetconfBaseOps.java +++ b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/util/NetconfBaseOps.java @@ -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 lock(final FutureCallback callback, final QName datastore) { - Preconditions.checkNotNull(callback); - Preconditions.checkNotNull(datastore); + requireNonNull(callback); + requireNonNull(datastore); final ListenableFuture future = rpc.invokeRpc(NETCONF_LOCK_PATH, getLockContent(datastore)); Futures.addCallback(future, callback, MoreExecutors.directExecutor()); @@ -106,8 +107,8 @@ public final class NetconfBaseOps { } public ListenableFuture unlock(final FutureCallback callback, final QName datastore) { - Preconditions.checkNotNull(callback); - Preconditions.checkNotNull(datastore); + requireNonNull(callback); + requireNonNull(datastore); final ListenableFuture future = rpc.invokeRpc(NETCONF_UNLOCK_PATH, getUnLockContent(datastore)); Futures.addCallback(future, callback, MoreExecutors.directExecutor()); @@ -129,7 +130,7 @@ public final class NetconfBaseOps { } public ListenableFuture discardChanges(final FutureCallback callback) { - Preconditions.checkNotNull(callback); + requireNonNull(callback); final ListenableFuture future = rpc.invokeRpc(NETCONF_DISCARD_CHANGES_PATH, null); Futures.addCallback(future, callback, MoreExecutors.directExecutor()); @@ -137,7 +138,7 @@ public final class NetconfBaseOps { } public ListenableFuture commit(final FutureCallback callback) { - Preconditions.checkNotNull(callback); + requireNonNull(callback); final ListenableFuture future = rpc.invokeRpc(NetconfMessageTransformUtil.NETCONF_COMMIT_PATH, NetconfMessageTransformUtil.COMMIT_RPC_CONTENT); @@ -146,11 +147,10 @@ public final class NetconfBaseOps { } public ListenableFuture validate(final FutureCallback callback, final QName datastore) { - Preconditions.checkNotNull(callback); - Preconditions.checkNotNull(datastore); + requireNonNull(callback); final ListenableFuture 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 copyConfig(final FutureCallback callback, final QName source, final QName target) { - Preconditions.checkNotNull(callback); - Preconditions.checkNotNull(source); - Preconditions.checkNotNull(target); + requireNonNull(callback); final ListenableFuture 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 getConfig(final FutureCallback callback, final QName datastore, final Optional filterPath) { - Preconditions.checkNotNull(callback); - Preconditions.checkNotNull(datastore); + requireNonNull(callback); + requireNonNull(datastore); final ListenableFuture future; if (isFilterPresent(filterPath)) { @@ -213,7 +211,7 @@ public final class NetconfBaseOps { private ListenableFuture>> extractData( final Optional path, final ListenableFuture 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 dataNode = ((ContainerNode) result.getResult()).getChild(NetconfMessageTransformUtil.NETCONF_DATA_NODEID) @@ -234,7 +232,7 @@ public final class NetconfBaseOps { public ListenableFuture get(final FutureCallback callback, final Optional filterPath) { - Preconditions.checkNotNull(callback); + requireNonNull(callback); final ListenableFuture 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 callback, final QName datastore, final DataContainerChild editStructure, final Optional modifyAction, final boolean rollback) { - Preconditions.checkNotNull(editStructure); - Preconditions.checkNotNull(callback); - Preconditions.checkNotNull(datastore); + requireNonNull(callback); final ListenableFuture 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; diff --git a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/util/NetconfTopologyRPCProvider.java b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/util/NetconfTopologyRPCProvider.java index 6499f54dd0..98eeb7d9fe 100644 --- a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/util/NetconfTopologyRPCProvider.java +++ b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/util/NetconfTopologyRPCProvider.java @@ -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 diff --git a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/util/RemoteDeviceId.java b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/util/RemoteDeviceId.java index 796ec2f8ba..39b4f9bf9c 100644 --- a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/util/RemoteDeviceId.java +++ b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/util/RemoteDeviceId.java @@ -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)); -- 2.36.6