Populate data/ hierarchy
[yangtools.git] / model / yang-model-ri / src / main / java / org / opendaylight / yangtools / yang / model / ri / type / UnionTypeBuilder.java
1 /*
2  * Copyright (c) 2015 Pantheon Technologies s.r.o. 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.model.ri.type;
9
10 import com.google.common.collect.ImmutableList;
11 import com.google.common.collect.ImmutableList.Builder;
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.opendaylight.yangtools.yang.common.QName;
14 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
15 import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
16
17 public final class UnionTypeBuilder extends TypeBuilder<UnionTypeDefinition> {
18     private final Builder<TypeDefinition<?>> builder = ImmutableList.builder();
19
20     UnionTypeBuilder(final QName qname) {
21         super(null, qname);
22     }
23
24     public UnionTypeBuilder addType(final @NonNull TypeDefinition<?> type) {
25         builder.add(type);
26         return this;
27     }
28
29     @Override
30     public UnionTypeDefinition build() {
31         return new BaseUnionType(getQName(), getUnknownSchemaNodes(), builder.build());
32     }
33 }