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