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;
13 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
15 abstract class ModificationContextNodeBuilder<T extends WriteableModificationNode> {
17 private final Map<PathArgument, InteriorNodeBuilder> interiorChildren = new HashMap<>();
18 private final Map<PathArgument, WriteableSubshardBoundaryNode> boundaryChildren = new HashMap<>();
20 protected InteriorNodeBuilder getInterior(final PathArgument arg) {
21 InteriorNodeBuilder potential = interiorChildren.get(arg);
22 if (potential == null) {
23 potential = new InteriorNodeBuilder(arg);
24 interiorChildren.put(arg, potential);
29 protected void addBoundary(final PathArgument arg, final WriteableSubshardBoundaryNode subshardNode) {
30 boundaryChildren.put(arg, subshardNode);
34 final Map<PathArgument, WriteableModificationNode> builtChildren = new HashMap<>(boundaryChildren);
35 for (InteriorNodeBuilder interiorNode : interiorChildren.values()) {
36 WriteableModificationNode builded = interiorNode.build();
37 builtChildren.put(builded.getIdentifier(), builded);
40 return build(builtChildren);
43 abstract T build(Map<PathArgument, WriteableModificationNode> children);
45 private static class InteriorNodeBuilder extends ModificationContextNodeBuilder<WritableInteriorNode> {
47 private final PathArgument arg;
49 InteriorNodeBuilder(final PathArgument arg) {
54 WritableInteriorNode build(final Map<PathArgument, WriteableModificationNode> children) {
55 return new WritableInteriorNode(arg, children);