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