2 * Copyright (c) 2013 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
8 package org.opendaylight.yangtools.yang.data.impl.util;
10 import java.util.ArrayList;
11 import java.util.List;
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;
18 import com.google.common.collect.Iterables;
20 import static com.google.common.base.Preconditions.*;
22 public abstract class AbstractCompositeNodeBuilder<P extends CompositeNode> //
23 extends AbstractNodeBuilder<P, CompositeNodeBuilder<P>> //
24 implements CompositeNodeBuilder<P> {
26 final List<Node<?>> childNodes;
28 public AbstractCompositeNodeBuilder() {
30 childNodes = new ArrayList<>();
33 public AbstractCompositeNodeBuilder(QName nodeType, Map<QName, String> attributes) {
34 super(nodeType, attributes);
35 childNodes = new ArrayList<>();
38 public AbstractCompositeNodeBuilder(QName nodeType, Iterable<? extends Node<?>> nodes) {
40 childNodes = new ArrayList<>();
44 public AbstractCompositeNodeBuilder<P> add(Node<?> node) {
45 childNodes.add(checkNotNull(node, "Node should not be null"));
50 public AbstractCompositeNodeBuilder<P> addAll(Iterable<? extends Node<?>> nodes) {
51 Iterables.addAll(childNodes, checkNotNull(nodes, "Node should not be null"));
56 public CompositeNodeBuilder<P> addLeaf(String leafLocalName, String leafValue) {
57 return addLeaf(QName.create(getQName(), leafLocalName), leafValue);
60 public List<Node<?>> getChildNodes() {