Cleanup requireNonNull() use in NormalizedNodes 89/84489/1
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 15 Sep 2019 22:07:49 +0000 (00:07 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 16 Sep 2019 00:06:54 +0000 (02:06 +0200)
Take advantage of the non-null return to save a tiny bit of bytecode.

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

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

index 8a2f32fc8a9499210b0efe7410d2478d08a45510..829f98b671f42f5c265468dcdb0debe7b92cf382 100644 (file)
@@ -38,6 +38,17 @@ public final class NormalizedNodes {
         throw new UnsupportedOperationException("Utility class should not be instantiated");
     }
 
+    /**
+     * Find duplicate NormalizedNode instances within a subtree. Duplicates are those, which compare
+     * as equal, but do not refer to the same object.
+     *
+     * @param node A normalized node subtree, may not be null
+     * @return A Map of NormalizedNode/DuplicateEntry relationships.
+     */
+    public static Map<NormalizedNode<?, ?>, DuplicateEntry> findDuplicates(final @NonNull NormalizedNode<?, ?> node) {
+        return Maps.filterValues(DuplicateFinder.findDuplicates(node), input -> !input.getDuplicates().isEmpty());
+    }
+
     public static Optional<NormalizedNode<?, ?>> findNode(final YangInstanceIdentifier rootPath,
             final NormalizedNode<?, ?> rootNode, final YangInstanceIdentifier childPath) {
         final Optional<YangInstanceIdentifier> relativePath = childPath.relativeTo(rootPath);
@@ -46,11 +57,9 @@ public final class NormalizedNodes {
 
     public static Optional<NormalizedNode<?, ?>> findNode(final Optional<NormalizedNode<?, ?>> parent,
             final Iterable<PathArgument> relativePath) {
-        requireNonNull(parent, "Parent must not be null");
-        requireNonNull(relativePath, "Relative path must not be null");
-
-        Optional<NormalizedNode<?, ?>> currentNode = parent;
-        final Iterator<PathArgument> pathIterator = relativePath.iterator();
+        final Iterator<PathArgument> pathIterator = requireNonNull(relativePath, "Relative path must not be null")
+                .iterator();
+        Optional<NormalizedNode<?, ?>> currentNode = requireNonNull(parent, "Parent must not be null");
         while (currentNode.isPresent() && pathIterator.hasNext()) {
             currentNode = getDirectChild(currentNode.get(), pathIterator.next());
         }
@@ -81,10 +90,8 @@ public final class NormalizedNodes {
 
     public static Optional<NormalizedNode<?, ?>> findNode(final NormalizedNode<?, ?> tree,
             final YangInstanceIdentifier path) {
-        requireNonNull(tree, "Tree must not be null");
-        requireNonNull(path, "Path must not be null");
-
-        return findNode(Optional.of(tree), path.getPathArguments());
+        return findNode(Optional.of(requireNonNull(tree, "Tree must not be null")),
+            requireNonNull(path, "Path must not be null").getPathArguments());
     }
 
     @SuppressWarnings({ "unchecked", "rawtypes" })
@@ -142,15 +149,4 @@ public final class NormalizedNodes {
             return identifier.getNodeType().getLocalName();
         }
     }
-
-    /**
-     * Find duplicate NormalizedNode instances within a subtree. Duplicates are those, which compare
-     * as equal, but do not refer to the same object.
-     *
-     * @param node A normalized node subtree, may not be null
-     * @return A Map of NormalizedNode/DuplicateEntry relationships.
-     */
-    public static Map<NormalizedNode<?, ?>, DuplicateEntry> findDuplicates(final @NonNull NormalizedNode<?, ?> node) {
-        return Maps.filterValues(DuplicateFinder.findDuplicates(node), input -> !input.getDuplicates().isEmpty());
-    }
 }