Modernize BindingStructuralType 63/101363/3
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 30 May 2022 15:54:59 +0000 (17:54 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 30 May 2022 17:12:49 +0000 (19:12 +0200)
Use switch expressions to remove an unused default case.

Change-Id: I5bbbcafebfb24af79c0ecb4d16b5dc6d9425c3d9
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/BindingStructuralType.java

index 7fabbeab785d6f752c2ff3419bd13c5534b52ec2..841574750c31f69828a354bb4ad3f663d017b2a1 100644 (file)
@@ -108,31 +108,23 @@ public enum BindingStructuralType {
 
     public static BindingStructuralType recursiveFrom(final DataTreeCandidateNode node) {
         final BindingStructuralType type = BindingStructuralType.from(node);
-        switch (type) {
-            case INVISIBLE_CONTAINER:
-            case INVISIBLE_LIST:
+        return switch (type) {
+            case INVISIBLE_CONTAINER, INVISIBLE_LIST -> {
                 // This node is invisible, try to resolve using a child node
                 for (final DataTreeCandidateNode child : node.getChildNodes()) {
                     final BindingStructuralType childType = recursiveFrom(child);
-                    switch (childType) {
-                        case INVISIBLE_CONTAINER:
-                        case INVISIBLE_LIST:
-                            // Invisible nodes are not addressable
-                            return BindingStructuralType.NOT_ADDRESSABLE;
-                        case NOT_ADDRESSABLE:
-                        case UNKNOWN:
-                        case VISIBLE_CONTAINER:
-                            return childType;
-                        default:
-                            throw new IllegalStateException("Unhandled child type " + childType + " for child "
-                                    + child);
-                    }
+                    yield switch (childType) {
+                            case INVISIBLE_CONTAINER, INVISIBLE_LIST ->
+                                // Invisible nodes are not addressable
+                                BindingStructuralType.NOT_ADDRESSABLE;
+                            case NOT_ADDRESSABLE, UNKNOWN, VISIBLE_CONTAINER -> childType;
+                        };
                 }
 
-                return BindingStructuralType.NOT_ADDRESSABLE;
-            default:
-                return type;
-        }
+                yield BindingStructuralType.NOT_ADDRESSABLE;
+            }
+            default -> type;
+        };
     }
 
     private static boolean isVisibleContainer(final NormalizedNode data) {