]> git.basschouten.com Git - openhab-addons.git/blob
5d6418014903134147d2bbe1fbd051435f57212a
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.alarmdecoder.internal.protocol;
14
15 import java.util.ArrayList;
16 import java.util.List;
17 import java.util.regex.Matcher;
18 import java.util.regex.Pattern;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21
22 /**
23  * Superclass for all Alarm Decoder protocol message types.
24  * Includes code from the original OH1 alarmdecoder binding by Bernd Pfrommer.
25  *
26  * @author Bob Adair - Initial contribution
27  */
28 @NonNullByDefault
29 public abstract class ADMessage {
30
31     protected static final Pattern SPLIT_REGEX = Pattern.compile("[^\\,\"]+|\"[^\"]*\"");
32
33     /** string containing the original unparsed message */
34     public final String message;
35
36     public ADMessage(String message) {
37         this.message = message;
38     }
39
40     @Override
41     public String toString() {
42         return message;
43     }
44
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());
51         }
52         return l;
53     }
54 }