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 com.google.common.base.Preconditions;
12 import java.util.HashMap;
13 import java.util.Iterator;
15 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
16 import org.opendaylight.yangtools.concepts.Builder;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
20 class ShardDataModificationFactoryBuilder extends ModificationContextNodeBuilder
21 implements Builder<ShardDataModificationFactory> {
23 private final Map<DOMDataTreeIdentifier, ForeignShardModificationContext> childShards = new HashMap<>();
24 private final DOMDataTreeIdentifier root;
26 ShardDataModificationFactoryBuilder(final DOMDataTreeIdentifier root) {
27 this.root = Preconditions.checkNotNull(root);
30 void addSubshard(final ForeignShardModificationContext value) {
31 WriteableSubshardBoundaryNode leafNode = WriteableSubshardBoundaryNode.from(value);
32 putNode(value.getIdentifier().getRootIdentifier(), leafNode);
35 void addSubshard(final DOMDataTreeIdentifier prefix, final ForeignShardModificationContext value) {
36 childShards.put(prefix, value);
39 private void putNode(final YangInstanceIdentifier key, final WriteableSubshardBoundaryNode subshardNode) {
40 final Iterator<PathArgument> toBoundary = toRelative(key).getPathArguments().iterator();
41 if (toBoundary.hasNext()) {
42 ModificationContextNodeBuilder current = this;
44 final PathArgument nextArg = toBoundary.next();
45 if (!toBoundary.hasNext()) {
46 current.addBoundary(nextArg, subshardNode);
50 current = getInterior(nextArg);
56 public ShardDataModificationFactory build() {
57 return new ShardDataModificationFactory(root, buildChildren(), childShards);
60 private YangInstanceIdentifier toRelative(final YangInstanceIdentifier key) {
61 return key.relativeTo(root.getRootIdentifier()).get();