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%2FInMemoryDataTreeCandidate.java;h=af87f9323acdac66388ff95cc6487e2f78063c04;hb=5b42439232c32255dfe0a27a18a90d4b54615522;hp=1f6b0f01c263d4c4bced319a823750d5164daed8;hpb=ece16db3db0f3599ee0ab92899ac42316414e032;p=yangtools.git diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/InMemoryDataTreeCandidate.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/InMemoryDataTreeCandidate.java index 1f6b0f01c2..af87f9323a 100644 --- a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/InMemoryDataTreeCandidate.java +++ b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/InMemoryDataTreeCandidate.java @@ -1,102 +1,28 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ package org.opendaylight.yangtools.yang.data.impl.schema.tree; - -import com.google.common.base.Function; -import com.google.common.base.Optional; -import com.google.common.base.Preconditions; -import com.google.common.collect.Iterables; -import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; -import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument; -import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; +import com.google.common.base.MoreObjects; +import javax.annotation.Nonnull; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode; -import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType; import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode; final class InMemoryDataTreeCandidate extends AbstractDataTreeCandidate { - private static abstract class AbstractNode implements DataTreeCandidateNode { - private final ModifiedNode mod; - private final TreeNode newMeta; - private final TreeNode oldMeta; - - protected AbstractNode(final ModifiedNode mod, - final TreeNode oldMeta, final TreeNode newMeta) { - this.newMeta = newMeta; - this.oldMeta = oldMeta; - this.mod = Preconditions.checkNotNull(mod); - } - - protected final ModifiedNode getMod() { - return mod; - } - - protected final TreeNode getNewMeta() { - return newMeta; - } - - protected final TreeNode getOldMeta() { - return oldMeta; - } - - private static final TreeNode childMeta(final TreeNode parent, final PathArgument id) { - if (parent != null) { - return parent.getChild(id).orNull(); - } else { - return null; - } - } - - @Override - public Iterable getChildNodes() { - return Iterables.transform(mod.getChildren(), new Function() { - @Override - public DataTreeCandidateNode apply(final ModifiedNode input) { - final PathArgument id = input.getIdentifier(); - return new ChildNode(input, childMeta(oldMeta, id), childMeta(newMeta, id)); - } - }); - } - - @Override - public ModificationType getModificationType() { - return mod.getType(); - } - - private Optional> optionalData(final TreeNode meta) { - if (meta != null) { - return Optional.>of(meta.getData()); - } else { - return Optional.absent(); - } - } - @Override - public Optional> getDataAfter() { - return optionalData(newMeta); - } - - @Override - public Optional> getDataBefore() { - return optionalData(oldMeta); - } - } - - private static final class ChildNode extends AbstractNode { - public ChildNode(final ModifiedNode mod, final TreeNode oldMeta, final TreeNode newMeta) { - super(mod, oldMeta, newMeta); - } - - @Override - public PathArgument getIdentifier() { - return getMod().getIdentifier(); - } - } - - private static final class RootNode extends AbstractNode { - public RootNode(final ModifiedNode mod, final TreeNode oldMeta, final TreeNode newMeta) { + private static final class RootNode extends AbstractModifiedNodeBasedCandidateNode { + RootNode(final ModifiedNode mod, final TreeNode oldMeta, final TreeNode newMeta) { super(mod, oldMeta, newMeta); } @Override + @Nonnull public PathArgument getIdentifier() { throw new IllegalStateException("Attempted to get identifier of the root node"); } @@ -104,13 +30,15 @@ final class InMemoryDataTreeCandidate extends AbstractDataTreeCandidate { private final RootNode root; - InMemoryDataTreeCandidate(final InstanceIdentifier rootPath, final ModifiedNode modificationRoot, + InMemoryDataTreeCandidate(final YangInstanceIdentifier rootPath, final ModifiedNode modificationRoot, final TreeNode beforeRoot, final TreeNode afterRoot) { super(rootPath); this.root = new RootNode(modificationRoot, beforeRoot, afterRoot); } - TreeNode getAfterRoot() { + @Override + @Nonnull + protected TreeNode getTipRoot() { return root.getNewMeta(); } @@ -122,4 +50,10 @@ final class InMemoryDataTreeCandidate extends AbstractDataTreeCandidate { public DataTreeCandidateNode getRootNode() { return root; } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this).add("rootPath", getRootPath()) + .add("rootNode", getRootNode()).toString(); + } }