]> git.basschouten.com Git - openhab-addons.git/blob
3b6d753debe82b7742e5b9692add550b360d25d9
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.insteon.internal.transport.message;
14
15 import java.util.Arrays;
16 import java.util.Map;
17 import java.util.function.Function;
18 import java.util.stream.Collectors;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21
22 /**
23  * Defines the data types that can be used in the fields of a message.
24  *
25  * @author Daniel Pfrommer - Initial contribution
26  * @author Rob Nielsen - Port to openHAB 2 insteon binding
27  * @author Jeremy Setton - Rewrite insteon binding
28  */
29 @NonNullByDefault
30 public enum DataType {
31     BYTE("byte", 1),
32     ADDRESS("address", 3),
33     INVALID("invalid", -1);
34
35     private static final Map<String, DataType> NAME_MAP = Arrays.stream(values())
36             .collect(Collectors.toUnmodifiableMap(type -> type.name, Function.identity()));
37
38     private final String name;
39     private final int size;
40
41     private DataType(String name, int size) {
42         this.name = name;
43         this.size = size;
44     }
45
46     public String getName() {
47         return name;
48     }
49
50     public int getSize() {
51         return size;
52     }
53
54     /**
55      * Factory method for getting a DataType from the data type name
56      *
57      * @param name the data type name
58      * @return the data type
59      */
60     public static DataType get(String name) {
61         return NAME_MAP.getOrDefault(name, DataType.INVALID);
62     }
63 }