abstract class AbstractModifiedNodeBasedCandidateNode implements DataTreeCandidateNode {
- private static final Function<NormalizedNode<?, ?>, DataTreeCandidateNode> TO_UNMODIFIED_NODES = new Function<NormalizedNode<?, ?>, DataTreeCandidateNode>() {
+ private static final Function<NormalizedNode<?, ?>, DataTreeCandidateNode> TO_UNMODIFIED_NODE = new Function<NormalizedNode<?, ?>, DataTreeCandidateNode>() {
@Override
public DataTreeCandidateNode apply(final NormalizedNode<?, ?> input) {
return AbstractRecursiveCandidateNode.unmodifiedNode(input);
return oldMeta;
}
- private static final TreeNode childMeta(final TreeNode parent, final PathArgument id) {
+ private static TreeNode childMeta(final TreeNode parent, final PathArgument id) {
if (parent != null) {
return parent.getChild(id).orNull();
} else {
@Override
public Collection<DataTreeCandidateNode> getChildNodes() {
switch (mod.getModificationType()) {
+ case APPEARED:
+ case DISAPPEARED:
case SUBTREE_MODIFIED:
return Collections2.transform(mod.getChildren(), new Function<ModifiedNode, DataTreeCandidateNode>() {
@Override
// 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();
}
}
@Override
- public Optional<NormalizedNode<?, ?>> getDataAfter() {
+ public final Optional<NormalizedNode<?, ?>> getDataAfter() {
return optionalData(newMeta);
}
@Override
- public Optional<NormalizedNode<?, ?>> getDataBefore() {
+ public final Optional<NormalizedNode<?, ?>> getDataBefore() {
return optionalData(oldMeta);
}
@Override
- public DataTreeCandidateNode getModifiedChild(final PathArgument identifier) {
+ public final DataTreeCandidateNode getModifiedChild(final PathArgument identifier) {
switch (mod.getModificationType()) {
+ case APPEARED:
+ case DISAPPEARED:
case SUBTREE_MODIFIED:
final Optional<ModifiedNode> 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<NormalizedNode<?, ?>> 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());
}
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 + "}";
+ }
+}