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%2Fnodes%2FAbstractImmutableDataContainerNode.java;h=dabcc5777eaeee7af57d56aefe9635ce9dfb455b;hb=6d818dcbe5187d15a46cced7893be28df1cec725;hp=01bfe32b2811d9afaf93040f6c8c112af899bdf7;hpb=68f459e972f360597301b929b5943082ba9e9730;p=yangtools.git diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/nodes/AbstractImmutableDataContainerNode.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/nodes/AbstractImmutableDataContainerNode.java index 01bfe32b28..dabcc5777e 100644 --- a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/nodes/AbstractImmutableDataContainerNode.java +++ b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/nodes/AbstractImmutableDataContainerNode.java @@ -7,60 +7,33 @@ */ package org.opendaylight.yangtools.yang.data.impl.schema.nodes; -import com.google.common.base.Optional; - -import java.util.Collections; +import java.util.Collection; import java.util.Map; - -import org.opendaylight.yangtools.concepts.Immutable; +import java.util.Optional; +import org.opendaylight.yangtools.util.ImmutableOffsetMap; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument; import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild; import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -public abstract class AbstractImmutableDataContainerNode extends AbstractImmutableNormalizedNode>> implements Immutable, DataContainerNode { - private static final Logger LOG = LoggerFactory.getLogger(AbstractImmutableDataContainerNode.class); - private final Map> children; +public abstract class AbstractImmutableDataContainerNode + extends AbstractImmutableNormalizedNode>> + implements DataContainerNode { + private final Map children; - public AbstractImmutableDataContainerNode( - final Map> children, final K nodeIdentifier) { + protected AbstractImmutableDataContainerNode(final Map children, final K nodeIdentifier) { super(nodeIdentifier); - /* - * There is a code path where AbstractImmutableDataContainerNodeBuilder can reflect - * the collection acquired via getChildren() back to us. This is typically the case - * in the datastore where transactions cancel each other out, leaving an unmodified - * node. In that case we want to skip wrapping the map again (and again and again). - * - * In a perfect world, Collection.unmodifiableMap() would be doing the instanceof - * check which would stop the proliferation. Unfortunately this not the case and the - * 'unmodifiable' trait is not exposed by anything we can query. Furthermore the API - * contract there is sufficiently vague so an implementation may actually return a - * different implementation based on input map -- for example - * Collections.unmodifiableMap(Collections.emptyMap()) returning the same thing as - * Collections.emptyMap(). - * - * This means that we have to perform the instantiation here (as opposed to once at - * class load time) and then compare the classes. - */ - final Map> pub = Collections.unmodifiableMap(children); - if (children.getClass().equals(pub.getClass())) { - LOG.trace("Reusing already-unmodifiable children {}", children); - this.children = children; - } else { - this.children = pub; - } + this.children = ImmutableOffsetMap.unorderedCopyOf(children); } @Override public final Optional> getChild(final PathArgument child) { - return Optional.> fromNullable(children.get(child)); + return LazyLeafOperations.findChild(children, child); } @Override - public final Iterable> getValue() { - return children.values(); + public final Collection> getValue() { + return LazyLeafOperations.getValue(children); } @Override @@ -68,16 +41,22 @@ public abstract class AbstractImmutableDataContainerNode return children.hashCode(); } - public final Map> getChildren() { + /** + * DO NOT USE THIS METHOD. + * + *

+ * This is an implementation-internal API and no outside users should use it. If you do, you are asking for trouble, + * as the returned object is not guaranteed to conform to java.util.Map interface, nor is its contents well-defined. + * + * @return An unmodifiable view if this node's children. + */ + public final Map getChildren() { return children; } @Override protected boolean valueEquals(final AbstractImmutableNormalizedNode other) { - if (!(other instanceof AbstractImmutableDataContainerNode)) { - return false; - } - - return children.equals(((AbstractImmutableDataContainerNode)other).children); + return other instanceof AbstractImmutableDataContainerNode && children.equals( + ((AbstractImmutableDataContainerNode) other).children); } }