From ffc3964fb99479a6c48c068320b60a501aa7a402 Mon Sep 17 00:00:00 2001 From: Maros Marsalek Date: Wed, 22 Jun 2016 14:35:29 +0200 Subject: HONEYCOMB-92 Ignore empty modifications for e.g. empty presence containers Change-Id: I565686dbd2474fffbfea4e8cc837861845723bda Signed-off-by: Maros Marsalek --- .../data/impl/ModifiableDataTreeDelegator.java | 44 +++++++++++----------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'v3po/data-impl/src/main/java/io/fd/honeycomb/v3po') diff --git a/v3po/data-impl/src/main/java/io/fd/honeycomb/v3po/data/impl/ModifiableDataTreeDelegator.java b/v3po/data-impl/src/main/java/io/fd/honeycomb/v3po/data/impl/ModifiableDataTreeDelegator.java index c8d258b43..91de1885e 100644 --- a/v3po/data-impl/src/main/java/io/fd/honeycomb/v3po/data/impl/ModifiableDataTreeDelegator.java +++ b/v3po/data-impl/src/main/java/io/fd/honeycomb/v3po/data/impl/ModifiableDataTreeDelegator.java @@ -178,7 +178,7 @@ public final class ModifiableDataTreeDelegator extends ModifiableDataTreeManager final HashMap, DataObject> transformed = new HashMap<>(biNodes.size()); for (Map.Entry> biEntry : biNodes.entrySet()) { final Map.Entry, DataObject> baEntry = serializer.fromNormalizedNode(biEntry.getKey(), biEntry.getValue()); - if(baEntry != null) { + if (baEntry != null) { transformed.put(baEntry.getKey(), baEntry.getValue()); } } @@ -253,7 +253,7 @@ public final class ModifiableDataTreeDelegator extends ModifiableDataTreeManager } /** - * Produce a diff from a candidate node recursively + * Produce a diff from a candidate node recursively. */ @Nonnull static ModificationDiff recursivelyFromCandidate(@Nonnull final YangInstanceIdentifier yangIid, @@ -266,9 +266,9 @@ public final class ModifiableDataTreeDelegator extends ModifiableDataTreeManager return ModificationDiff.EMPTY_DIFF; } case WRITE: { - return currentCandidate.getDataBefore().isPresent() ? - ModificationDiff.create(yangIid, currentCandidate) : - ModificationDiff.createFromAfter(yangIid, currentCandidate); + return currentCandidate.getDataBefore().isPresent() + ? ModificationDiff.create(yangIid, currentCandidate) + : ModificationDiff.createFromAfter(yangIid, currentCandidate); // TODO HONEYCOMB-94 process children recursively to get modifications for child nodes } case DELETE: @@ -282,10 +282,9 @@ public final class ModifiableDataTreeDelegator extends ModifiableDataTreeManager // and that messes up our modifications collection here, so we need to skip .filter(ModificationDiff::isModification) .map(child -> LEAF_MODIFICATIONS.contains(child.getModificationType())) - .reduce((aBoolean, aBoolean2) -> aBoolean || aBoolean2); + .reduce((boolOne, boolTwo) -> boolOne || boolTwo); - // - if(leavesModified.isPresent() && leavesModified.get()) { + if (leavesModified.isPresent() && leavesModified.get()) { return ModificationDiff.create(yangIid, currentCandidate); // TODO HONEYCOMB-94 process children recursively to get modifications for child nodes even if current // was modified @@ -309,33 +308,34 @@ public final class ModifiableDataTreeDelegator extends ModifiableDataTreeManager * Check whether candidate.before and candidate.after is different. If not * return false. */ - private static boolean isModification(final DataTreeCandidateNode a) { - if(a.getDataBefore().isPresent()) { - if(a.getDataAfter().isPresent()) { - return !a.getDataAfter().get().equals(a.getDataBefore().get()); + private static boolean isModification(final DataTreeCandidateNode candidateNode) { + if (candidateNode.getDataBefore().isPresent()) { + if (candidateNode.getDataAfter().isPresent()) { + return !candidateNode.getDataAfter().get().equals(candidateNode.getDataBefore().get()); } else { return true; } } - return true; + // considering not a modification if data after is also null + return candidateNode.getDataAfter().isPresent(); } /** - * Check whether candidate node is for a leaf type node + * Check whether candidate node is for a leaf type node. */ - private static boolean isLeaf(final DataTreeCandidateNode a) { - return a.getDataAfter().isPresent() - ? (a.getDataAfter().get() instanceof LeafNode) - : (a.getDataBefore().get() instanceof LeafNode); + private static boolean isLeaf(final DataTreeCandidateNode candidateNode) { + // orNull intentional, some candidate nodes have both data after and data before null + return candidateNode.getDataAfter().orNull() instanceof LeafNode + || candidateNode.getDataBefore().orNull() instanceof LeafNode; } @Override public String toString() { - return "ModificationDiff{" + - "modificationsBefore=" + modificationsBefore + - ", modificationsAfter=" + modificationsAfter + - '}'; + return "ModificationDiff{" + + "modificationsBefore=" + modificationsBefore + + ", modificationsAfter=" + modificationsAfter + + '}'; } } } -- cgit 1.2.3-korg