2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.bluetooth.bluegiga.internal.enumeration;
15 import java.util.HashMap;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
22 * Class to implement the BlueGiga Enumeration <b>ConnectionStatusFlag</b>.
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.
28 * Note that this code is autogenerated. Manual changes may be overwritten.
30 * @author Chris Jackson - Initial contribution of Java code generator
33 public enum ConnectionStatusFlag {
35 * Default unknown value
40 * [1] This status flag tells the connection exists to a remote device.
42 CONNECTION_CONNECTED(0x0001),
45 * [2] This flag tells the connection is encrypted.
47 CONNECTION_ENCRYPTED(0x0002),
50 * [4] Connection completed flag, which is used to tell a new connection has been created.
52 CONNECTION_COMPLETED(0x0004),
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.
58 CONNECTION_PARAMETERS_CHANGE(0x0008);
61 * A mapping between the integer code and its corresponding type to
62 * facilitate lookup by code.
64 private static @Nullable Map<Integer, ConnectionStatusFlag> codeMapping;
68 private ConnectionStatusFlag(int key) {
73 * Lookup function based on the type code. Returns {@link UNKNOWN} if the code does not exist.
75 * @param connectionStatusFlag
77 * @return enumeration value.
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);
86 codeMapping = localCodeMapping;
89 return localCodeMapping.getOrDefault(connectionStatusFlag, UNKNOWN);
93 * Returns the BlueGiga protocol defined value for this enum
95 * @return the BGAPI enumeration key