]> git.basschouten.com Git - openhab-addons.git/blob
b18c4cdb142a01ca71526f91bc7e781c59b4c250
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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.message;
14
15 import java.util.HashMap;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19
20 /**
21  * Definition (layout) of an Insteon message. Says which bytes go where.
22  * For more info, see the public Insteon Developer's Guide, 2nd edition,
23  * and the Insteon Modem Developer's Guide.
24  *
25  * @author Daniel Pfrommer - Initial contribution
26  * @author Rob Nielsen - Port to openHAB 2 insteon binding
27  */
28 @NonNullByDefault
29 @SuppressWarnings("null")
30 public class MsgDefinition {
31     private HashMap<String, @Nullable Field> fields = new HashMap<>();
32
33     MsgDefinition() {
34     }
35
36     /*
37      * Copy constructor, needed to make a copy of a message
38      *
39      * @param m the definition to copy
40      */
41     MsgDefinition(@Nullable MsgDefinition m) {
42         fields = new HashMap<>(m.fields);
43     }
44
45     public HashMap<String, @Nullable Field> getFields() {
46         return fields;
47     }
48
49     public boolean containsField(String name) {
50         return fields.containsKey(name);
51     }
52
53     public void addField(Field field) {
54         fields.put(field.getName(), field);
55     }
56
57     /**
58      * Finds field of a given name
59      *
60      * @param name name of the field to search for
61      * @return reference to field
62      * @throws FieldException if no such field can be found
63      */
64     public Field getField(@Nullable String name) throws FieldException {
65         @Nullable
66         Field f = fields.get(name);
67         if (f == null) {
68             throw new FieldException("field " + name + " not found");
69         }
70         return f;
71     }
72 }