Add NodeIdentifierWithPredicates.containsKey() 46/84346/2
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 12 Sep 2019 15:16:05 +0000 (17:16 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 12 Sep 2019 17:12:19 +0000 (19:12 +0200)
This is a useful check, which can be performed via getValue()
and checking for null return, but implementations can perform
it a wee bit more quickly.

Change-Id: I2182870ca3cfba082c6cebafe947643d5e191f4a
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 553dadbff0756bb7555545cd264916f6f2bd2101)

yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/YangInstanceIdentifier.java

index caaf5b9217b5a6b88796d98a793f9a77f006e131..542c802171c19b62ee75cf1c3f0ba24dc5eb8935 100644 (file)
@@ -676,6 +676,18 @@ public abstract class YangInstanceIdentifier implements Path<YangInstanceIdentif
             return keyValues.keySet();
         }
 
+        /**
+         * Determine whether a particular predicate key is present.
+         *
+         * @param key Predicate key
+         * @return True if the predicate is present, false otherwise
+         * @throws NullPointerException if {@code key} is null
+         */
+        @Beta
+        public boolean containsKey(final QName key) {
+            return keyValues.containsKey(requireNonNull(key));
+        }
+
         /**
          * Return the predicate values in the iteration order of {@link #entrySet()}.
          *