Use switch expressions in NetconfRestconfStrategy 83/107083/1
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 26 Jul 2023 15:01:07 +0000 (17:01 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 26 Jul 2023 15:01:07 +0000 (17:01 +0200)
We are switching on a well-established enum, use switch expressions to
eliminate never-taken paths.

Change-Id: I1f5aaca2b8a8b683b41570ef4c0eb314688082d7
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/NetconfRestconfStrategy.java

index 4cb04a0b461a3fc8dd227016f243a12368d6311d..e1f6b1efb61edc935ead60029cfad0aed6ef266c 100644 (file)
@@ -22,8 +22,6 @@ import org.opendaylight.mdsal.common.api.ReadFailedException;
 import org.opendaylight.netconf.dom.api.NetconfDataTreeService;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /**
  * Implementation of RESTCONF operations on top of a raw NETCONF backend.
@@ -31,8 +29,6 @@ import org.slf4j.LoggerFactory;
  * @see NetconfDataTreeService
  */
 public final class NetconfRestconfStrategy extends RestconfStrategy {
-    private static final Logger LOG = LoggerFactory.getLogger(NetconfRestconfStrategy.class);
-
     private final NetconfDataTreeService netconfService;
 
     public NetconfRestconfStrategy(final NetconfDataTreeService netconfService) {
@@ -47,33 +43,19 @@ public final class NetconfRestconfStrategy extends RestconfStrategy {
     @Override
     public ListenableFuture<Optional<NormalizedNode>> read(final LogicalDatastoreType store,
             final YangInstanceIdentifier path) {
-        switch (store) {
-            case CONFIGURATION:
-                return netconfService.getConfig(path);
-            case OPERATIONAL:
-                return netconfService.get(path);
-            default:
-                LOG.info("Unknown datastore type: {}.", store);
-                throw new IllegalArgumentException(String.format(
-                        "%s, Cannot read data %s for %s datastore, unknown datastore type",
-                        netconfService.getDeviceId(), path, store));
-        }
+        return switch (store) {
+            case CONFIGURATION -> netconfService.getConfig(path);
+            case OPERATIONAL -> netconfService.get(path);
+        };
     }
 
     @Override
     public ListenableFuture<Optional<NormalizedNode>> read(final LogicalDatastoreType store,
             final YangInstanceIdentifier path, final List<YangInstanceIdentifier> fields) {
-        switch (store) {
-            case CONFIGURATION:
-                return netconfService.getConfig(path, fields);
-            case OPERATIONAL:
-                return netconfService.get(path, fields);
-            default:
-                LOG.info("Unknown datastore type: {}.", store);
-                throw new IllegalArgumentException(String.format(
-                        "%s, Cannot read data %s with fields %s for %s datastore, unknown datastore type",
-                        netconfService.getDeviceId(), path, fields, store));
-        }
+        return switch (store) {
+            case CONFIGURATION -> netconfService.getConfig(path, fields);
+            case OPERATIONAL -> netconfService.get(path, fields);
+        };
     }
 
     @Override