*/
package org.opendaylight.yangtools.yang.data.impl.schema.nodes;
-import java.util.Collections;
+import java.util.Collection;
import java.util.Map;
-
-import org.opendaylight.yangtools.concepts.Immutable;
-import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument;
+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 com.google.common.base.Optional;
-import com.google.common.collect.Iterables;
-
-public abstract class AbstractImmutableDataContainerNode<K extends PathArgument> //
- extends AbstractImmutableNormalizedNode<K, Iterable<DataContainerChild<? extends PathArgument, ?>>> //
- implements Immutable, DataContainerNode<K> {
+public abstract class AbstractImmutableDataContainerNode<K extends PathArgument>
+ extends AbstractImmutableNormalizedNode<K, Collection<DataContainerChild<? extends PathArgument, ?>>>
+ implements DataContainerNode<K> {
+ private final Map<PathArgument, Object> children;
- protected final Map<PathArgument, DataContainerChild<? extends PathArgument, ?>> 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 = children;
+
+ this.children = ImmutableOffsetMap.unorderedCopyOf(children);
}
@Override
public final Optional<DataContainerChild<? extends PathArgument, ?>> getChild(final PathArgument child) {
- return Optional.<DataContainerChild<? extends PathArgument, ?>> fromNullable(children.get(child));
+ return Optional.ofNullable(LazyLeafOperations.getChild(children, child));
}
@Override
- public final Iterable<DataContainerChild<? extends PathArgument, ?>> getValue() {
- return Iterables.unmodifiableIterable(children.values());
+ public final Collection<DataContainerChild<? extends PathArgument, ?>> getValue() {
+ return new LazyValues(children);
+ }
+
+ @Override
+ public final int size() {
+ return children.size();
}
@Override
return children.hashCode();
}
- public final Map<PathArgument, DataContainerChild<? extends PathArgument, ?>> getChildren() {
- // Make sure we do not leak a mutable view
- return Collections.unmodifiableMap(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
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);
}
}