From: Robert Varga Date: Tue, 25 Oct 2022 13:10:25 +0000 (+0200) Subject: Use instanceof patterns in NormalizedNodeStreamWriterStack X-Git-Tag: v10.0.0~37 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F69%2F102869%2F1;p=yangtools.git Use instanceof patterns in NormalizedNodeStreamWriterStack We have a few places where we can apply these shortcuts, improving safety and expressiveness. Change-Id: I80bfbab9adb21ae2f0727d9e52135a103d0ecba8 Signed-off-by: Robert Varga --- diff --git a/data/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/NormalizedNodeStreamWriterStack.java b/data/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/NormalizedNodeStreamWriterStack.java index 081cf686da..d065386cf1 100644 --- a/data/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/NormalizedNodeStreamWriterStack.java +++ b/data/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/NormalizedNodeStreamWriterStack.java @@ -189,8 +189,8 @@ public final class NormalizedNodeStreamWriterStack implements LeafrefResolver { verify(stmt instanceof SchemaNode, "Unexpected result %s", stmt); final SchemaNode ret = (SchemaNode) stmt; final Object parent = getParent(); - if (parent instanceof ChoiceSchemaNode) { - final DataSchemaNode check = ((ChoiceSchemaNode) parent).findDataSchemaChild(qname).orElse(null); + if (parent instanceof ChoiceSchemaNode choice) { + final DataSchemaNode check = choice.findDataSchemaChild(qname).orElse(null); verify(check == ret, "Data tree result %s does not match choice result %s", ret, check); } return ret; @@ -223,8 +223,8 @@ public final class NormalizedNodeStreamWriterStack implements LeafrefResolver { public LeafListSchemaNode leafSetEntryNode(final QName qname) { final Object parent = getParent(); - if (parent instanceof LeafListSchemaNode) { - return (LeafListSchemaNode) parent; + if (parent instanceof LeafListSchemaNode leafList) { + return leafList; } checkArgument(parent instanceof DataNodeContainer, "Cannot lookup %s in parent %s", qname, parent); final DataSchemaNode child = ((DataNodeContainer) parent).dataChildByName(qname); @@ -250,12 +250,12 @@ public final class NormalizedNodeStreamWriterStack implements LeafrefResolver { LOG.debug("Enter container {}", name); final SchemaNode schema; - if (schemaStack.isEmpty() && root instanceof NotificationDefinition) { + if (schemaStack.isEmpty() && root instanceof NotificationDefinition notification) { // Special case for stacks initialized at notification. We pretend the first container is contained within // itself. // FIXME: 8.0.0: factor this special case out to something more reasonable, like being initialized at the // Notification's parent and knowing to enterSchemaTree() instead of enterDataTree(). - schema = (NotificationDefinition) root; + schema = notification; } else { schema = enterDataTree(name); checkArgument(schema instanceof ContainerLike, "Node %s is not a container", schema); @@ -292,9 +292,9 @@ public final class NormalizedNodeStreamWriterStack implements LeafrefResolver { Object parent = getParent(); checkArgument(parent instanceof AugmentationTarget, "Augmentation not allowed under %s", parent); - if (parent instanceof ChoiceSchemaNode) { + if (parent instanceof ChoiceSchemaNode choice) { final QName name = Iterables.get(identifier.getPossibleChildNames(), 0); - parent = findCaseByChild((ChoiceSchemaNode) parent, name); + parent = findCaseByChild(choice, name); } checkArgument(parent instanceof DataNodeContainer, "Augmentation allowed only in DataNodeContainer", parent); final AugmentationSchemaNode schema = findSchemaForAugment((AugmentationTarget) parent,