6d4b988b12365e3cc8d16a7d114aab5ab75f16b9
[yangtools.git] / yang / yang-model-util / src / main / java / org / opendaylight / yangtools / yang / model / util / type / RequireInstanceRestrictedTypeBuilder.java
1 /*
2  * Copyright (c) 2017 Cisco Systems, Inc. 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
9 package org.opendaylight.yangtools.yang.model.util.type;
10
11 import com.google.common.annotations.Beta;
12 import com.google.common.base.Preconditions;
13 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
14 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
15
16 @Beta
17 public abstract class RequireInstanceRestrictedTypeBuilder<T extends TypeDefinition<T>>
18         extends AbstractRestrictedTypeBuilder<T> {
19
20     private boolean requireInstance;
21
22     RequireInstanceRestrictedTypeBuilder(final T baseType, final SchemaPath path) {
23         super(baseType, path);
24     }
25
26     public final void setRequireInstance(final boolean requireInstance) {
27         if (this.requireInstance) {
28             Preconditions.checkArgument(requireInstance, "Cannot switch off require-instance in type %s", getPath());
29         }
30
31         this.requireInstance = requireInstance;
32         touch();
33     }
34
35     final boolean getRequireInstance() {
36         return requireInstance;
37     }
38 }