]> git.basschouten.com Git - openhab-addons.git/blob
2bee872d6bd9d5aa7d11c422720acb7c64b67856
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.bluetooth.bluegiga.internal.enumeration;
14
15 import java.util.HashMap;
16 import java.util.Map;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20
21 /**
22  * Class to implement the BlueGiga Enumeration <b>AttributeValueType</b>.
23  * <p>
24  * These enumerations are in the Attribute Client class
25  * <p>
26  * Note that this code is autogenerated. Manual changes may be overwritten.
27  *
28  * @author Chris Jackson - Initial contribution of Java code generator
29  */
30 @NonNullByDefault
31 public enum AttributeValueType {
32     /**
33      * Default unknown value
34      */
35     UNKNOWN(-1),
36
37     /**
38      * [0] Value was read
39      */
40     ATTCLIENT_ATTRIBUTE_VALUE_TYPE_READ(0x0000),
41
42     /**
43      * [1] Value was notified
44      */
45     ATTCLIENT_ATTRIBUTE_VALUE_TYPE_NOTIFY(0x0001),
46
47     /**
48      * [2] Value was indicated
49      */
50     ATTCLIENT_ATTRIBUTE_VALUE_TYPE_INDICATE(0x0002),
51
52     /**
53      * [3] Value was read
54      */
55     ATTCLIENT_ATTRIBUTE_VALUE_TYPE_READ_BY_TYPE(0x0003),
56
57     /**
58      * [4] Value was part of a long attribute
59      */
60     ATTCLIENT_ATTRIBUTE_VALUE_TYPE_READ_BLOB(0x0004),
61
62     /**
63      * [5] Value was indicated and the remote device is waiting for a confirmation. Indicate
64      * Confirm command can be used to send a confirmation.
65      */
66     ATTCLIENT_ATTRIBUTE_VALUE_TYPE_INDICATE_RSP_REQ(0x0005);
67
68     /**
69      * A mapping between the integer code and its corresponding type to
70      * facilitate lookup by code.
71      */
72     private static @Nullable Map<Integer, AttributeValueType> codeMapping;
73
74     private int key;
75
76     private AttributeValueType(int key) {
77         this.key = key;
78     }
79
80     /**
81      * Lookup function based on the type code. Returns {@link UNKNOWN} if the code does not exist.
82      *
83      * @param attributeValueType
84      *            the code to lookup
85      * @return enumeration value.
86      */
87     public static AttributeValueType getAttributeValueType(int attributeValueType) {
88         Map<Integer, AttributeValueType> localCodeMapping = codeMapping;
89         if (localCodeMapping == null) {
90             localCodeMapping = new HashMap<>();
91             for (AttributeValueType s : values()) {
92                 localCodeMapping.put(s.key, s);
93             }
94             codeMapping = localCodeMapping;
95         }
96
97         return localCodeMapping.getOrDefault(attributeValueType, UNKNOWN);
98     }
99
100     /**
101      * Returns the BlueGiga protocol defined value for this enum
102      *
103      * @return the BGAPI enumeration key
104      */
105     public int getKey() {
106         return key;
107     }
108 }