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.util.type;
10 import com.google.common.annotations.Beta;
11 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
12 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
13 import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition;
14 import org.opendaylight.yangtools.yang.model.api.type.BooleanTypeDefinition;
15 import org.opendaylight.yangtools.yang.model.api.type.EmptyTypeDefinition;
16 import org.opendaylight.yangtools.yang.model.api.type.InstanceIdentifierTypeDefinition;
17 import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition;
18 import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
19 import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinition;
22 * Utility access methods for creating and accessing YANG base type definitions. YANG types come in two basic variants,
23 * depending on whether they fully define their base instance or model input is required to fully-form the type.
25 * The following types have their base type fully specified and are exposed as appropriate TypeDefinition sub-interfaces:
30 * <li>int{8,16,32,64}</li>
32 * <li>uint{8,16,32,64}</li>
35 * The following types require additional specification in the model and are exposed by means of a specialized
36 * {@link TypeBuilder}s for each type:
39 * <li>instance-identifier</li>
40 * <li>enumeration</li>
41 * <li>identityref</li>
47 public final class BaseTypes {
49 throw new UnsupportedOperationException();
52 public static BinaryTypeDefinition binaryType() {
53 return BaseBinaryType.INSTANCE;
56 public static BitsTypeBuilder bitsTypeBuilder(final SchemaPath path) {
57 return new BitsTypeBuilder(path);
60 public static BooleanTypeDefinition booleanType() {
61 return BaseBooleanType.INSTANCE;
64 public static DecimalTypeBuilder decimalTypeBuilder(final SchemaPath path) {
65 return new DecimalTypeBuilder(path);
68 public static EmptyTypeDefinition emptyType() {
69 return BaseEmptyType.INSTANCE;
72 public static EnumerationTypeBuilder enumerationTypeBuilder(final SchemaPath path) {
73 return new EnumerationTypeBuilder(path);
76 public static IdentityrefTypeBuilder identityrefTypeBuilder(final SchemaPath path) {
77 return new IdentityrefTypeBuilder(path);
80 public static InstanceIdentifierTypeDefinition instanceIdentifierType() {
81 return BaseInstanceIdentifierType.INSTANCE;
84 public static IntegerTypeDefinition int8Type() {
85 return BaseInt8Type.INSTANCE;
88 public static boolean isInt8(final TypeDefinition<?> type) {
89 return BaseInt8Type.INSTANCE.getPath().equals(findBaseTypePath(type));
92 public static IntegerTypeDefinition int16Type() {
93 return BaseInt16Type.INSTANCE;
96 public static boolean isInt16(final TypeDefinition<?> type) {
97 return BaseInt16Type.INSTANCE.getPath().equals(findBaseTypePath(type));
100 public static IntegerTypeDefinition int32Type() {
101 return BaseInt32Type.INSTANCE;
104 public static boolean isInt32(final TypeDefinition<?> type) {
105 return BaseInt32Type.INSTANCE.getPath().equals(findBaseTypePath(type));
108 public static IntegerTypeDefinition int64Type() {
109 return BaseInt64Type.INSTANCE;
112 public static boolean isInt64(final TypeDefinition<?> type) {
113 return BaseInt64Type.INSTANCE.getPath().equals(findBaseTypePath(type));
116 public static LeafrefTypeBuilder leafrefTypeBuilder(final SchemaPath path) {
117 return new LeafrefTypeBuilder(path);
120 public static StringTypeDefinition stringType() {
121 return BaseStringType.INSTANCE;
124 public static UnionTypeBuilder unionTypeBuilder(final SchemaPath path) {
125 return new UnionTypeBuilder(path);
128 public static UnsignedIntegerTypeDefinition uint8Type() {
129 return BaseUint8Type.INSTANCE;
132 public static boolean isUint8(final TypeDefinition<?> type) {
133 return BaseUint8Type.INSTANCE.getPath().equals(findBaseTypePath(type));
136 public static UnsignedIntegerTypeDefinition uint16Type() {
137 return BaseUint16Type.INSTANCE;
140 public static boolean isUint16(final TypeDefinition<?> type) {
141 return BaseUint16Type.INSTANCE.getPath().equals(findBaseTypePath(type));
144 public static UnsignedIntegerTypeDefinition uint32Type() {
145 return BaseUint32Type.INSTANCE;
148 public static boolean isUint32(final TypeDefinition<?> type) {
149 return BaseUint32Type.INSTANCE.getPath().equals(findBaseTypePath(type));
152 public static UnsignedIntegerTypeDefinition uint64Type() {
153 return BaseUint64Type.INSTANCE;
156 public static boolean isUint64(final TypeDefinition<?> type) {
157 return BaseUint64Type.INSTANCE.getPath().equals(findBaseTypePath(type));
160 private static SchemaPath findBaseTypePath(final TypeDefinition<?> type) {
161 TypeDefinition<?> ret = type;
162 while (ret.getBaseType() != null) {
163 ret = ret.getBaseType();
165 return ret.getPath();