Use YangInstanceIdentifier.isEmpty() 65/71565/4
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 30 Apr 2018 09:06:26 +0000 (11:06 +0200)
committerStephen Kitt <skitt@redhat.com>
Mon, 30 Apr 2018 15:16:14 +0000 (15:16 +0000)
This is a faster way of checking if an InstanceIdentifier is empty
than comparison to a constant.

Change-Id: I095576cdf1ac522348f3befaa8b14e84feaddf1c
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionProxy.java

index aca4e41..4b8dc45 100644 (file)
@@ -104,14 +104,10 @@ public class TransactionProxy extends AbstractDOMStoreTransaction<TransactionIde
     public CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read(final YangInstanceIdentifier path) {
         Preconditions.checkState(type != TransactionType.WRITE_ONLY,
                 "Reads from write-only transactions are not allowed");
+        Preconditions.checkNotNull(path, "path should not be null");
 
         LOG.trace("Tx {} read {}", getIdentifier(), path);
-
-        if (YangInstanceIdentifier.EMPTY.equals(path)) {
-            return readAllData();
-        } else {
-            return singleShardRead(shardNameFromIdentifier(path), path);
-        }
+        return path.isEmpty() ? readAllData() :  singleShardRead(shardNameFromIdentifier(path), path);
     }
 
     private CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> singleShardRead(

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.