2 * Copyright (c) 2010-2024 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 public class MsgDefinition {
31 private Map<String, Field> fields = new HashMap<>();
37 * Copy constructor, needed to make a copy of a message
39 * @param m the definition to copy
41 MsgDefinition(MsgDefinition m) {
42 fields = new HashMap<>(m.fields);
45 public Map<String, Field> getFields() {
49 public boolean containsField(String name) {
50 return fields.containsKey(name);
53 public void addField(Field field) {
54 fields.put(field.getName(), field);
58 * Finds field of a given name
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
64 public Field getField(@Nullable String name) throws FieldException {
66 Field f = fields.get(name);
68 throw new FieldException("field " + name + " not found");