Do not generate 'isFoo()' methods
[mdsal.git] / dom / mdsal-dom-spi / src / main / java / org / opendaylight / mdsal / dom / spi / shard / ModificationContextNodeBuilder.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.mdsal.dom.spi.shard;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.annotations.Beta;
13 import java.util.HashMap;
14 import java.util.LinkedHashMap;
15 import java.util.Map;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
17
18 @Beta
19 @Deprecated(forRemoval = true)
20 public abstract class ModificationContextNodeBuilder {
21
22     private final Map<PathArgument, InteriorNodeBuilder> interiorChildren = new LinkedHashMap<>();
23     private final Map<PathArgument, WriteableSubshardBoundaryNode> boundaryChildren = new HashMap<>();
24
25     public ModificationContextNodeBuilder getInterior(final PathArgument arg) {
26         InteriorNodeBuilder potential = interiorChildren.get(arg);
27         if (potential == null) {
28             potential = new InteriorNodeBuilder(arg);
29             interiorChildren.put(arg, potential);
30         }
31         return potential;
32     }
33
34     public void addBoundary(final PathArgument arg, final WriteableSubshardBoundaryNode subshardNode) {
35         boundaryChildren.put(arg, subshardNode);
36     }
37
38     public final Map<PathArgument, WriteableModificationNode> buildChildren() {
39         final Map<PathArgument, WriteableModificationNode> builtChildren = new HashMap<>(boundaryChildren);
40         for (InteriorNodeBuilder interiorNode : interiorChildren.values()) {
41             WriteableModificationNode builded = interiorNode.build();
42             builtChildren.put(builded.getIdentifier(), builded);
43         }
44
45         return builtChildren;
46     }
47
48     public static final class InteriorNodeBuilder extends ModificationContextNodeBuilder {
49         private final PathArgument arg;
50
51         InteriorNodeBuilder(final PathArgument arg) {
52             this.arg = requireNonNull(arg);
53         }
54
55         WritableInteriorNode build() {
56             return new WritableInteriorNode(arg, buildChildren());
57         }
58     }
59 }