X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=yang%2Fyang-data-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fdata%2Fimpl%2Fschema%2Ftree%2FAbstractModifiedNodeBasedCandidateNode.java;h=439c43193a9bc228dcaa808b277a3d4b86a43478;hb=1057e76d8a8a17b0103ee437b6d7d9ba5ba9ca77;hp=76b3131b6b6518317523ea71d55ed9b67fe85c9d;hpb=6204e3cddac855bfd6d00be3b16acfc10752bb5b;p=yangtools.git diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/AbstractModifiedNodeBasedCandidateNode.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/AbstractModifiedNodeBasedCandidateNode.java index 76b3131b6b..439c43193a 100644 --- a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/AbstractModifiedNodeBasedCandidateNode.java +++ b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/AbstractModifiedNodeBasedCandidateNode.java @@ -13,6 +13,7 @@ import com.google.common.base.Verify; import com.google.common.collect.Collections2; import java.util.Collection; import java.util.Collections; +import javax.annotation.Nonnull; import javax.annotation.Nullable; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; @@ -23,7 +24,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode; abstract class AbstractModifiedNodeBasedCandidateNode implements DataTreeCandidateNode { - private static final Function, DataTreeCandidateNode> TO_UNMODIFIED_NODES = new Function, DataTreeCandidateNode>() { + private static final Function, DataTreeCandidateNode> TO_UNMODIFIED_NODE = new Function, DataTreeCandidateNode>() { @Override public DataTreeCandidateNode apply(final NormalizedNode input) { return AbstractRecursiveCandidateNode.unmodifiedNode(input); @@ -82,8 +83,11 @@ abstract class AbstractModifiedNodeBasedCandidateNode implements DataTreeCandida } @Override + @Nonnull public Collection getChildNodes() { switch (mod.getModificationType()) { + case APPEARED: + case DISAPPEARED: case SUBTREE_MODIFIED: return Collections2.transform(mod.getChildren(), new Function() { @Override @@ -95,7 +99,7 @@ abstract class AbstractModifiedNodeBasedCandidateNode implements DataTreeCandida // Unmodified node, but we still need to resolve potential children. canHaveChildren returns // false if both arguments are null. if (canHaveChildren(oldMeta, newMeta)) { - return Collections2.transform(getContainer(newMeta != null ? newMeta : oldMeta).getValue(), TO_UNMODIFIED_NODES); + return Collections2.transform(getContainer(newMeta != null ? newMeta : oldMeta).getValue(), TO_UNMODIFIED_NODE); } else { return Collections.emptyList(); } @@ -114,6 +118,7 @@ abstract class AbstractModifiedNodeBasedCandidateNode implements DataTreeCandida } @Override + @Nonnull public ModificationType getModificationType() { return Verify.verifyNotNull(mod.getModificationType(), "Node %s does not have resolved modification type", mod); } @@ -127,11 +132,13 @@ abstract class AbstractModifiedNodeBasedCandidateNode implements DataTreeCandida } @Override + @Nonnull public final Optional> getDataAfter() { return optionalData(newMeta); } @Override + @Nonnull public final Optional> getDataBefore() { return optionalData(oldMeta); } @@ -139,23 +146,32 @@ abstract class AbstractModifiedNodeBasedCandidateNode implements DataTreeCandida @Override public final DataTreeCandidateNode getModifiedChild(final PathArgument identifier) { switch (mod.getModificationType()) { + case APPEARED: + case DISAPPEARED: case SUBTREE_MODIFIED: final Optional childMod = mod.getChild(identifier); if (childMod.isPresent()) { return childNode(childMod.get()); } return null; - case DELETE: case UNMODIFIED: - case WRITE: - // FIXME: this is a linear walk. We need a Map of these in order to - // do something like getChildMap().get(identifier); - for (DataTreeCandidateNode c : getChildNodes()) { - if (identifier.equals(c.getIdentifier())) { - return c; + if (canHaveChildren(oldMeta, newMeta)) { + final Optional> maybeChild = getContainer(newMeta != null ? newMeta : oldMeta).getChild(identifier); + if (maybeChild.isPresent()) { + return TO_UNMODIFIED_NODE.apply(maybeChild.get()); + } else { + return null; } + } else { + return null; + } + case DELETE: + case WRITE: + if (canHaveChildren(oldMeta, newMeta)) { + return AbstractDataTreeCandidateNode.deltaChild(getContainer(oldMeta), getContainer(newMeta), identifier); + } else { + return null; } - return null; default: throw new IllegalArgumentException("Unhandled modification type " + mod.getModificationType()); } @@ -167,8 +183,15 @@ abstract class AbstractModifiedNodeBasedCandidateNode implements DataTreeCandida } @Override + @Nonnull public PathArgument getIdentifier() { return getMod().getIdentifier(); } } -} \ No newline at end of file + + @Override + public String toString() { + return this.getClass().getSimpleName() + "{mod = " + this.mod + ", oldMeta = " + this.oldMeta + ", newMeta = " + + this.newMeta + "}"; + } +}