]> git.basschouten.com Git - openhab-addons.git/blob
e385faa747d444361276c89944d2db0cfca68f81
[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>ScanResponseType</b>.
23  * <p>
24  * Defines the packet types received during a scan response
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 ScanResponseType {
32     /**
33      * Default unknown value
34      */
35     UNKNOWN(-1),
36
37     /**
38      * [0] Connectable Advertisement packet
39      */
40     CONNECTABLE_ADVERTISEMENT(0x0000),
41
42     /**
43      * [2] Non Connectable Advertisement packet
44      */
45     NON_CONNECTABLE_ADVERTISEMENT(0x0002),
46
47     /**
48      * [4] Scan response packet
49      */
50     SCAN_RESPONSE(0x0004),
51
52     /**
53      * [6] Discoverable advertisement packet
54      */
55     DISCOVERABLE_ADVERTISEMENT(0x0006);
56
57     /**
58      * A mapping between the integer code and its corresponding type to
59      * facilitate lookup by code.
60      */
61     private static @Nullable Map<Integer, ScanResponseType> codeMapping;
62
63     private int key;
64
65     private ScanResponseType(int key) {
66         this.key = key;
67     }
68
69     /**
70      * Lookup function based on the type code. Returns {@link UNKNOWN} if the code does not exist.
71      *
72      * @param scanResponseType
73      *            the code to lookup
74      * @return enumeration value.
75      */
76     public static ScanResponseType getScanResponseType(int scanResponseType) {
77         Map<Integer, ScanResponseType> localCodeMapping = codeMapping;
78         if (localCodeMapping == null) {
79             localCodeMapping = new HashMap<>();
80             for (ScanResponseType s : values()) {
81                 localCodeMapping.put(s.key, s);
82             }
83             codeMapping = localCodeMapping;
84         }
85
86         return localCodeMapping.getOrDefault(scanResponseType, UNKNOWN);
87     }
88
89     /**
90      * Returns the BlueGiga protocol defined value for this enum
91      *
92      * @return the BGAPI enumeration key
93      */
94     public int getKey() {
95         return key;
96     }
97 }