Always use lazy leaf nodes
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / nodes / AbstractImmutableDataContainerNode.java
index aad07e89e2f8b227dff950234840f5ef34667462..6b5e0d7e5124eb8ee661fa9f8119a624252f7daf 100644 (file)
@@ -7,10 +7,9 @@
  */
 package org.opendaylight.yangtools.yang.data.impl.schema.nodes;
 
-import com.google.common.base.Optional;
 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;
@@ -18,11 +17,10 @@ import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
 
 public abstract class AbstractImmutableDataContainerNode<K extends PathArgument>
         extends AbstractImmutableNormalizedNode<K, Collection<DataContainerChild<? extends PathArgument, ?>>>
-        implements Immutable, DataContainerNode<K> {
-    private final Map<PathArgument, DataContainerChild<? extends PathArgument, ?>> children;
+        implements DataContainerNode<K> {
+    private final Map<PathArgument, Object> children;
 
-    public AbstractImmutableDataContainerNode(
-            final Map<PathArgument, DataContainerChild<? extends PathArgument, ?>> children, final K nodeIdentifier) {
+    protected AbstractImmutableDataContainerNode(final Map<PathArgument, Object> children, final K nodeIdentifier) {
         super(nodeIdentifier);
 
         this.children = ImmutableOffsetMap.unorderedCopyOf(children);
@@ -30,12 +28,17 @@ public abstract class AbstractImmutableDataContainerNode<K extends PathArgument>
 
     @Override
     public final Optional<DataContainerChild<? extends PathArgument, ?>> getChild(final PathArgument child) {
-        return Optional.fromNullable(children.get(child));
+        return Optional.ofNullable(LazyLeafOperations.getChild(children, child));
     }
 
     @Override
     public final Collection<DataContainerChild<? extends PathArgument, ?>> getValue() {
-        return children.values();
+        return new LazyValues(children);
+    }
+
+    @Override
+    public final int size() {
+        return children.size();
     }
 
     @Override
@@ -47,13 +50,12 @@ public abstract class AbstractImmutableDataContainerNode<K extends PathArgument>
      * DO NOT USE THIS METHOD.
      *
      * <p>
-     * 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.
+     * 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<PathArgument, DataContainerChild<? extends PathArgument, ?>> getChildren() {
+    public final Map<PathArgument, Object> getChildren() {
         return children;
     }
 
@@ -61,6 +63,5 @@ public abstract class AbstractImmutableDataContainerNode<K extends PathArgument>
     protected boolean valueEquals(final AbstractImmutableNormalizedNode<?, ?> other) {
         return other instanceof AbstractImmutableDataContainerNode<?> && children.equals(
                 ((AbstractImmutableDataContainerNode<?>) other).children);
-
     }
 }