*/
package org.opendaylight.yangtools.yang.data.impl.schema.builder.impl;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.nodes.AbstractImmutableDataContainerAttrNode;
import com.google.common.base.Preconditions;
-import com.google.common.collect.Maps;
public class ImmutableMapEntryNodeBuilder
extends AbstractImmutableDataContainerNodeAttrBuilder<InstanceIdentifier.NodeIdentifierWithPredicates, MapEntryNode> {
protected final Map<QName, InstanceIdentifier.PathArgument> childrenQNamesToPaths;
protected ImmutableMapEntryNodeBuilder() {
- this.childrenQNamesToPaths = Maps.newLinkedHashMap();
+ this.childrenQNamesToPaths = new LinkedHashMap<>();
+ }
+
+ protected ImmutableMapEntryNodeBuilder(final ImmutableMapEntryNode node) {
+ super(node);
+ this.childrenQNamesToPaths = new LinkedHashMap<>();
+ fillQnames(node.getValue(), childrenQNamesToPaths);
}
public static DataContainerNodeAttrBuilder<InstanceIdentifier.NodeIdentifierWithPredicates, MapEntryNode> create() {
return new ImmutableMapEntryNodeBuilder();
}
- // FIXME, find better solution than 2 maps (map from QName to Child ?)
+ public static DataContainerNodeAttrBuilder<InstanceIdentifier.NodeIdentifierWithPredicates, MapEntryNode> create(final MapEntryNode node) {
+ if (!(node instanceof ImmutableMapEntryNode)) {
+ throw new UnsupportedOperationException(String.format("Cannot initialize from class %s", node.getClass()));
+ }
- @Override
- public DataContainerNodeAttrBuilder<InstanceIdentifier.NodeIdentifierWithPredicates, MapEntryNode> withValue(final List<DataContainerChild<? extends InstanceIdentifier.PathArgument, ?>> value) {
- for (final DataContainerChild<? extends InstanceIdentifier.PathArgument, ?> childId : value) {
+ return new ImmutableMapEntryNodeBuilder((ImmutableMapEntryNode)node);
+ }
+
+ private static void fillQnames(final Iterable<DataContainerChild<? extends PathArgument, ?>> iterable, final Map<QName, PathArgument> out) {
+ for (final DataContainerChild<? extends InstanceIdentifier.PathArgument, ?> childId : iterable) {
final InstanceIdentifier.PathArgument identifier = childId.getIdentifier();
// Augmentation nodes cannot be keys, and do not have to be present in childrenQNamesToPaths map
continue;
}
- this.childrenQNamesToPaths.put(childId.getNodeType(), identifier);
+ out.put(childId.getNodeType(), identifier);
}
+ }
+
+ // FIXME, find better solution than 2 maps (map from QName to Child ?)
+
+ @Override
+ public DataContainerNodeAttrBuilder<InstanceIdentifier.NodeIdentifierWithPredicates, MapEntryNode> withValue(final List<DataContainerChild<? extends InstanceIdentifier.PathArgument, ?>> value) {
+ fillQnames(value, childrenQNamesToPaths);
return super.withValue(value);
}
@Override
public MapEntryNode build() {
checkKeys();
- return new ImmutableMapEntryNode(getNodeIdentifier(), buildValue(), attributes);
+ return new ImmutableMapEntryNode(getNodeIdentifier(), buildValue(), getAttributes());
}
private void checkKeys() {
}
}
- static final class ImmutableMapEntryNode extends AbstractImmutableDataContainerAttrNode<InstanceIdentifier.NodeIdentifierWithPredicates> implements MapEntryNode {
+ private static final class ImmutableMapEntryNode extends AbstractImmutableDataContainerAttrNode<InstanceIdentifier.NodeIdentifierWithPredicates> implements MapEntryNode {
ImmutableMapEntryNode(final InstanceIdentifier.NodeIdentifierWithPredicates nodeIdentifier,
final Map<InstanceIdentifier.PathArgument, DataContainerChild<? extends InstanceIdentifier.PathArgument, ?>> children, final Map<QName, String> attributes) {