]> git.basschouten.com Git - openhab-addons.git/blob
15a27e825e1aa18b82bc027cc9c4035fa190e493
[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.livisismarthome.internal.client.api.entity.link;
14
15 /**
16  * Defines the data structure for a {@link LinkDTO}. This is the basic component used to link different data types in
17  * the
18  * LIVISI API.
19  *
20  * @author Oliver Kuhl - Initial contribution
21  */
22 public class LinkDTO {
23
24     public static final String LINK_TYPE_CAPABILITY = "/capability/";
25     public static final String LINK_TYPE_DEVICE = "/device/";
26     public static final String LINK_TYPE_MESSAGE = "/message/";
27     public static final String LINK_TYPE_SHC = "/desc/device/SHC.RWE/";
28     public static final String LINK_TYPE_UNKNOWN = "unknown";
29
30     /**
31      * Returns the Type of the {@link LinkDTO}.
32      *
33      * @return {@link #LINK_TYPE_CAPABILITY},{@link #LINK_TYPE_DEVICE}, {@link #LINK_TYPE_MESSAGE},
34      *         {@link #LINK_TYPE_SHC} or {@link #LINK_TYPE_UNKNOWN}
35      */
36     public static String getLinkType(String link) {
37         if (link.startsWith(LINK_TYPE_CAPABILITY)) {
38             return LINK_TYPE_CAPABILITY;
39         } else if (link.startsWith(LINK_TYPE_DEVICE)) {
40             return LINK_TYPE_DEVICE;
41         } else if (link.startsWith(LINK_TYPE_MESSAGE)) {
42             return LINK_TYPE_MESSAGE;
43         } else if (link.startsWith(LINK_TYPE_SHC)) {
44             return LINK_TYPE_SHC;
45         } else {
46             return LINK_TYPE_UNKNOWN;
47         }
48     }
49
50     /**
51      * Returns the id of the {@link LinkDTO} or null, if the link does not have an id or even no value.
52      *
53      * @return String the id of the link or null
54      */
55     public static String getId(String link) {
56         if (link != null) {
57             final String linkType = getLinkType(link);
58             if (linkType != null && !LinkDTO.LINK_TYPE_UNKNOWN.equals(linkType)
59                     && !LinkDTO.LINK_TYPE_SHC.equals(linkType)) {
60                 return link.replace(linkType, "");
61             }
62         }
63         return null;
64     }
65
66     /**
67      * Returns true, if the {@link LinkDTO} points to a
68      * {@link org.openhab.binding.livisismarthome.internal.client.api.entity.capability.CapabilityDTO}.
69      *
70      * @return true if the link points to a capability, otherwise false
71      */
72     public static boolean isTypeCapability(String link) {
73         return LINK_TYPE_CAPABILITY.equals(LinkDTO.getLinkType(link));
74     }
75
76     /**
77      * Returns true, if the {@link LinkDTO} points to a
78      * {@link org.openhab.binding.livisismarthome.internal.client.api.entity.device.DeviceDTO}.
79      *
80      * @return true if the link points to a device, otherwise false
81      */
82     public static boolean isTypeDevice(String link) {
83         return LINK_TYPE_DEVICE.equals(LinkDTO.getLinkType(link));
84     }
85
86     /**
87      * Returns true, if the {@link LinkDTO} points to a
88      * {@link org.openhab.binding.livisismarthome.internal.client.api.entity.message.MessageDTO}.
89      *
90      * @return true if the link points to a message, otherwise false
91      */
92     public static boolean isTypeMessage(String link) {
93         return LINK_TYPE_MESSAGE.equals(LinkDTO.getLinkType(link));
94     }
95
96     /**
97      * Returns true, if the {@link LinkDTO} points to a SHC.
98      *
99      * @return true if the link points to a SHC bridge device, otherwise false
100      */
101     public static boolean isTypeSHC(String link) {
102         return LINK_TYPE_SHC.equals(LinkDTO.getLinkType(link));
103     }
104
105     /**
106      * Returns true, if the {@link LinkDTO} points to something unknown.
107      *
108      * @return true if the link points to something unknown, otherwise false
109      */
110     public static boolean isTypeUnknown(String link) {
111         return LINK_TYPE_UNKNOWN.equals(LinkDTO.getLinkType(link));
112     }
113 }