Convert to using requireNonNull() 88/84188/5
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 4 Sep 2019 06:30:56 +0000 (08:30 +0200)
committerRobert Varga <nite@hq.sk>
Fri, 6 Sep 2019 12:32:04 +0000 (12:32 +0000)
This is a second pass to migrate further Preconditions users
to java.util.Objects.requireNonNull().

Change-Id: Idb32790ae96957961628eae384c801931a203c08
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
27 files changed:
netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/CallHomeAuthorization.java
netconf/callhome-protocol/src/main/java/org/opendaylight/netconf/callhome/protocol/MinaSshNettyChannel.java
netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/CallHomeMountSessionContext.java
netconf/callhome-provider/src/main/java/org/opendaylight/netconf/callhome/mount/ContextKey.java
netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/api/RemoteDeviceConnector.java
netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/MasterSalFacade.java
netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/RemoteDeviceConnectorImpl.java
netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/DummyMonitoringService.java
netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/MdsalOperationProvider.java
netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/NetconfDeviceSimulator.java
netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/client/stress/AbstractExecutionStrategy.java
netconf/tools/netconf-testtool/src/main/java/org/opendaylight/netconf/test/tool/client/stress/AsyncExecutionStrategy.java
restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/errors/RestconfDocumentedException.java
restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/errors/RestconfError.java
restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/patch/PatchEntity.java
restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/util/RestUtil.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/codecs/RestCodec.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/handlers/SchemaContextHandler.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/ParameterAwareNormalizedNodeWriter.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PutDataTransactionUtil.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/services/simple/impl/FakeImportedModule.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/services/simple/impl/FakeModuleImport.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/AbstractQueryParams.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/ListenerAdapter.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/NotificationListenerAdapter.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/TestUtils.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/NotificationListenerTest.java

index 81d6c6fa75bedd843df58a5098bd166942295fa0..673c932050a917f969438b8820547eeaad9648d1 100644 (file)
@@ -7,7 +7,9 @@
  */
 package org.opendaylight.netconf.callhome.protocol;
 
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkArgument;
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.collect.ImmutableSet;
 import java.security.KeyPair;
 import java.util.Collection;
@@ -104,8 +106,8 @@ public abstract class CallHomeAuthorization {
         private final Set<KeyPair> clientKeys = new HashSet<>();
 
         Builder(final String nodeId, final String username) {
-            this.nodeId = Preconditions.checkNotNull(nodeId);
-            this.username = Preconditions.checkNotNull(username);
+            this.nodeId = requireNonNull(nodeId);
+            this.username = requireNonNull(username);
         }
 
         /**
@@ -146,10 +148,10 @@ public abstract class CallHomeAuthorization {
 
         ServerAllowed(final String nodeId, final String username, final Collection<String> passwords,
                       final Collection<KeyPair> clientKeyPairs) {
-            this.username = Preconditions.checkNotNull(username);
+            this.username = requireNonNull(username);
             this.passwords = ImmutableSet.copyOf(passwords);
             this.clientKeyPair = ImmutableSet.copyOf(clientKeyPairs);
-            this.nodeId = Preconditions.checkNotNull(nodeId);
+            this.nodeId = requireNonNull(nodeId);
         }
 
         @Override
@@ -164,7 +166,7 @@ public abstract class CallHomeAuthorization {
 
         @Override
         protected void applyTo(final ClientSession session) {
-            Preconditions.checkArgument(session instanceof ClientSessionImpl);
+            checkArgument(session instanceof ClientSessionImpl);
             session.setUsername(username);
 
             // First try authentication using server host keys, else try password.
index e18facf652d77b834f5bf674f142575b4cd0a139..72ba8b1698600374b19cd5574b5c2c8202c8c421 100644 (file)
@@ -5,10 +5,10 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.netconf.callhome.protocol;
 
-import com.google.common.base.Preconditions;
+import static java.util.Objects.requireNonNull;
+
 import io.netty.buffer.ByteBuf;
 import io.netty.channel.AbstractServerChannel;
 import io.netty.channel.ChannelConfig;
@@ -43,9 +43,9 @@ class MinaSshNettyChannel extends AbstractServerChannel {
 
     MinaSshNettyChannel(final CallHomeSessionContext context, final ClientSession session,
         final ClientChannel sshChannel) {
-        this.context = Preconditions.checkNotNull(context);
-        this.session = Preconditions.checkNotNull(session);
-        this.sshChannel = Preconditions.checkNotNull(sshChannel);
+        this.context = requireNonNull(context);
+        this.session = requireNonNull(session);
+        this.sshChannel = requireNonNull(sshChannel);
         this.sshReadHandler = new AsyncSshHandlerReader(
             new ConnectionClosedDuringRead(), new FireReadMessage(), "netconf", sshChannel.getAsyncOut());
         this.sshWriteAsyncHandler = new AsyncSshHandlerWriter(sshChannel.getAsyncIn());
index 539f6ab3158d66a933c7af6fd825684bccae536c..85a79934abc52a1d9ea891861d528ad70a8d64d4 100644 (file)
@@ -5,10 +5,10 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.netconf.callhome.mount;
 
-import com.google.common.base.Preconditions;
+import static java.util.Objects.requireNonNull;
+
 import io.netty.util.concurrent.Promise;
 import java.net.InetSocketAddress;
 import java.security.PublicKey;
@@ -42,11 +42,11 @@ class CallHomeMountSessionContext {
     CallHomeMountSessionContext(String nodeId, CallHomeProtocolSessionContext protocol,
                                 CallHomeChannelActivator activator, CloseCallback callback) {
 
-        this.nodeId = new NodeId(Preconditions.checkNotNull(nodeId, "nodeId"));
+        this.nodeId = new NodeId(requireNonNull(nodeId, "nodeId"));
         this.key = ContextKey.from(protocol.getRemoteAddress());
-        this.protocol = Preconditions.checkNotNull(protocol, "protocol");
-        this.activator = Preconditions.checkNotNull(activator, "activator");
-        this.onClose = Preconditions.checkNotNull(callback, "callback");
+        this.protocol = requireNonNull(protocol, "protocol");
+        this.activator = requireNonNull(activator, "activator");
+        this.onClose = requireNonNull(callback, "callback");
     }
 
     NodeId getId() {
index 3536d66090daf0a89bc15b7bda94b79c712ac216..9f422d109e2fde4635b64f3140cf715f5384127e 100644 (file)
@@ -5,11 +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.callhome.mount;
 
-import com.google.common.base.Objects;
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkArgument;
+import static java.util.Objects.requireNonNull;
+
 import java.net.Inet4Address;
 import java.net.Inet6Address;
 import java.net.InetAddress;
@@ -21,13 +21,12 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
 
 class ContextKey {
-
     private final IpAddress address;
     private final PortNumber port;
 
-    ContextKey(IpAddress address, PortNumber port) {
-        this.address = Preconditions.checkNotNull(address);
-        this.port = Preconditions.checkNotNull(port);
+    ContextKey(final IpAddress address, final PortNumber port) {
+        this.address = requireNonNull(address);
+        this.port = requireNonNull(port);
     }
 
     @Override
@@ -40,7 +39,7 @@ class ContextKey {
     }
 
     @Override
-    public boolean equals(Object obj) {
+    public boolean equals(final Object obj) {
         if (this == obj) {
             return true;
         }
@@ -51,7 +50,7 @@ class ContextKey {
             return false;
         }
         ContextKey other = (ContextKey) obj;
-        return Objects.equal(address, other.address) && Objects.equal(port, other.port);
+        return address.equals(other.address) && port.equals(other.port);
     }
 
     IpAddress getIpAddress() {
@@ -62,12 +61,12 @@ class ContextKey {
         return port;
     }
 
-    public static ContextKey from(NetconfNode node) {
+    public static ContextKey from(final NetconfNode node) {
         return new ContextKey(node.getHost().getIpAddress(), node.getPort());
     }
 
-    public static ContextKey from(SocketAddress remoteAddress) {
-        Preconditions.checkArgument(remoteAddress instanceof InetSocketAddress);
+    public static ContextKey from(final SocketAddress remoteAddress) {
+        checkArgument(remoteAddress instanceof InetSocketAddress);
         InetSocketAddress inetSocketAddr = (InetSocketAddress) remoteAddress;
         InetAddress ipAddress = inetSocketAddr.getAddress();
 
@@ -75,7 +74,7 @@ class ContextKey {
         if (ipAddress instanceof Inet4Address) {
             yangIp = new IpAddress(IetfInetUtil.INSTANCE.ipv4AddressFor(ipAddress));
         } else {
-            Preconditions.checkArgument(ipAddress instanceof Inet6Address);
+            checkArgument(ipAddress instanceof Inet6Address);
             yangIp = new IpAddress(IetfInetUtil.INSTANCE.ipv6AddressFor(ipAddress));
         }
         return new ContextKey(yangIp, new PortNumber(inetSocketAddr.getPort()));
index 69e2dd20bd494660d3b40f3703824f1189e28a05..97d067dae5ab29e13d0f898a377d12f205ff27ca 100644 (file)
@@ -5,24 +5,29 @@
  * 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.topology.singleton.api;
 
 import org.opendaylight.netconf.sal.connect.api.RemoteDeviceHandler;
 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences;
 
 /**
- * Provides API for connection odl (master) with device.
+ * Provides API for connection ODL (master) with device.
  */
+// FIXME: way more documentation is needed here
 public interface RemoteDeviceConnector {
 
     /**
      * Create device communicator and open device connection.
+     *
+     * @param deviceHandler Device handler
+     * @throws NullPointerException if {@code deviceHandler} is null
      */
+    // FIXME: this should return a resource corresponding to the device connection
     void startRemoteDeviceConnection(RemoteDeviceHandler<NetconfSessionPreferences> deviceHandler);
 
     /**
      * Stop device communicator.
      */
+    // FIXME: see above, this should live in the returned resource
     void stopRemoteDeviceConnection();
 }
index ee2d3ee0b1341a869d132b57ccf63295c8bc6418..2460134aa7c692793ccac382bb474f2dc5d9788a 100644 (file)
@@ -7,13 +7,14 @@
  */
 package org.opendaylight.netconf.topology.singleton.impl;
 
+import static java.util.Objects.requireNonNull;
+
 import akka.actor.ActorRef;
 import akka.actor.ActorSystem;
 import akka.cluster.Cluster;
 import akka.dispatch.OnComplete;
 import akka.pattern.Patterns;
 import akka.util.Timeout;
-import com.google.common.base.Preconditions;
 import java.util.List;
 import java.util.stream.Collectors;
 import org.opendaylight.mdsal.binding.api.DataBroker;
@@ -129,11 +130,9 @@ class MasterSalFacade implements AutoCloseable, RemoteDeviceHandler<NetconfSessi
     }
 
     private void registerMasterMountPoint() {
-        Preconditions.checkNotNull(id);
-        Preconditions.checkNotNull(currentSchemaContext,
-                "Device has no remote schema context yet. Probably not fully connected.");
-        Preconditions.checkNotNull(netconfSessionPreferences,
-                "Device has no capabilities yet. Probably not fully connected.");
+        requireNonNull(id);
+        requireNonNull(currentSchemaContext, "Device has no remote schema context yet. Probably not fully connected.");
+        requireNonNull(netconfSessionPreferences, "Device has no capabilities yet. Probably not fully connected.");
 
         final NetconfDeviceNotificationService notificationService = new NetconfDeviceNotificationService();
         deviceDataBroker = newDeviceDataBroker();
@@ -185,4 +184,4 @@ class MasterSalFacade implements AutoCloseable, RemoteDeviceHandler<NetconfSessi
             }
         }
     }
-}
\ No newline at end of file
+}
index 907a67167c946066f6068bed243b89ebba8b0921..14cd6824c11a0d573c504466628d300ddf693a8d 100644 (file)
@@ -88,10 +88,13 @@ public class RemoteDeviceConnectorImpl implements RemoteDeviceConnector {
     private final String privateKeyPath;
     private final String privateKeyPassphrase;
     private final AAAEncryptionService encryptionService;
-    private NetconfConnectorDTO deviceCommunicatorDTO;
     private final NetconfKeystoreAdapter keystoreAdapter;
     private final DeviceActionFactory deviceActionFactory;
 
+    // FIXME: this seems to be a builder-like transition between {start,stop}RemoteDeviceConnection. More documentation
+    //        is needed, as to what the lifecycle is here.
+    private NetconfConnectorDTO deviceCommunicatorDTO;
+
     public RemoteDeviceConnectorImpl(final NetconfTopologySetup netconfTopologyDeviceSetup,
             final RemoteDeviceId remoteDeviceId, final DeviceActionFactory deviceActionFactory) {
         this.netconfTopologyDeviceSetup = requireNonNull(netconfTopologyDeviceSetup);
@@ -155,7 +158,7 @@ public class RemoteDeviceConnectorImpl implements RemoteDeviceConnector {
         final boolean reconnectOnChangedSchema = node.isReconnectOnChangedSchema() == null
                 ? NetconfTopologyUtils.DEFAULT_RECONNECT_ON_CHANGED_SCHEMA : node.isReconnectOnChangedSchema();
 
-        RemoteDeviceHandler<NetconfSessionPreferences> salFacade = deviceHandler;
+        RemoteDeviceHandler<NetconfSessionPreferences> salFacade = requireNonNull(deviceHandler);
         if (keepaliveDelay > 0) {
             LOG.info("{}: Adding keepalive facade.", remoteDeviceId);
             salFacade = new KeepaliveSalFacade(remoteDeviceId, salFacade,
@@ -166,6 +169,8 @@ public class RemoteDeviceConnectorImpl implements RemoteDeviceConnector {
         final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO = netconfTopologyDeviceSetup.getSchemaResourcesDTO();
 
         // pre register yang library sources as fallback schemas to schema registry
+        // FIXME: this list not used anywhere. Should it be retained or discarded? (why?)
+        //        it would seem those registrations should be bound to NetconfConnectorDTO
         final List<SchemaSourceRegistration<YangTextSchemaSource>> registeredYangLibSources = Lists.newArrayList();
         if (node.getYangLibrary() != null) {
             final String yangLibURL = node.getYangLibrary().getYangLibraryUrl().getValue();
index 753637753c7196751a9313c69096159970ae583d..ec76f8866b9ba5f0b1ea77f522a883e21a12f133 100644 (file)
@@ -10,9 +10,9 @@ package org.opendaylight.netconf.test.tool;
 import com.google.common.base.Function;
 import com.google.common.collect.ArrayListMultimap;
 import com.google.common.collect.Collections2;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
+import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.Optional;
 import java.util.Set;
 import org.opendaylight.netconf.api.capability.Capability;
@@ -57,9 +57,9 @@ public class DummyMonitoringService implements NetconfMonitoringService {
     public DummyMonitoringService(final Set<Capability> capabilities) {
 
         this.capabilities = new CapabilitiesBuilder().setCapability(
-                Lists.newArrayList(Collections2.transform(capabilities, CAPABILITY_URI_FUNCTION))).build();
+                new ArrayList<>(Collections2.transform(capabilities, CAPABILITY_URI_FUNCTION))).build();
 
-        Set<Capability> moduleCapabilities = Sets.newHashSet();
+        Set<Capability> moduleCapabilities = new HashSet<>();
         this.capabilityMultiMap = ArrayListMultimap.create();
         for (Capability cap : capabilities) {
             if (cap.getModuleName().isPresent()) {
@@ -69,7 +69,7 @@ public class DummyMonitoringService implements NetconfMonitoringService {
         }
 
         this.schemas = new SchemasBuilder().setSchema(
-            Lists.newArrayList(Collections2.transform(moduleCapabilities, CAPABILITY_SCHEMA_FUNCTION))).build();
+            new ArrayList<>(Collections2.transform(moduleCapabilities, CAPABILITY_SCHEMA_FUNCTION))).build();
     }
 
     @Override
index ae396dc0568ce5cc83464992b587352eeb819280..49eb3558f110c5ba23bd4dbf31e0dc426820ec02 100644 (file)
@@ -9,11 +9,11 @@ package org.opendaylight.netconf.test.tool;
 
 import com.google.common.collect.ClassToInstanceMap;
 import com.google.common.collect.ImmutableClassToInstanceMap;
-import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
 import com.google.common.util.concurrent.MoreExecutors;
 import java.util.Collections;
 import java.util.EnumMap;
+import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ExecutionException;
@@ -181,7 +181,7 @@ class MdsalOperationProvider implements NetconfOperationServiceFactory {
             LeafSetEntryNode locationLeafSetEntryNode = Builders.leafSetEntryBuilder().withNodeIdentifier(
                             new NodeWithValue<>(location, "NETCONF")).withValue("NETCONF").build();
 
-            Map<QName, Object> keyValues = Maps.newHashMap();
+            Map<QName, Object> keyValues = new HashMap<>();
             for (final Schema schema : monitor.getSchemas().getSchema()) {
                 keyValues.put(identifier, schema.getIdentifier());
                 keyValues.put(version, schema.getVersion());
index b74f5f52b0e71b565cf43dab5006af311e395f43..46ac8a5e7cd53a59de7494e8f246d00804d8ece6 100644 (file)
@@ -5,13 +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.test.tool;
 
 import com.google.common.base.MoreObjects.ToStringHelper;
 import com.google.common.collect.Collections2;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ThreadFactoryBuilder;
 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
@@ -28,6 +25,8 @@ import java.net.Inet4Address;
 import java.net.InetSocketAddress;
 import java.net.UnknownHostException;
 import java.nio.channels.AsynchronousChannelGroup;
+import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Optional;
 import java.util.Set;
@@ -81,8 +80,8 @@ public class NetconfDeviceSimulator implements Closeable {
 
     private final NioEventLoopGroup nettyThreadgroup;
     private final HashedWheelTimer hashedWheelTimer;
-    private final List<Channel> devicesChannels = Lists.newArrayList();
-    private final List<SshProxyServer> sshWrappers = Lists.newArrayList();
+    private final List<Channel> devicesChannels = new ArrayList<>();
+    private final List<SshProxyServer> sshWrappers = new ArrayList<>();
     private final ScheduledExecutorService minaTimerExecutor;
     private final ExecutorService nioExecutor;
     private final Configuration configuration;
@@ -103,7 +102,7 @@ public class NetconfDeviceSimulator implements Closeable {
     private NetconfServerDispatcherImpl createDispatcher(final Set<Capability> capabilities,
             final SchemaSourceProvider<YangTextSchemaSource> sourceProvider) {
 
-        final Set<Capability> transformedCapabilities = Sets.newHashSet(Collections2.transform(capabilities, input -> {
+        final Set<Capability> transformedCapabilities = new HashSet<>(Collections2.transform(capabilities, input -> {
             if (sendFakeSchema) {
                 sendFakeSchema = false;
                 return new FakeCapability((YangModuleCapability) input);
@@ -184,7 +183,7 @@ public class NetconfDeviceSimulator implements Closeable {
 
         int currentPort = configuration.getStartingPort();
 
-        final List<Integer> openDevices = Lists.newArrayList();
+        final List<Integer> openDevices = new ArrayList<>();
 
         // Generate key to temp folder
         final KeyPairProvider keyPairProvider = new VirtualKeyPairProvider();
@@ -285,7 +284,7 @@ public class NetconfDeviceSimulator implements Closeable {
     }
 
     private Set<Capability> parseSchemasToModuleCapabilities(final SharedSchemaRepository consumer) {
-        final Set<SourceIdentifier> loadedSources = Sets.newHashSet();
+        final Set<SourceIdentifier> loadedSources = new HashSet<>();
         consumer.registerSchemaSourceListener(TextToASTTransformer.create(consumer, consumer));
         consumer.registerSchemaSourceListener(new SchemaSourceListener() {
             @Override
@@ -334,7 +333,7 @@ public class NetconfDeviceSimulator implements Closeable {
             throw new RuntimeException("Cannot parse schema context", e);
         }
 
-        final Set<Capability> capabilities = Sets.newHashSet();
+        final Set<Capability> capabilities = new HashSet<>();
 
         for (final Module module : schemaContext.getModules()) {
             for (final Module subModule : module.getSubmodules()) {
index b59df5495b3752e70792724e117ce8bdf5cbac07..6f1a477696468ff3237a97463a3bf5d20aaa642c 100644 (file)
@@ -5,10 +5,9 @@
  * 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.test.tool.client.stress;
 
-import com.google.common.collect.Lists;
+import java.util.ArrayList;
 import java.util.List;
 import org.opendaylight.netconf.api.NetconfMessage;
 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCommunicator;
@@ -30,7 +29,7 @@ abstract class AbstractExecutionStrategy implements ExecutionStrategy {
     }
 
     private static List<Integer> countEditBatchSizes(final Parameters params, final int amount) {
-        final List<Integer> editBatches = Lists.newArrayList();
+        final List<Integer> editBatches = new ArrayList<>();
         if (params.editBatchSize != amount) {
             final int fullBatches = amount / params.editBatchSize;
             for (int i = 0; i < fullBatches; i++) {
index c5833ddef5885096c00eb4a6696dfe975df5546a..5cfebdcdc8e9deb3f36ce651923b6663e47cbeac 100644 (file)
@@ -5,12 +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.test.tool.client.stress;
 
 import com.google.common.base.Preconditions;
-import com.google.common.collect.Lists;
 import com.google.common.util.concurrent.ListenableFuture;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
@@ -34,7 +33,7 @@ class AsyncExecutionStrategy extends AbstractExecutionStrategy {
     @Override
     public void invoke() {
         final AtomicInteger responseCounter = new AtomicInteger(0);
-        final List<ListenableFuture<RpcResult<NetconfMessage>>> futures = Lists.newArrayList();
+        final List<ListenableFuture<RpcResult<NetconfMessage>>> futures = new ArrayList<>();
 
         int batchI = 0;
         for (final Integer editBatch : getEditBatches()) {
index ecd894b7ff913816f2152d117d027e65801e6979..1d7870173b8451f8a7d6d3f56cdd7fb20e346e8d 100644 (file)
@@ -7,7 +7,8 @@
  */
 package org.opendaylight.restconf.common.errors;
 
-import com.google.common.base.Preconditions;
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.collect.ImmutableList;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -152,14 +153,12 @@ public class RestconfDocumentedException extends WebApplicationException {
      *            the HTTP status.
      */
     public RestconfDocumentedException(final Status status) {
-        Preconditions.checkNotNull(status, "Status can't be null");
         errors = ImmutableList.of();
-        this.status = status;
+        this.status = requireNonNull(status, "Status can't be null");
     }
 
     public RestconfDocumentedException(final Throwable cause, final RestconfError error) {
         super(cause, error.getErrorTag().getStatusCode());
-        Preconditions.checkNotNull(error, "RestconfError can't be null");
         errors = ImmutableList.of(error);
         status = null;
     }
index fcf350f0d87489e00ed02f63aac81a23c6121e01..44890df1a98e6efa2ac38420f8ae8d161c91802f 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.restconf.common.errors;
 
-import com.google.common.base.Preconditions;
+import static java.util.Objects.requireNonNull;
+
 import java.io.Serializable;
 import java.util.Locale;
 import org.opendaylight.yangtools.yang.common.RpcError;
@@ -198,10 +198,8 @@ public class RestconfError implements Serializable {
      */
     public RestconfError(final ErrorType errorType, final ErrorTag errorTag, final String errorMessage,
                          final String errorAppTag, final String errorInfo, final YangInstanceIdentifier errorPath) {
-        Preconditions.checkNotNull(errorType, "Error type is required for RestConfError");
-        Preconditions.checkNotNull(errorTag, "Error tag is required for RestConfError");
-        this.errorType = errorType;
-        this.errorTag = errorTag;
+        this.errorType = requireNonNull(errorType, "Error type is required for RestConfError");
+        this.errorTag = requireNonNull(errorTag, "Error tag is required for RestConfError");
         this.errorMessage = errorMessage;
         this.errorAppTag = errorAppTag;
         this.errorInfo = errorInfo;
index 790892304c9c46bdc79dd2a66ad28f8432f9630f..a57698ce934c5245096e2e45fb3cb442e2ec6ec5 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.restconf.common.patch;
 
-import com.google.common.base.Preconditions;
+import static java.util.Objects.requireNonNull;
+
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 
@@ -28,10 +28,10 @@ public class PatchEntity {
      */
     public PatchEntity(final String editId, final PatchEditOperation operation, final YangInstanceIdentifier targetNode,
                        final NormalizedNode<?, ?> node) {
-        this.editId = Preconditions.checkNotNull(editId);
-        this.operation = Preconditions.checkNotNull(operation);
-        this.targetNode = Preconditions.checkNotNull(targetNode);
-        this.node = Preconditions.checkNotNull(node);
+        this.editId = requireNonNull(editId);
+        this.operation = requireNonNull(operation);
+        this.targetNode = requireNonNull(targetNode);
+        this.node = requireNonNull(node);
     }
 
     /**
@@ -43,9 +43,9 @@ public class PatchEntity {
      */
     public PatchEntity(final String editId, final PatchEditOperation operation,
             final YangInstanceIdentifier targetNode) {
-        this.editId = Preconditions.checkNotNull(editId);
-        this.operation = Preconditions.checkNotNull(operation);
-        this.targetNode = Preconditions.checkNotNull(targetNode);
+        this.editId = requireNonNull(editId);
+        this.operation = requireNonNull(operation);
+        this.targetNode = requireNonNull(targetNode);
         this.node = null;
     }
 
index 82551250ac29edf46f02b2d0973ea15a40c2ba57..4086546b32ad9ae838391719c9b0931f2eaf7362 100644 (file)
@@ -7,7 +7,8 @@
  */
 package org.opendaylight.restconf.common.util;
 
-import com.google.common.base.Preconditions;
+import static java.util.Objects.requireNonNull;
+
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.PushbackInputStream;
@@ -52,8 +53,7 @@ public final class RestUtil {
      *
      */
     public static Optional<InputStream> isInputStreamEmpty(final InputStream entityStream) throws IOException {
-        Preconditions.checkNotNull(entityStream);
-        final PushbackInputStream pushbackInputStream = new PushbackInputStream(entityStream);
+        final PushbackInputStream pushbackInputStream = new PushbackInputStream(requireNonNull(entityStream));
 
         int firstByte = pushbackInputStream.read();
         if (firstByte == -1) {
index 62c540f4335be1cec847075f478816fc8b6f2535..9f4a9c25e7a33729f7cd3d197492a26ec35a71c9 100644 (file)
@@ -7,7 +7,8 @@
  */
 package org.opendaylight.restconf.nb.rfc8040.codecs;
 
-import com.google.common.base.Preconditions;
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.collect.Iterables;
 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.net.URI;
@@ -339,6 +340,8 @@ public final class RestCodec {
         }
     }
 
+    @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
+            justification = "https://github.com/spotbugs/spotbugs/issues/811")
     private static Module getModuleByNamespace(final String namespace, final DOMMountPoint mountPoint,
             final SchemaContext schemaContext) {
         final URI validNamespace = resolveValidNamespace(namespace, mountPoint, schemaContext);
@@ -379,9 +382,11 @@ public final class RestCodec {
         return null;
     }
 
+    @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
+            justification = "https://github.com/spotbugs/spotbugs/issues/811")
     private static DataSchemaNode findInstanceDataChildByNameAndNamespace(final DataNodeContainer container,
             final String name, final URI namespace) {
-        Preconditions.checkNotNull(namespace);
+        requireNonNull(namespace);
 
         final Iterable<DataSchemaNode> result = Iterables.filter(findInstanceDataChildrenByName(container, name),
             node -> namespace.equals(node.getQName().getNamespace()));
@@ -390,11 +395,9 @@ public final class RestCodec {
 
     private static List<DataSchemaNode> findInstanceDataChildrenByName(final DataNodeContainer container,
             final String name) {
-        Preconditions.checkNotNull(container);
-        Preconditions.checkNotNull(name);
-
         final List<DataSchemaNode> instantiatedDataNodeContainers = new ArrayList<>();
-        collectInstanceDataNodeContainers(instantiatedDataNodeContainers, container, name);
+        collectInstanceDataNodeContainers(instantiatedDataNodeContainers, requireNonNull(container),
+            requireNonNull(name));
         return instantiatedDataNodeContainers;
     }
 
index 6e12200660a7d9d2e09907e053acfb2d15a52967..5483dab8d4167555d1b8980072bedffd3e9a925e 100644 (file)
@@ -7,7 +7,8 @@
  */
 package org.opendaylight.restconf.nb.rfc8040.handlers;
 
-import com.google.common.base.Preconditions;
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.base.Throwables;
 import java.util.Collection;
 import java.util.concurrent.ExecutionException;
@@ -89,8 +90,7 @@ public class SchemaContextHandler implements SchemaContextListenerHandler, AutoC
     @Override
     @SuppressWarnings("checkstyle:hiddenField")
     public void onGlobalContextUpdated(final SchemaContext context) {
-        Preconditions.checkNotNull(context);
-        schemaContext = context;
+        schemaContext = requireNonNull(context);
 
         final Module ietfYangLibraryModule =
                 context.findModule(IetfYangLibrary.MODULE_QNAME).orElse(null);
index faf28ffe44e3dfdebd221cd03cf5c1cf2b658d5c..516b799df81ffd9a862bb9f92fd0f874c04b1461 100644 (file)
@@ -7,10 +7,10 @@
  */
 package org.opendaylight.restconf.nb.rfc8040.jersey.providers;
 
+import static java.util.Objects.requireNonNull;
 import static org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter.UNKNOWN_SIZE;
 
 import com.google.common.annotations.Beta;
-import com.google.common.base.Preconditions;
 import com.google.common.collect.Iterables;
 import java.io.IOException;
 import java.util.Collection;
@@ -56,7 +56,7 @@ public class ParameterAwareNormalizedNodeWriter implements RestconfNormalizedNod
 
     private ParameterAwareNormalizedNodeWriter(final NormalizedNodeStreamWriter writer, final Integer maxDepth,
                                                final List<Set<QName>> fields) {
-        this.writer = Preconditions.checkNotNull(writer);
+        this.writer = requireNonNull(writer);
         this.maxDepth = maxDepth;
         this.fields = fields;
     }
index e187b60102a676b3f43ec48ceacde908afc72482..97f04909473ae89e41df6d192d8a7574155c9a16 100644 (file)
@@ -7,8 +7,8 @@
  */
 package org.opendaylight.restconf.nb.rfc8040.rests.utils;
 
-import com.google.common.collect.Maps;
 import com.google.common.util.concurrent.FluentFuture;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
@@ -122,7 +122,7 @@ public final class PutDataTransactionUtil {
 
     private static void isEqualUriAndPayloadKeyValues(final Map<QName, Object> uriKeyValues, final MapEntryNode payload,
             final List<QName> keyDefinitions) {
-        final Map<QName, Object> mutableCopyUriKeyValues = Maps.newHashMap(uriKeyValues);
+        final Map<QName, Object> mutableCopyUriKeyValues = new HashMap<>(uriKeyValues);
         for (final QName keyDefinition : keyDefinitions) {
             final Object uriKeyValue = RestconfDocumentedException.throwIfNull(
                 mutableCopyUriKeyValues.remove(keyDefinition), ErrorType.PROTOCOL, ErrorTag.DATA_MISSING,
index 3d7feae3fd3e104954223de720ebe310fb6920d8..24418c9efff5a4487660bbeeae80da4cae90276f 100644 (file)
@@ -7,7 +7,8 @@
  */
 package org.opendaylight.restconf.nb.rfc8040.services.simple.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 eff7662440ded76304de46d942d53db63069a086..e11df85ef6af1d858e7d27eda745e3500daa9c95 100644 (file)
@@ -7,7 +7,8 @@
  */
 package org.opendaylight.restconf.nb.rfc8040.services.simple.impl;
 
-import com.google.common.base.Preconditions;
+import static java.util.Objects.requireNonNull;
+
 import java.util.Optional;
 import org.opendaylight.yangtools.concepts.SemVer;
 import org.opendaylight.yangtools.yang.common.Revision;
@@ -23,7 +24,7 @@ final class FakeModuleImport implements ModuleImport {
     private final Module module;
 
     FakeModuleImport(final Module module) {
-        this.module = Preconditions.checkNotNull(module);
+        this.module = requireNonNull(module);
     }
 
     @Override
index feb60142b4f6fbc6556bae582987f547a76922e5..15b217da1b6714b917974f769a99c9849d344987 100644 (file)
@@ -7,8 +7,9 @@
  */
 package org.opendaylight.restconf.nb.rfc8040.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 javax.xml.XMLConstants;
@@ -68,7 +69,7 @@ abstract class AbstractQueryParams extends AbstractNotificationsData {
     @SuppressWarnings("checkstyle:hiddenField")
     public void setQueryParams(final Instant start, final Instant stop, final String filter,
             final boolean leafNodesOnly) {
-        this.start = Preconditions.checkNotNull(start);
+        this.start = requireNonNull(start);
         this.stop = stop;
         this.filter = filter;
         this.leafNodesOnly = leafNodesOnly;
index ac3f4aeaf7192b11c9f10f21d45af04cadd99c3a..c241a63281b861bdcefbf2ebac993fe60f6212db 100644 (file)
@@ -7,8 +7,11 @@
  */
 package org.opendaylight.restconf.nb.rfc8040.streams.listeners;
 
+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.base.MoreObjects;
-import com.google.common.base.Preconditions;
 import java.io.IOException;
 import java.time.Instant;
 import java.util.Collection;
@@ -63,10 +66,10 @@ public class ListenerAdapter extends AbstractCommonSubscriber implements Cluster
             final NotificationOutputType outputType) {
         setLocalNameOfPath(path.getLastPathArgument().getNodeType().getLocalName());
 
-        this.outputType = Preconditions.checkNotNull(outputType);
-        this.path = Preconditions.checkNotNull(path);
-        Preconditions.checkArgument(streamName != null && !streamName.isEmpty());
-        this.streamName = streamName;
+        this.outputType = requireNonNull(outputType);
+        this.path = requireNonNull(path);
+        this.streamName = requireNonNull(streamName);
+        checkArgument(!streamName.isEmpty());
     }
 
     @Override
@@ -190,7 +193,7 @@ public class ListenerAdapter extends AbstractCommonSubscriber implements Cluster
                 .append(normalizedNode.getIdentifier()).build();
 
         final Optional<DataSchemaContextNode<?>> childrenSchemaNode = dataSchemaContextTree.findChild(yiid);
-        Preconditions.checkState(childrenSchemaNode.isPresent());
+        checkState(childrenSchemaNode.isPresent());
         boolean isNodeMixin = childrenSchemaNode.get().isMixin();
         boolean isSkippedNonLeaf = getLeafNodesOnly() && !(normalizedNode instanceof LeafNode);
         if (!isNodeMixin && !isSkippedNonLeaf) {
@@ -258,7 +261,7 @@ public class ListenerAdapter extends AbstractCommonSubscriber implements Cluster
         try {
             SchemaPath nodePath;
             final Optional<DataSchemaContextNode<?>> childrenSchemaNode = dataSchemaContextTree.findChild(eventPath);
-            Preconditions.checkState(childrenSchemaNode.isPresent());
+            checkState(childrenSchemaNode.isPresent());
             if (normalized instanceof MapEntryNode || normalized instanceof UnkeyedListEntryNode) {
                 nodePath = childrenSchemaNode.get().getDataSchemaNode().getPath();
             } else {
index bbfad3127c369cc6eddeb74b324aaaf5dc60e222..8d95aca7880d3d79f629ab681bddc87446945355 100644 (file)
@@ -7,9 +7,11 @@
  */
 package org.opendaylight.restconf.nb.rfc8040.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.MoreObjects;
-import com.google.common.base.Preconditions;
 import com.google.gson.JsonObject;
 import com.google.gson.JsonParser;
 import java.io.IOException;
@@ -55,10 +57,10 @@ public class NotificationListenerAdapter extends AbstractCommonSubscriber implem
     NotificationListenerAdapter(final SchemaPath path, final String streamName, final String outputType) {
         setLocalNameOfPath(path.getLastComponent().getLocalName());
 
-        this.outputType = Preconditions.checkNotNull(outputType);
-        this.path = Preconditions.checkNotNull(path);
-        Preconditions.checkArgument(streamName != null && !streamName.isEmpty());
-        this.streamName = streamName;
+        this.outputType = requireNonNull(outputType);
+        this.path = requireNonNull(path);
+        this.streamName = requireNonNull(streamName);
+        checkArgument(!streamName.isEmpty());
     }
 
     /**
index aa79fdedf9e0d878c4f9f7d25214a3137bb60a7b..4a6f7607a6538f05a40f12034a9b3a1c78f0f1a6 100644 (file)
@@ -7,12 +7,13 @@
  */
 package org.opendaylight.restconf.nb.rfc8040;
 
+import static com.google.common.base.Preconditions.checkArgument;
+import static java.util.Objects.requireNonNull;
 import static org.junit.Assert.assertNotNull;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 
-import com.google.common.base.Preconditions;
 import java.io.BufferedReader;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
@@ -114,7 +115,6 @@ public final class TestUtils {
     }
 
     public static String getDocumentInPrintableForm(final Document doc) {
-        Preconditions.checkNotNull(doc);
         try {
             final ByteArrayOutputStream out = new ByteArrayOutputStream();
             final TransformerFactory tf = TransformerFactory.newInstance();
@@ -125,7 +125,7 @@ public final class TestUtils {
             transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
             transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
 
-            transformer.transform(new DOMSource(doc), new StreamResult(new OutputStreamWriter(out,
+            transformer.transform(new DOMSource(requireNonNull(doc)), new StreamResult(new OutputStreamWriter(out,
                 StandardCharsets.UTF_8)));
             final byte[] charData = out.toByteArray();
             return new String(charData, StandardCharsets.UTF_8);
@@ -235,8 +235,7 @@ public final class TestUtils {
 
     public static NodeIdentifierWithPredicates getNodeIdentifierPredicate(final String localName,
             final String namespace, final String revision, final String... keysAndValues) throws ParseException {
-        Preconditions.checkArgument(keysAndValues.length % 2 == 0,
-                "number of keys argument have to be divisible by 2 (map)");
+        checkArgument(keysAndValues.length % 2 == 0, "number of keys argument have to be divisible by 2 (map)");
         final Map<QName, Object> predicate = new HashMap<>();
 
         int index = 0;
index 4f923eb120fe68615b9baa2a97f89bc05641d926..851dae944913938cc1668645d6fb8e364db8ae06 100644 (file)
@@ -7,12 +7,12 @@
  */
 package org.opendaylight.restconf.nb.rfc8040.streams.listeners;
 
+import static java.util.Objects.requireNonNull;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-import com.google.common.base.Preconditions;
 import com.google.common.collect.Lists;
 import java.net.URI;
 import java.util.ArrayList;
@@ -214,7 +214,6 @@ public class NotificationListenerTest {
     private String prepareJson(final DOMNotification notificationData, final SchemaPath schemaPathNotifi) {
         final NotificationListenerAdapter notifiAdapter = ListenersBroker.getInstance().registerNotificationListener(
                 schemaPathNotifi, "stream-name", NotificationOutputType.JSON);
-        final String result = notifiAdapter.prepareJson(schmeaCtx, notificationData);
-        return Preconditions.checkNotNull(result);
+        return requireNonNull(notifiAdapter.prepareJson(schmeaCtx, notificationData));
     }
 }