Introduce model.util.type package
[yangtools.git] / yang / yang-model-util / src / main / java / org / opendaylight / yangtools / yang / model / util / 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.util.type;
9
10 import com.google.common.base.Preconditions;
11 import javax.annotation.Nonnull;
12 import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
13 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
14 import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
15
16 public final class IdentityrefTypeBuilder extends TypeBuilder<IdentityrefTypeDefinition> {
17     private IdentitySchemaNode identity;
18
19     IdentityrefTypeBuilder(final SchemaPath path) {
20         super(null, path);
21     }
22
23     public void setIdentity(@Nonnull final IdentitySchemaNode identity) {
24         Preconditions.checkState(identity == null, "Identity already set to %s", identity);
25         this.identity = Preconditions.checkNotNull(identity);
26     }
27
28     @Override
29     public BaseIdentityrefType build() {
30         return new BaseIdentityrefType(getPath(), getUnknownSchemaNodes(), identity);
31     }
32 }