]> git.basschouten.com Git - openhab-addons.git/blob
2eb78e17d861e1ba1a10eaae71f3deec0a3b4326
[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 /**
19  * Class to implement the BlueGiga Enumeration <b>BluetoothAddressType</b>.
20  * <p>
21  * Bluetooth address types
22  * <p>
23  * Note that this code is autogenerated. Manual changes may be overwritten.
24  *
25  * @author Chris Jackson - Initial contribution of Java code generator
26  */
27 public enum BluetoothAddressType {
28     /**
29      * Default unknown value
30      */
31     UNKNOWN(-1),
32
33     /**
34      * [0] Public Address
35      */
36     GAP_ADDRESS_TYPE_PUBLIC(0x0000),
37
38     /**
39      * [1] Random Address
40      */
41     GAP_ADDRESS_TYPE_RANDOM(0x0001);
42
43     /**
44      * A mapping between the integer code and its corresponding type to
45      * facilitate lookup by code.
46      */
47     private static Map<Integer, BluetoothAddressType> codeMapping;
48
49     private int key;
50
51     private BluetoothAddressType(int key) {
52         this.key = key;
53     }
54
55     private static void initMapping() {
56         codeMapping = new HashMap<>();
57         for (BluetoothAddressType s : values()) {
58             codeMapping.put(s.key, s);
59         }
60     }
61
62     /**
63      * Lookup function based on the type code. Returns null if the code does not exist.
64      *
65      * @param bluetoothAddressType
66      *            the code to lookup
67      * @return enumeration value.
68      */
69     public static BluetoothAddressType getBluetoothAddressType(int bluetoothAddressType) {
70         if (codeMapping == null) {
71             initMapping();
72         }
73
74         if (codeMapping.get(bluetoothAddressType) == null) {
75             return UNKNOWN;
76         }
77
78         return codeMapping.get(bluetoothAddressType);
79     }
80
81     /**
82      * Returns the BlueGiga protocol defined value for this enum
83      *
84      * @return the BGAPI enumeration key
85      */
86     public int getKey() {
87         return key;
88     }
89 }