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.alarmdecoder.internal.protocol;
15 import java.util.ArrayList;
16 import java.util.List;
17 import java.util.regex.Matcher;
18 import java.util.regex.Pattern;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
23 * Superclass for all Alarm Decoder protocol message types.
24 * Includes code from the original OH1 alarmdecoder binding by Bernd Pfrommer.
26 * @author Bob Adair - Initial contribution
29 public abstract class ADMessage {
31 protected static final Pattern SPLIT_REGEX = Pattern.compile("[^\\,\"]+|\"[^\"]*\"");
33 /** string containing the original unparsed message */
34 public final String message;
36 public ADMessage(String message) {
37 this.message = message;
41 public String toString() {
45 /** Utility routine to split an AD message into its component parts */
46 protected static List<String> splitMsg(String msg) {
47 List<String> l = new ArrayList<String>();
48 Matcher regexMatcher = SPLIT_REGEX.matcher(msg);
49 while (regexMatcher.find()) {
50 l.add(regexMatcher.group());