]> git.basschouten.com Git - openhab-addons.git/blob
200ce93bdfb08ef56a72a57299221c9dc245caf7
[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>ConnectionStatusFlag</b>.
20  * <p>
21  * The possible connection status flags are described in the table below. The flags field is a
22  * bit mask, so multiple flags can be set at a time. If the bit is 1 the flag is active and if the bit is
23  * 0 the flag is inactive.
24  * <p>
25  * Note that this code is autogenerated. Manual changes may be overwritten.
26  *
27  * @author Chris Jackson - Initial contribution of Java code generator
28  */
29 public enum ConnectionStatusFlag {
30     /**
31      * Default unknown value
32      */
33     UNKNOWN(-1),
34
35     /**
36      * [1] This status flag tells the connection exists to a remote device.
37      */
38     CONNECTION_CONNECTED(0x0001),
39
40     /**
41      * [2] This flag tells the connection is encrypted.
42      */
43     CONNECTION_ENCRYPTED(0x0002),
44
45     /**
46      * [4] Connection completed flag, which is used to tell a new connection has been created.
47      */
48     CONNECTION_COMPLETED(0x0004),
49
50     /**
51      * [8] This flag tells that connection parameters have changed and. It is set when connection
52      * parameters have changed due to a link layer operation.
53      */
54     CONNECTION_PARAMETERS_CHANGE(0x0008);
55
56     /**
57      * A mapping between the integer code and its corresponding type to
58      * facilitate lookup by code.
59      */
60     private static Map<Integer, ConnectionStatusFlag> codeMapping;
61
62     private int key;
63
64     private ConnectionStatusFlag(int key) {
65         this.key = key;
66     }
67
68     private static void initMapping() {
69         codeMapping = new HashMap<>();
70         for (ConnectionStatusFlag s : values()) {
71             codeMapping.put(s.key, s);
72         }
73     }
74
75     /**
76      * Lookup function based on the type code. Returns null if the code does not exist.
77      *
78      * @param connectionStatusFlag
79      *            the code to lookup
80      * @return enumeration value.
81      */
82     public static ConnectionStatusFlag getConnectionStatusFlag(int connectionStatusFlag) {
83         if (codeMapping == null) {
84             initMapping();
85         }
86
87         if (codeMapping.get(connectionStatusFlag) == null) {
88             return UNKNOWN;
89         }
90
91         return codeMapping.get(connectionStatusFlag);
92     }
93
94     /**
95      * Returns the BlueGiga protocol defined value for this enum
96      *
97      * @return the BGAPI enumeration key
98      */
99     public int getKey() {
100         return key;
101     }
102 }