]> git.basschouten.com Git - openhab-addons.git/blob
6836e0dc33b615644251e60fcf47887cca3de5b7
[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.lametrictime.internal;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16
17 /**
18  * This bean represents the information necessary to uniquely reference a widget on the LaMetric Time platform.
19  *
20  * @author Gregor Moyer - Initial contribution
21  */
22 @NonNullByDefault
23 public class WidgetRef {
24     private final String packageName;
25     private final String widgetId;
26
27     /**
28      * Build a {@link WidgetRef} from the given String.
29      *
30      * @param widgetRef formatted as <code>package name:widget ID</code>
31      * @return the widget reference
32      */
33     public static WidgetRef fromString(String widgetRef) {
34         String[] tokens = widgetRef.split(":");
35         if (tokens.length != 2) {
36             throw new IllegalArgumentException(
37                     "Provided string '" + widgetRef + "' is not in the format '<package name>:<widget ID>'");
38         }
39
40         return new WidgetRef(tokens[0], tokens[1]);
41     }
42
43     public WidgetRef(String packageName, String widgetId) {
44         this.packageName = packageName;
45         this.widgetId = widgetId;
46     }
47
48     public String getPackageName() {
49         return packageName;
50     }
51
52     public String getWidgetId() {
53         return widgetId;
54     }
55
56     @Override
57     public String toString() {
58         return packageName + ":" + widgetId;
59     }
60 }