Clean up NormalizedNodeSchemaUtils 57/104457/2
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 21 Feb 2023 14:44:38 +0000 (15:44 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 21 Feb 2023 15:36:38 +0000 (16:36 +0100)
Use instanceof pattern to simplify casts. Also simplify
findCorrespondingAugment(), making the logic more obvious.

Change-Id: I7f134d333aa2543169acdf30a5e4e116bb7ca22e
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
data/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/NormalizedNodeSchemaUtils.java

index cec10592e7160bacd8679c8047ed079d79d6ab3b..c37faab53a4a2974a1c50826835defeef6037b45 100644 (file)
@@ -29,8 +29,8 @@ public final class NormalizedNodeSchemaUtils {
     }
 
     public static Optional<CaseSchemaNode> detectCase(final ChoiceSchemaNode schema, final DataContainerChild child) {
-        if (child instanceof AugmentationNode) {
-            return detectCase(schema, (AugmentationNode) child);
+        if (child instanceof AugmentationNode augment) {
+            return detectCase(schema, augment);
         }
 
         final QName childId = child.getIdentifier().getNodeType();
@@ -79,13 +79,11 @@ public final class NormalizedNodeSchemaUtils {
      */
     public static AugmentationSchemaNode findCorrespondingAugment(final DataSchemaNode parent,
             final DataSchemaNode child) {
-        if (!(parent instanceof AugmentationTarget) || parent instanceof ChoiceSchemaNode) {
-            return null;
-        }
-
-        for (final AugmentationSchemaNode augmentation : ((AugmentationTarget) parent).getAvailableAugmentations()) {
-            if (augmentation.dataChildByName(child.getQName()) != null) {
-                return augmentation;
+        if (parent instanceof AugmentationTarget target && !(parent instanceof ChoiceSchemaNode)) {
+            for (final AugmentationSchemaNode augmentation : target.getAvailableAugmentations()) {
+                if (augmentation.dataChildByName(child.getQName()) != null) {
+                    return augmentation;
+                }
             }
         }
         return null;