]> git.basschouten.com Git - openhab-addons.git/blob
7a6bbac7345835dc8dc5a8b48f0605a568506928
[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.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 public class MsgDefinition {
31     private Map<String, 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(MsgDefinition m) {
42         fields = new HashMap<>(m.fields);
43     }
44
45     public Map<String, 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 }