2 * Copyright (c) 2010-2020 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.insteon.internal.message;
15 import java.util.HashMap;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
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.
26 * @author Daniel Pfrommer - Initial contribution
27 * @author Rob Nielsen - Port to openHAB 2 insteon binding
30 @SuppressWarnings("null")
31 public class MsgDefinition {
32 private Map<String, Field> fields = new HashMap<>();
38 * Copy constructor, needed to make a copy of a message
40 * @param m the definition to copy
42 MsgDefinition(@Nullable MsgDefinition m) {
43 fields = new HashMap<>(m.fields);
46 public Map<String, Field> getFields() {
50 public boolean containsField(String name) {
51 return fields.containsKey(name);
54 public void addField(Field field) {
55 fields.put(field.getName(), field);
59 * Finds field of a given name
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
65 public Field getField(@Nullable String name) throws FieldException {
67 Field f = fields.get(name);
69 throw new FieldException("field " + name + " not found");