Use java.util.Optional 80/94480/1
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 7 Jan 2021 16:39:56 +0000 (17:39 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 7 Jan 2021 16:39:56 +0000 (17:39 +0100)
This is the last real place where we use Guava's Optional, migrate
it.

Change-Id: Iba87bc765af007a2db13cc68bf386b8931c0ff05
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/api/JSONRestconfService.java
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/JSONRestconfServiceImpl.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/JSONRestconfServiceImplTest.java

index 3fa3654c2a7fd50d33dc86ab0371065a9a9fb038..5e3426c3b65c5860cb68229daa7a13237789b61c 100644 (file)
@@ -7,7 +7,7 @@
  */
 package org.opendaylight.netconf.sal.restconf.api;
 
-import com.google.common.base.Optional;
+import java.util.Optional;
 import javax.ws.rs.core.MultivaluedMap;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
index 9c64e0df2903abb3ba50a4d682a968d80affaa01..61ef37b38b104885d2cd8cd9a9ae4bc6d9bc8401 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.netconf.sal.restconf.impl;
 
 import static java.util.Objects.requireNonNull;
 
-import com.google.common.base.Optional;
 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
@@ -18,6 +17,7 @@ import java.io.InputStream;
 import java.lang.annotation.Annotation;
 import java.nio.charset.StandardCharsets;
 import java.util.List;
+import java.util.Optional;
 import javax.inject.Inject;
 import javax.inject.Singleton;
 import javax.ws.rs.core.MediaType;
@@ -149,7 +149,7 @@ public class JSONRestconfServiceImpl implements JSONRestconfService {
             }
 
             LOG.debug("Data missing - returning absent");
-            return Optional.absent();
+            return Optional.empty();
         }
     }
 
@@ -188,7 +188,7 @@ public class JSONRestconfServiceImpl implements JSONRestconfService {
             propagateExceptionAs(uriPath, e, "RPC");
         }
 
-        return Optional.fromNullable(output);
+        return Optional.ofNullable(output);
     }
 
     @SuppressWarnings("checkstyle:IllegalCatch")
@@ -216,7 +216,7 @@ public class JSONRestconfServiceImpl implements JSONRestconfService {
         } catch (final Exception e) {
             propagateExceptionAs(uriPath, e, "PATCH");
         }
-        return Optional.fromNullable(output);
+        return Optional.ofNullable(output);
     }
 
     @SuppressWarnings("checkstyle:IllegalCatch")
@@ -236,7 +236,7 @@ public class JSONRestconfServiceImpl implements JSONRestconfService {
             propagateExceptionAs(identifier, e, "RPC");
         }
 
-        return Optional.fromNullable(jsonRes);
+        return Optional.ofNullable(jsonRes);
     }
 
     private static String toJson(final PatchStatusContext patchStatusContext) throws IOException {
index e1571aa58c36d025258f8a23341655880e208511..f09360ae5a5b3af23f970a840fdcbd99e95838c3 100644 (file)
@@ -24,13 +24,13 @@ import static org.mockito.Mockito.when;
 import static org.opendaylight.yangtools.util.concurrent.FluentFutures.immediateFailedFluentFuture;
 import static org.opendaylight.yangtools.util.concurrent.FluentFutures.immediateFluentFuture;
 
-import com.google.common.base.Optional;
 import com.google.common.io.Resources;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Optional;
 import javax.ws.rs.core.Response.Status;
 import org.junit.Before;
 import org.junit.BeforeClass;
@@ -445,7 +445,7 @@ public class JSONRestconfServiceImplTest {
 
         final String uriPath = "toaster:cancel-toast";
 
-        final Optional<String> output = this.service.invokeRpc(uriPath, Optional.absent());
+        final Optional<String> output = this.service.invokeRpc(uriPath, Optional.empty());
 
         assertEquals("Output present", false, output.isPresent());
 
@@ -462,7 +462,7 @@ public class JSONRestconfServiceImplTest {
 
         final String uriPath = "toaster:testOutput";
 
-        final Optional<String> output = this.service.invokeRpc(uriPath, Optional.absent());
+        final Optional<String> output = this.service.invokeRpc(uriPath, Optional.empty());
 
         assertEquals("Output present", true, output.isPresent());
         assertNotNull("Returned null response", output.get());
@@ -479,7 +479,7 @@ public class JSONRestconfServiceImplTest {
 
         final String uriPath = "toaster:cancel-toast";
 
-        this.service.invokeRpc(uriPath, Optional.absent());
+        this.service.invokeRpc(uriPath, Optional.empty());
     }
 
     void testGet(final LogicalDatastoreType datastoreType) throws OperationFailedException {