2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.mdsal.dom.store.inmemory;
11 import java.util.HashMap;
12 import java.util.Iterator;
14 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
18 class ShardDataModificationBuilder extends ModificationContextNodeBuilder<ShardDataModification> {
20 private final ShardRootModificationContext root;
21 private final Map<DOMDataTreeIdentifier, ForeignShardModificationContext> childShards =
24 ShardDataModificationBuilder(final ShardRootModificationContext root) {
28 public void addSubshard(final ForeignShardModificationContext value) {
29 WriteableSubshardBoundaryNode leafNode = WriteableSubshardBoundaryNode.from(value);
30 putNode(value.getIdentifier().getRootIdentifier(), leafNode);
33 public void addSubshard(final DOMDataTreeIdentifier prefix, final ForeignShardModificationContext value) {
34 childShards.put(prefix, value);
37 private void putNode(final YangInstanceIdentifier key, final WriteableSubshardBoundaryNode subshardNode) {
38 ModificationContextNodeBuilder<?> current = this;
39 Iterator<PathArgument> toBoundary = toRelative(key).getPathArguments().iterator();
40 while (toBoundary.hasNext()) {
41 PathArgument nextArg = toBoundary.next();
42 if (toBoundary.hasNext()) {
43 current = getInterior(nextArg);
45 current.addBoundary(nextArg, subshardNode);
52 ShardDataModification build(final Map<PathArgument, WriteableModificationNode> children) {
53 return new ShardDataModification(root, children, childShards);
56 private YangInstanceIdentifier toRelative(final YangInstanceIdentifier key) {
57 return key.relativeTo(root.getIdentifier().getRootIdentifier()).get();