BUG-865: remove deprecated BaseTypes constants
[yangtools.git] / yang / yang-model-util / src / main / java / org / opendaylight / yangtools / yang / model / util / BaseTypes.java
1 /*
2  * Copyright (c) 2013 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 package org.opendaylight.yangtools.yang.model.util;
9
10 import com.google.common.base.Strings;
11 import com.google.common.collect.ImmutableSet;
12 import java.util.Set;
13 import org.opendaylight.yangtools.yang.common.QName;
14 import org.opendaylight.yangtools.yang.common.YangConstants;
15 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
16
17 /**
18  * Utility methods and constants to work with built-in YANG types
19  *
20  *
21  */
22 public final class BaseTypes {
23
24     private BaseTypes() {
25     }
26
27     public static final QName BINARY_QNAME = constructQName("binary");
28     public static final QName BITS_QNAME = constructQName("bits");
29     public static final QName BOOLEAN_QNAME = constructQName("boolean");
30     public static final QName DECIMAL64_QNAME = constructQName("decimal64");
31     public static final QName EMPTY_QNAME = constructQName("empty");
32     public static final QName ENUMERATION_QNAME = constructQName("enumeration");
33     public static final QName IDENTITYREF_QNAME = constructQName("identityref");
34     public static final QName INSTANCE_IDENTIFIER_QNAME = constructQName("instance-identifier");
35     public static final QName INT8_QNAME = constructQName("int8");
36     public static final QName INT16_QNAME = constructQName("int16");
37     public static final QName INT32_QNAME = constructQName("int32");
38     public static final QName INT64_QNAME = constructQName("int64");
39     public static final QName LEAFREF_QNAME = constructQName("leafref");
40     public static final QName STRING_QNAME = constructQName("string");
41     public static final QName UINT8_QNAME = constructQName("uint8");
42     public static final QName UINT16_QNAME = constructQName("uint16");
43     public static final QName UINT32_QNAME = constructQName("uint32");
44     public static final QName UINT64_QNAME = constructQName("uint64");
45     public static final QName UNION_QNAME = constructQName("union");
46
47     private static final Set<QName> BUILT_IN_TYPES = ImmutableSet.<QName>builder()
48             .add(BINARY_QNAME)
49             .add(BITS_QNAME)
50             .add(BOOLEAN_QNAME)
51             .add(DECIMAL64_QNAME)
52             .add(EMPTY_QNAME)
53             .add(ENUMERATION_QNAME)
54             .add(IDENTITYREF_QNAME)
55             .add(INSTANCE_IDENTIFIER_QNAME)
56             .add(INT8_QNAME)
57             .add(INT16_QNAME)
58             .add(INT32_QNAME)
59             .add(INT64_QNAME)
60             .add(LEAFREF_QNAME)
61             .add(STRING_QNAME)
62             .add(UINT8_QNAME)
63             .add(UINT16_QNAME)
64             .add(UINT32_QNAME)
65             .add(UINT64_QNAME)
66             .add(UNION_QNAME)
67             .build();
68
69     /**
70      * Construct QName for Built-in base Yang type. The namespace for built-in
71      * base yang types is defined as: urn:ietf:params:xml:ns:yang:1
72      *
73      * @param typeName
74      *            yang type name
75      * @return built-in base yang type QName.
76      */
77     public static QName constructQName(final String typeName) {
78         return QName.create(YangConstants.RFC6020_YANG_MODULE, typeName).intern();
79     }
80
81     /**
82      * Returns true if supplied type is representation of built-in YANG type as
83      * per RFC 6020.
84      *
85      * See package documentation for description of base types.
86      *
87      * @param type
88      * @return true if type is built-in YANG Types.
89      */
90     public static boolean isYangBuildInType(final String type) {
91         return !Strings.isNullOrEmpty(type) && BUILT_IN_TYPES.contains(
92                 QName.create(YangConstants.RFC6020_YANG_MODULE, type));
93     }
94
95     /**
96      * Returns true if supplied type is representation of built-in YANG type as
97      * per RFC 6020.
98      *
99      * See package documentation for description of base types.
100      *
101      * @param type
102      * @return true if type is built-in YANG Types.
103      */
104     public static boolean isYangBuildInType(final TypeDefinition<?> type) {
105         return type != null && BUILT_IN_TYPES.contains(type.getQName());
106     }
107 }