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 java.util.Map.Entry;
14 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
16 abstract class ModificationContextNodeBuilder<T extends WriteableModificationNode> {
18 private final Map<PathArgument, InteriorNodeBuilder> interiorChildren = new HashMap<>();
19 private final Map<PathArgument, WriteableSubshardBoundaryNode> boundaryChildren = new HashMap<>();
21 protected InteriorNodeBuilder getInterior(final PathArgument arg) {
22 InteriorNodeBuilder potential = interiorChildren.get(arg);
23 if (potential == null) {
24 potential = new InteriorNodeBuilder(arg);
25 interiorChildren.put(arg, potential);
30 protected void addBoundary(final PathArgument arg, final WriteableSubshardBoundaryNode subshardNode) {
31 boundaryChildren.put(arg, subshardNode);
35 HashMap<PathArgument, WriteableModificationNode> builtChildren =
36 new HashMap<PathArgument, WriteableModificationNode>(boundaryChildren);
37 for (Entry<PathArgument, InteriorNodeBuilder> interiorNode : interiorChildren.entrySet()) {
38 WriteableModificationNode builded = interiorNode.getValue().build();
39 builtChildren.put(builded.getIdentifier(), builded);
42 return build(builtChildren);
45 abstract T build(Map<PathArgument, WriteableModificationNode> children);
47 private static class InteriorNodeBuilder extends ModificationContextNodeBuilder<WritableInteriorNode> {
49 private final PathArgument arg;
51 InteriorNodeBuilder(final PathArgument arg) {
56 WritableInteriorNode build(final Map<PathArgument, WriteableModificationNode> children) {
57 return new WritableInteriorNode(arg, children);