Bug 1372 - toString methods in generated classes
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / util / AbstractCompositeNodeBuilder.java
1 /*
2  * Copyright (c) 2013 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.yangtools.yang.data.impl.util;
9
10 import java.util.ArrayList;
11 import java.util.List;
12 import java.util.Map;
13
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
16 import org.opendaylight.yangtools.yang.data.api.Node;
17
18 import com.google.common.collect.Iterables;
19
20 import static com.google.common.base.Preconditions.*;
21
22 public abstract class AbstractCompositeNodeBuilder<P extends CompositeNode> //
23         extends AbstractNodeBuilder<P, CompositeNodeBuilder<P>> //
24         implements CompositeNodeBuilder<P> {
25
26     final List<Node<?>> childNodes;
27
28     public AbstractCompositeNodeBuilder() {
29         super();
30         childNodes = new ArrayList<>();
31     }
32
33     public AbstractCompositeNodeBuilder(QName nodeType, Map<QName, String> attributes) {
34         super(nodeType, attributes);
35         childNodes = new ArrayList<>();
36     }
37
38     public AbstractCompositeNodeBuilder(QName nodeType, Iterable<? extends Node<?>> nodes) {
39         super(nodeType);
40         childNodes = new ArrayList<>();
41     }
42
43     @Override
44     public AbstractCompositeNodeBuilder<P> add(Node<?> node) {
45         childNodes.add(checkNotNull(node, "Node should not be null"));
46         return this;
47     }
48
49     @Override
50     public AbstractCompositeNodeBuilder<P> addAll(Iterable<? extends Node<?>> nodes) {
51         Iterables.addAll(childNodes, checkNotNull(nodes, "Node should not be null"));
52         return this;
53     }
54
55     @Override
56     public CompositeNodeBuilder<P> addLeaf(String leafLocalName, String leafValue) {
57         return addLeaf(QName.create(getQName(), leafLocalName), leafValue);
58     }
59
60     public List<Node<?>> getChildNodes() {
61         return childNodes;
62     }
63 }