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