Modernize yang-data-tree-ri
[yangtools.git] / data / yang-data-tree-ri / src / main / java / org / opendaylight / yangtools / yang / data / tree / impl / SchemaAwareApplyOperation.java
index fc28dd1e7b5822424ddf200124f0d56f2ee935b4..8cf9daeebf70d8e0bd3d1b4cbcb2480ff625d49c 100644 (file)
@@ -50,25 +50,18 @@ abstract sealed class SchemaAwareApplyOperation<T extends DataSchemaNode> extend
         if (!belongsToTree(treeConfig.getTreeType(), schemaNode)) {
             throw new ExcludedDataSchemaNodeException(schemaNode + " does not belong to configuration tree");
         }
-        if (schemaNode instanceof ContainerSchemaNode container) {
-            return ContainerModificationStrategy.of(container, treeConfig);
-        } else if (schemaNode instanceof ListSchemaNode list) {
-            return fromListSchemaNode(list, treeConfig);
-        } else if (schemaNode instanceof ChoiceSchemaNode choice) {
-            return new ChoiceModificationStrategy(choice, treeConfig);
-        } else if (schemaNode instanceof LeafListSchemaNode leafList) {
-            return MinMaxElementsValidation.from(new LeafSetModificationStrategy(leafList, treeConfig));
-        } else if (schemaNode instanceof LeafSchemaNode leaf) {
-            return new ValueNodeModificationStrategy<>(LeafNode.class, leaf);
-        } else if (schemaNode instanceof AnydataSchemaNode anydata) {
-            return new ValueNodeModificationStrategy<>(AnydataNode.class, anydata);
-        } else if (schemaNode instanceof AnyxmlSchemaNode anyxml) {
-            return new ValueNodeModificationStrategy<>(AnyxmlNode.class, anyxml);
-        } else if (schemaNode instanceof SchemaContext context) {
-            return new ContainerModificationStrategy.Structural(context, treeConfig);
-        } else {
-            throw new IllegalStateException("Unsupported schema " + schemaNode);
-        }
+        return switch (schemaNode) {
+            case AnydataSchemaNode anydata -> new ValueNodeModificationStrategy<>(AnydataNode.class, anydata);
+            case AnyxmlSchemaNode anyxml -> new ValueNodeModificationStrategy<>(AnyxmlNode.class, anyxml);
+            case ChoiceSchemaNode choice -> new ChoiceModificationStrategy(choice, treeConfig);
+            case ContainerSchemaNode container -> ContainerModificationStrategy.of(container, treeConfig);
+            case LeafSchemaNode leaf -> new ValueNodeModificationStrategy<>(LeafNode.class, leaf);
+            case LeafListSchemaNode leafList ->
+                MinMaxElementsValidation.from(new LeafSetModificationStrategy(leafList, treeConfig));
+            case ListSchemaNode list -> fromListSchemaNode(list, treeConfig);
+            case SchemaContext context -> new ContainerModificationStrategy.Structural(context, treeConfig);
+            default -> throw new IllegalStateException("Unsupported schema " + schemaNode);
+        };
     }
 
     static void checkConflicting(final ModificationPath path, final boolean condition, final String message)