2 * Copyright (c) 2015 Pantheon Technologies s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.model.ri.type;
10 import static com.google.common.base.Preconditions.checkArgument;
11 import static com.google.common.base.Verify.verifyNotNull;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
17 abstract class AbstractRestrictedTypeBuilder<T extends TypeDefinition<T>> extends TypeBuilder<T> {
18 private boolean touched;
20 AbstractRestrictedTypeBuilder(final T baseType, final QName qname) {
21 super(baseType, qname);
22 if (baseType != null) {
23 checkArgument(baseType instanceof AbstractBaseType || baseType instanceof AbstractDerivedType,
24 "Restricted type has to be based on either a base or derived type, not %s", baseType);
34 abstract @NonNull T buildType();
37 public final T build() {
38 return touched ? buildType() : verifyNotNull(getBaseType());