BUG-1472: deprecated CompositeNode and friends
[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 static com.google.common.base.Preconditions.checkNotNull;
11
12 import com.google.common.collect.Iterables;
13
14 import java.util.ArrayList;
15 import java.util.List;
16 import java.util.Map;
17
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
20 import org.opendaylight.yangtools.yang.data.api.Node;
21 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeContainerBuilder;
22
23 /**
24  * @deprecated Use one of the {@link NormalizedNodeContainerBuilder} implementations.
25  */
26 @Deprecated
27 public abstract class AbstractCompositeNodeBuilder<P extends CompositeNode> extends AbstractNodeBuilder<P, CompositeNodeBuilder<P>> implements CompositeNodeBuilder<P> {
28
29     final List<Node<?>> childNodes;
30
31     public AbstractCompositeNodeBuilder() {
32         super();
33         childNodes = new ArrayList<>();
34     }
35
36     public AbstractCompositeNodeBuilder(final QName nodeType, final Map<QName, String> attributes) {
37         super(nodeType, attributes);
38         childNodes = new ArrayList<>();
39     }
40
41     public AbstractCompositeNodeBuilder(final QName nodeType, final Iterable<? extends Node<?>> nodes) {
42         super(nodeType);
43         childNodes = new ArrayList<>();
44     }
45
46     @Override
47     public AbstractCompositeNodeBuilder<P> add(final Node<?> node) {
48         childNodes.add(checkNotNull(node, "Node should not be null"));
49         return this;
50     }
51
52     @Override
53     public AbstractCompositeNodeBuilder<P> addAll(final Iterable<? extends Node<?>> nodes) {
54         Iterables.addAll(childNodes, checkNotNull(nodes, "Node should not be null"));
55         return this;
56     }
57
58     @Override
59     public CompositeNodeBuilder<P> addLeaf(final String leafLocalName, final String leafValue) {
60         return addLeaf(QName.create(getQName(), leafLocalName), leafValue);
61     }
62
63     public List<Node<?>> getChildNodes() {
64         return childNodes;
65     }
66 }