]> git.basschouten.com Git - openhab-addons.git/blob
d605f332798447eb80a03abd88cd1dbda1f9c404
[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.dscalarm.internal.handler;
14
15 import java.util.HashMap;
16 import java.util.Map;
17
18 /**
19  * Used to map thing types from the binding string to an ENUM value.
20  *
21  * @author Russell Stephens - Initial Contribution
22  */
23 public enum DSCAlarmThingType {
24     PANEL("panel"),
25     PARTITION("partition"),
26     ZONE("zone"),
27     KEYPAD("keypad");
28
29     private String label;
30
31     /**
32      * Lookup map to get a DSCAlarmDeviceType from its label.
33      */
34     private static Map<String, DSCAlarmThingType> labelToDSCAlarmThingType;
35
36     /**
37      * Constructor.
38      *
39      * @param label
40      */
41     private DSCAlarmThingType(String label) {
42         this.label = label;
43     }
44
45     /**
46      * Creates a HashMap that maps the string label to a DSCAlarmDeviceType enum value.
47      */
48     private static void initMapping() {
49         labelToDSCAlarmThingType = new HashMap<>();
50         for (DSCAlarmThingType s : values()) {
51             labelToDSCAlarmThingType.put(s.label, s);
52         }
53     }
54
55     /**
56      * Returns the label of the DSCAlarmItemType Values enumeration.
57      *
58      * @return the label
59      */
60     public String getLabel() {
61         return label;
62     }
63
64     /**
65      * Lookup function based on the binding type label. Returns null if the binding type is not found.
66      *
67      * @param label
68      * @return enum value
69      */
70     public static DSCAlarmThingType getDSCAlarmThingType(String label) {
71         if (labelToDSCAlarmThingType == null) {
72             initMapping();
73         }
74         return labelToDSCAlarmThingType.get(label);
75     }
76 }