Introduce model.util.type package
[yangtools.git] / yang / yang-model-util / src / main / java / org / opendaylight / yangtools / yang / model / util / type / AbstractRestrictedTypeBuilder.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 org.opendaylight.yangtools.yang.model.api.SchemaPath;
12 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
13
14 abstract class AbstractRestrictedTypeBuilder<T extends TypeDefinition<T>> extends TypeBuilder<T> {
15     private boolean touched = false;
16
17     AbstractRestrictedTypeBuilder(final T baseType, final SchemaPath path) {
18         super(Preconditions.checkNotNull(baseType), path);
19     }
20
21     final void touch() {
22         touched = true;
23     }
24
25     abstract T buildType();
26
27     @Override
28     public final T build() {
29         if (!touched) {
30             return getBaseType();
31         }
32
33         return buildType();
34     }
35 }