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.transport.message;
15 import java.util.Comparator;
16 import java.util.HashMap;
17 import java.util.List;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
23 * Definition (layout) of an Insteon message. Says which bytes go where.
24 * For more info, see the public Insteon Developer's Guide, 2nd edition,
25 * and the Insteon Modem Developer's Guide.
27 * @author Daniel Pfrommer - Initial contribution
28 * @author Rob Nielsen - Port to openHAB 2 insteon binding
29 * @author Jeremy Setton - Rewrite insteon binding
32 public class MsgDefinition {
33 private Map<String, Field> fields = new HashMap<>();
38 MsgDefinition(MsgDefinition definition) {
39 fields = new HashMap<>(definition.fields);
42 public List<Field> getFields() {
43 return fields.values().stream().sorted(Comparator.comparing(Field::getOffset)).toList();
46 public boolean containsField(String name) {
47 return fields.containsKey(name);
50 public void addField(Field field) {
51 fields.put(field.getName(), field);
55 * Finds field of a given name
57 * @param name name of the field to search for
58 * @return reference to field
59 * @throws FieldException if no such field can be found
61 public Field getField(String name) throws FieldException {
62 Field field = fields.get(name);
64 throw new FieldException("field " + name + " not found");