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.rfxcom.internal.messages;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
19 * An Utility class to handle {@link ByteEnumWrapper} instances
21 * @author Martin van Wingerden - Initial contribution
24 public class ByteEnumUtil {
25 private ByteEnumUtil() {
29 public static <T extends ByteEnumWrapper> T fromByte(Class<T> typeClass, int input)
30 throws RFXComUnsupportedValueException {
31 for (T enumValue : typeClass.getEnumConstants()) {
32 if (enumValue.toByte() == input) {
37 throw new RFXComUnsupportedValueException(typeClass, input);
40 public static <T extends ByteEnumWrapper> T convertSubType(Class<T> typeClass, String subType)
41 throws RFXComUnsupportedValueException {
42 for (T enumValue : typeClass.getEnumConstants()) {
43 if (enumValue.toString().equals(subType)) {
49 int byteValue = Integer.parseInt(subType);
50 return fromByte(typeClass, byteValue);
51 } catch (NumberFormatException e) {
52 throw new RFXComUnsupportedValueException(typeClass, subType);
56 public static <T extends ByteEnumWrapperWithSupportedSubTypes<?>> T fromByte(Class<T> typeClass, int input,
57 Object subType) throws RFXComUnsupportedValueException {
58 for (T enumValue : typeClass.getEnumConstants()) {
59 if (enumValue.toByte() == input && enumValue.supportedBySubTypes().contains(subType)) {
64 throw new RFXComUnsupportedValueException(RFXComLighting5Message.Commands.class, input, subType);