2 * Copyright (c) 2010-2024 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.insteon.internal.message;
15 import java.util.HashMap;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
21 * Defines the data types that can be used in the fields of a message.
23 * @author Daniel Pfrommer - Initial contribution
24 * @author Rob Nielsen - Port to openHAB 2 insteon binding
27 public enum DataType {
31 ADDRESS("address", 3),
32 INVALID("INVALID", -1);
34 private static Map<String, DataType> typeMap = new HashMap<>();
40 typeMap.put(BYTE.getName(), BYTE);
41 typeMap.put(INT.getName(), INT);
42 typeMap.put(FLOAT.getName(), FLOAT);
43 typeMap.put(ADDRESS.getName(), ADDRESS);
49 * @param name the name of the data type
50 * @param size the size (in bytes) of this data type
52 DataType(String name, int size) {
58 * @return the size (in bytes) of this data type
60 public int getSize() {
65 * @return clear text string with the name
67 public String getName() {
72 * Turns a string into the corresponding data type
74 * @param name the string to translate to a type
75 * @return the data type corresponding to the name string, or null if not found
77 public static DataType getDataType(String name) {
78 DataType dataType = typeMap.get(name);
79 if (dataType != null) {
82 throw new IllegalArgumentException("Unable to find data type for " + name);