BUG-4803: introduce unordered offset maps
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / nodes / AbstractImmutableDataContainerNode.java
index f914484831b120066529ed6696c8a58e5f099081..ea6e954da79685bb471d5bde4ae39750d08ffe1f 100644 (file)
@@ -7,25 +7,25 @@
  */
 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 org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument;
+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 com.google.common.base.Optional;
-
-public abstract class AbstractImmutableDataContainerNode<K extends PathArgument> //
-        extends AbstractImmutableNormalizedNode<K, Iterable<DataContainerChild<? extends PathArgument, ?>>> //
+public abstract class AbstractImmutableDataContainerNode<K extends PathArgument>
+        extends AbstractImmutableNormalizedNode<K, Collection<DataContainerChild<? extends PathArgument, ?>>>
         implements Immutable, DataContainerNode<K> {
-
-    protected final Map<PathArgument, DataContainerChild<? extends PathArgument, ?>> children;
+    private final Map<PathArgument, DataContainerChild<? extends PathArgument, ?>> children;
 
     public AbstractImmutableDataContainerNode(
             final Map<PathArgument, DataContainerChild<? extends PathArgument, ?>> children, final K nodeIdentifier) {
-        super(nodeIdentifier, children.values());
-        this.children = children;
+        super(nodeIdentifier);
+
+        this.children = ImmutableOffsetMap.unorderedCopyOf(children);
     }
 
     @Override
@@ -34,11 +34,34 @@ public abstract class AbstractImmutableDataContainerNode<K extends PathArgument>
     }
 
     @Override
-    public String toString() {
-        final StringBuffer sb = new StringBuffer("ImmutableContainerNode{");
-        sb.append("nodeIdentifier=").append(nodeIdentifier);
-        sb.append(", children=").append(children);
-        sb.append('}');
-        return sb.toString();
+    public final Collection<DataContainerChild<? extends PathArgument, ?>> getValue() {
+        return children.values();
+    }
+
+    @Override
+    protected int valueHashCode() {
+        return children.hashCode();
+    }
+
+    /**
+     * 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.
+     *
+     * @return An unmodifiable view if this node's children.
+     */
+    public final Map<PathArgument, DataContainerChild<? extends PathArgument, ?>> getChildren() {
+        return children;
+    }
+
+    @Override
+    protected boolean valueEquals(final AbstractImmutableNormalizedNode<?, ?> other) {
+        if (!(other instanceof AbstractImmutableDataContainerNode<?>)) {
+            return false;
+        }
+
+        return children.equals(((AbstractImmutableDataContainerNode<?>)other).children);
     }
 }