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 com.google.common.annotations.Beta;
11 import org.eclipse.jdt.annotation.NonNull;
12 import org.opendaylight.yangtools.yang.common.QName;
13 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
14 import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition;
15 import org.opendaylight.yangtools.yang.model.api.type.BooleanTypeDefinition;
16 import org.opendaylight.yangtools.yang.model.api.type.EmptyTypeDefinition;
17 import org.opendaylight.yangtools.yang.model.api.type.InstanceIdentifierTypeDefinition;
18 import org.opendaylight.yangtools.yang.model.api.type.Int16TypeDefinition;
19 import org.opendaylight.yangtools.yang.model.api.type.Int32TypeDefinition;
20 import org.opendaylight.yangtools.yang.model.api.type.Int64TypeDefinition;
21 import org.opendaylight.yangtools.yang.model.api.type.Int8TypeDefinition;
22 import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
23 import org.opendaylight.yangtools.yang.model.api.type.Uint16TypeDefinition;
24 import org.opendaylight.yangtools.yang.model.api.type.Uint32TypeDefinition;
25 import org.opendaylight.yangtools.yang.model.api.type.Uint64TypeDefinition;
26 import org.opendaylight.yangtools.yang.model.api.type.Uint8TypeDefinition;
29 * Utility access methods for creating and accessing YANG base type definitions. YANG types come in two basic variants,
30 * depending on whether they fully define their base instance or model input is required to fully-form the type.
33 * The following types have their base type fully specified and are exposed as appropriate TypeDefinition
39 * <li>int{8,16,32,64}</li>
41 * <li>uint{8,16,32,64}</li>
45 * The following types require additional specification in the model and are exposed by means of a specialized
46 * {@link TypeBuilder}s for each type:
49 * <li>instance-identifier</li>
50 * <li>enumeration</li>
51 * <li>identityref</li>
57 public final class BaseTypes {
62 public static @NonNull BinaryTypeDefinition binaryType() {
63 return BaseBinaryType.INSTANCE;
66 public static @NonNull BitsTypeBuilder bitsTypeBuilder(final QName qname) {
67 return new BitsTypeBuilder(qname);
70 public static @NonNull BooleanTypeDefinition booleanType() {
71 return BaseBooleanType.INSTANCE;
74 public static @NonNull DecimalTypeBuilder decimalTypeBuilder(final QName qname) {
75 return new DecimalTypeBuilder(qname);
78 public static @NonNull EmptyTypeDefinition emptyType() {
79 return BaseEmptyType.INSTANCE;
82 public static @NonNull EnumerationTypeBuilder enumerationTypeBuilder(final QName qname) {
83 return new EnumerationTypeBuilder(qname);
86 public static @NonNull IdentityrefTypeBuilder identityrefTypeBuilder(final QName qname) {
87 return new IdentityrefTypeBuilder(qname);
90 public static @NonNull InstanceIdentifierTypeDefinition instanceIdentifierType() {
91 return BaseInstanceIdentifierType.INSTANCE;
94 public static @NonNull Int8TypeDefinition int8Type() {
95 return BaseInt8Type.INSTANCE;
98 public static @NonNull Int16TypeDefinition int16Type() {
99 return BaseInt16Type.INSTANCE;
102 public static @NonNull Int32TypeDefinition int32Type() {
103 return BaseInt32Type.INSTANCE;
106 public static @NonNull Int64TypeDefinition int64Type() {
107 return BaseInt64Type.INSTANCE;
110 public static @NonNull LeafrefTypeBuilder leafrefTypeBuilder(final QName qname) {
111 return new LeafrefTypeBuilder(qname);
114 public static @NonNull StringTypeDefinition stringType() {
115 return BaseStringType.INSTANCE;
118 public static UnionTypeBuilder unionTypeBuilder(final QName qname) {
119 return new UnionTypeBuilder(qname);
122 public static @NonNull Uint8TypeDefinition uint8Type() {
123 return BaseUint8Type.INSTANCE;
126 public static @NonNull Uint16TypeDefinition uint16Type() {
127 return BaseUint16Type.INSTANCE;
130 public static @NonNull Uint32TypeDefinition uint32Type() {
131 return BaseUint32Type.INSTANCE;
134 public static @NonNull Uint64TypeDefinition uint64Type() {
135 return BaseUint64Type.INSTANCE;
139 * Return the base type of a particular type. This method performs recursive lookup through the type's base type
140 * until it finds the last element and returns it. If the argument is already the base type, it is returned as is.
142 * @param type Type for which to find the base type
143 * @return Base type of specified type
144 * @throws NullPointerException if type is null
146 public static @NonNull TypeDefinition<?> baseTypeOf(final @NonNull TypeDefinition<?> type) {
147 TypeDefinition<?> ret = type;
148 while (ret.getBaseType() != null) {
149 ret = ret.getBaseType();