]> git.basschouten.com Git - openhab-addons.git/blob
689f9adcffbcc17735291d4f5a3a297ccafe8d75
[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>GapConnectableMode</b>.
23  * <p>
24  * GAP connectable modes
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 GapConnectableMode {
32     /**
33      * Default unknown value
34      */
35     UNKNOWN(-1),
36
37     /**
38      * [0] Not connectable
39      */
40     GAP_NON_CONNECTABLE(0x0000),
41
42     /**
43      * [1] Directed Connectable
44      */
45     GAP_DIRECTED_CONNECTABLE(0x0001),
46
47     /**
48      * [2] Undirected connectable
49      */
50     GAP_UNDIRECTED_CONNECTABLE(0x0002),
51
52     /**
53      * [3] Same as non-connectable, but also supports ADV_SCAN_IND packets. Device accepts scan
54      * requests (active scanning) but is not connectable.
55      */
56     GAP_SCANNABLE_NON_CONNECTABLE(0x0003);
57
58     /**
59      * A mapping between the integer code and its corresponding type to
60      * facilitate lookup by code.
61      */
62     private static @Nullable Map<Integer, GapConnectableMode> codeMapping;
63
64     private int key;
65
66     private GapConnectableMode(int key) {
67         this.key = key;
68     }
69
70     /**
71      * Lookup function based on the type code. Returns {@link UNKNOWN} if the code does not exist.
72      *
73      * @param gapConnectableMode
74      *            the code to lookup
75      * @return enumeration value.
76      */
77     public static GapConnectableMode getGapConnectableMode(int gapConnectableMode) {
78         Map<Integer, GapConnectableMode> localCodeMapping = codeMapping;
79         if (localCodeMapping == null) {
80             localCodeMapping = new HashMap<>();
81             for (GapConnectableMode s : values()) {
82                 localCodeMapping.put(s.key, s);
83             }
84             codeMapping = localCodeMapping;
85         }
86
87         return localCodeMapping.getOrDefault(gapConnectableMode, UNKNOWN);
88     }
89
90     /**
91      * Returns the BlueGiga protocol defined value for this enum
92      *
93      * @return the BGAPI enumeration key
94      */
95     public int getKey() {
96         return key;
97     }
98 }