Populate data/ hierarchy
[yangtools.git] / model / yang-model-ri / src / main / java / org / opendaylight / yangtools / yang / model / ri / type / LeafrefTypeBuilder.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 import static java.util.Objects.requireNonNull;
12
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.model.api.PathExpression;
16 import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
17
18 public final class LeafrefTypeBuilder extends RequireInstanceRestrictedTypeBuilder<LeafrefTypeDefinition> {
19     private PathExpression pathStatement;
20
21     LeafrefTypeBuilder(final QName qname) {
22         super(null, qname);
23     }
24
25     public LeafrefTypeBuilder setPathStatement(final @NonNull PathExpression pathStatement) {
26         checkState(this.pathStatement == null, "Path statement already set to %s", this.pathStatement);
27         this.pathStatement = requireNonNull(pathStatement);
28         return this;
29     }
30
31     @Override
32     LeafrefTypeDefinition buildType() {
33         return new BaseLeafrefType(getQName(), pathStatement, getRequireInstance(), getUnknownSchemaNodes());
34     }
35 }