Remove yang.model.util.BaseTypes
[yangtools.git] / yang / yang-model-api / src / main / java / org / opendaylight / yangtools / yang / model / api / type / BitsTypeDefinition.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.api.type;
9
10 import java.util.Collection;
11 import java.util.Objects;
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.eclipse.jdt.annotation.Nullable;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.common.Uint32;
16 import org.opendaylight.yangtools.yang.common.YangConstants;
17 import org.opendaylight.yangtools.yang.model.api.DocumentedNode;
18 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
19
20 /**
21  * Makes is possible to access to the individual bits values of this type.
22  */
23 public interface BitsTypeDefinition extends TypeDefinition<BitsTypeDefinition> {
24     /**
25      * Well-known QName of the {@code bits} built-in type.
26      */
27     QName QNAME = QName.create(YangConstants.RFC6020_YANG_MODULE, "bits").intern();
28
29     /**
30      * Returns all bit values.
31      *
32      * @return list of {@code Bit} type instances with data about all individual bits of {@code bits} YANG built-in type
33      */
34     @NonNull Collection<? extends Bit> getBits();
35
36     static int hashCode(final @NonNull BitsTypeDefinition type) {
37         return Objects.hash(type.getQName(), type.getUnknownSchemaNodes(), type.getBaseType(),
38             type.getUnits().orElse(null), type.getDefaultValue().orElse(null), type.getBits());
39     }
40
41     static boolean equals(final @NonNull BitsTypeDefinition type, final @Nullable Object obj) {
42         if (type == obj) {
43             return true;
44         }
45
46         final BitsTypeDefinition other = TypeDefinitions.castIfEquals(BitsTypeDefinition.class, type, obj);
47         return other != null && type.getBits().equals(other.getBits());
48     }
49
50     static String toString(final @NonNull BitsTypeDefinition type) {
51         return TypeDefinitions.toStringHelper(type).add("bits", type.getBits()).toString();
52     }
53
54     /**
55      * Contains the methods for accessing the data about the individual bit of
56      * <code>bits</code> YANG type.
57      */
58     interface Bit extends DocumentedNode.WithStatus {
59         /**
60          * Returns the name of the concrete bit.
61          *
62          * @return string with the name of the concrete bit
63          */
64         @NonNull String getName();
65
66         /**
67          * The position value MUST be in the range 0 to 4294967295, and it MUST
68          * be unique within the bits type.
69          *
70          * @return The position value of bit in range from 0 to 4294967295.
71          */
72         @NonNull Uint32 getPosition();
73     }
74 }