*/
package org.opendaylight.yangtools.yang.data.impl.schema.nodes;
+import java.util.Collection;
import java.util.Map;
-
-import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
+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, N extends DataContainerNode<K>>
+ extends AbstractImmutableNormalizedNode<K, N> implements DataContainerNode<K> {
+ private final Map<PathArgument, Object> children;
+
+ protected AbstractImmutableDataContainerNode(final Map<PathArgument, Object> children, final K nodeIdentifier) {
+ super(nodeIdentifier);
+ this.children = ImmutableOffsetMap.unorderedCopyOf(children);
+ }
+
+ @Override
+ public final DataContainerChild childByArg(final PathArgument child) {
+ return LazyLeafOperations.getChild(children, child);
+ }
-public abstract class AbstractImmutableDataContainerNode<K extends InstanceIdentifier.PathArgument>
- extends AbstractImmutableNormalizedNode<K, Iterable<DataContainerChild<? extends InstanceIdentifier.PathArgument, ?>>>
- implements DataContainerNode<K> {
+ @Override
+ public final Collection<DataContainerChild> body() {
+ return new LazyValues(children);
+ }
- protected Map<InstanceIdentifier.PathArgument, DataContainerChild<? extends InstanceIdentifier.PathArgument, ?>> children;
+ @Override
+ public final int size() {
+ return children.size();
+ }
- public AbstractImmutableDataContainerNode(Map<InstanceIdentifier.PathArgument, DataContainerChild<? extends InstanceIdentifier.PathArgument, ?>> children, K nodeIdentifier) {
- super(nodeIdentifier, children.values());
- this.children = children;
+ /**
+ * 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, nor is its contents well-defined.
+ *
+ * @return An unmodifiable view if this node's children.
+ */
+ public final Map<PathArgument, Object> getChildren() {
+ return children;
}
@Override
- public Optional<DataContainerChild<? extends InstanceIdentifier.PathArgument, ?>> getChild(InstanceIdentifier.PathArgument child) {
- return Optional.<DataContainerChild<? extends InstanceIdentifier.PathArgument, ?>>fromNullable(children.get(child));
+ protected int valueHashCode() {
+ return children.hashCode();
}
@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();
+ protected boolean valueEquals(final N other) {
+ return other instanceof AbstractImmutableDataContainerNode<?, ?> && children.equals(
+ ((AbstractImmutableDataContainerNode<?, ?>) other).children);
}
}