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
8 package org.opendaylight.mdsal.dom.spi.shard;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.annotations.Beta;
13 import java.util.HashMap;
14 import java.util.Iterator;
16 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
17 import org.opendaylight.yangtools.concepts.Builder;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
22 @Deprecated(forRemoval = true)
23 public abstract class AbstractShardModificationFactoryBuilder<T> extends ModificationContextNodeBuilder
24 implements Builder<T> {
25 protected final Map<DOMDataTreeIdentifier, ForeignShardModificationContext> childShards = new HashMap<>();
26 protected final DOMDataTreeIdentifier root;
28 public AbstractShardModificationFactoryBuilder(final DOMDataTreeIdentifier root) {
29 this.root = requireNonNull(root);
32 public void addSubshard(final ForeignShardModificationContext value) {
33 WriteableSubshardBoundaryNode leafNode = WriteableSubshardBoundaryNode.from(value);
34 putNode(value.getIdentifier().getRootIdentifier(), leafNode);
37 public void addSubshard(final DOMDataTreeIdentifier prefix, final ForeignShardModificationContext value) {
38 childShards.put(prefix, value);
42 public abstract T build();
44 private void putNode(final YangInstanceIdentifier key, final WriteableSubshardBoundaryNode subshardNode) {
45 final Iterator<PathArgument> toBoundary = toRelative(key).getPathArguments().iterator();
46 if (toBoundary.hasNext()) {
47 ModificationContextNodeBuilder current = this;
49 final PathArgument nextArg = toBoundary.next();
50 if (!toBoundary.hasNext()) {
51 current.addBoundary(nextArg, subshardNode);
55 current = current.getInterior(nextArg);
60 private YangInstanceIdentifier toRelative(final YangInstanceIdentifier key) {
61 return key.relativeTo(root.getRootIdentifier()).get();