9d75aacc9f51383a5973214c2b10138ef5fda95d
[yangtools.git] / model / yang-model-ri / src / main / java / org / opendaylight / yangtools / yang / model / ri / type / IdentityrefTypeBuilder.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 static com.google.common.base.Preconditions.checkState;
11
12 import com.google.common.collect.ImmutableSet;
13 import com.google.common.collect.ImmutableSet.Builder;
14 import java.util.Set;
15 import org.eclipse.jdt.annotation.NonNull;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
19
20 public final class IdentityrefTypeBuilder extends TypeBuilder<IdentityrefTypeDefinition> {
21     private final Builder<IdentitySchemaNode> builder = ImmutableSet.builder();
22
23     IdentityrefTypeBuilder(final QName qname) {
24         super(null, qname);
25     }
26
27     public IdentityrefTypeBuilder addIdentity(final @NonNull IdentitySchemaNode identity) {
28         builder.add(identity);
29         return this;
30     }
31
32     @Override
33     public IdentityrefTypeDefinition build() {
34         final Set<IdentitySchemaNode> identities = builder.build();
35         checkState(!identities.isEmpty(), "No identities specified in %s, at least one is required", getQName());
36         return new BaseIdentityrefType(getQName(), getUnknownSchemaNodes(), identities);
37     }
38 }