Allow base type builders to be used fluently
[yangtools.git] / yang / yang-model-util / src / main / java / org / opendaylight / yangtools / yang / model / util / 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.util.type;
9
10 import com.google.common.base.Preconditions;
11 import javax.annotation.Nonnull;
12 import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
13 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
14 import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
15
16 public final class LeafrefTypeBuilder extends TypeBuilder<LeafrefTypeDefinition> {
17     private RevisionAwareXPath pathStatement;
18
19     LeafrefTypeBuilder(final SchemaPath path) {
20         super(null, path);
21     }
22
23     public LeafrefTypeBuilder setPathStatement(@Nonnull final RevisionAwareXPath pathStatement) {
24         Preconditions.checkState(this.pathStatement == null, "Path statement already set to %s", this.pathStatement);
25         this.pathStatement = Preconditions.checkNotNull(pathStatement);
26         return this;
27     }
28
29     @Override
30     public LeafrefTypeDefinition build() {
31         return new BaseLeafrefType(getPath(), pathStatement, getUnknownSchemaNodes());
32     }
33 }