]> git.basschouten.com Git - openhab-addons.git/blob
ba5e820810e1b369096f8a0085fb95d36dea23dc
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 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.io.neeo.internal.models;
14
15 import org.apache.commons.lang.StringUtils;
16 import org.eclipse.jdt.annotation.NonNullByDefault;
17 import org.eclipse.jdt.annotation.Nullable;
18 import org.openhab.io.neeo.internal.NeeoUtil;
19
20 /**
21  * Represents a directory list item. This class is simply used for serialization of the result back to the brain.
22  *
23  * @author Tim Roberts - Initial Contribution
24  *
25  */
26 @NonNullByDefault
27 public class NeeoDirectoryResultItem {
28     /** The title (label) of the item */
29     private final String title;
30
31     /** The URI to the thumbnail representing the item */
32     @Nullable
33     private final String thumbnailUri;
34
35     /** The browse identifier (reflected back in a request if this item is a container) */
36     @Nullable
37     private final String browseIdentifier;
38
39     /** The action identifier (reflected back in a request if this is a leaf) */
40     @Nullable
41     private final String actionIdentifier;
42
43     /** Whether the item is queueable (no explanation posted by NEEO) */
44     private final boolean isQueueable;
45
46     /**
47      * Creates the directory from the given items
48      *
49      * @param title a non-null, non-empty title
50      * @param thumbnailUri a possibly null, possibly empty thumbnail URI
51      * @param browseIdentifier a possibly null, possibly empty browse identifier
52      * @param actionIdentifier a possibly null, possibly empty action identifier
53      * @param isQueueable true/false if queueable
54      * @throws IllegalArgumentException if both browseIdentifier and actionIdentifier are null or empty
55      */
56     public NeeoDirectoryResultItem(String title, @Nullable String thumbnailUri, @Nullable String browseIdentifier,
57             @Nullable String actionIdentifier, boolean isQueueable) {
58         NeeoUtil.requireNotEmpty(title, "title cannot be empty");
59
60         if (StringUtils.isEmpty(browseIdentifier) && StringUtils.isEmpty(actionIdentifier)) {
61             throw new IllegalArgumentException("Either browserIdentifier or actionIdentifier must be specified");
62         }
63
64         this.title = title;
65         this.thumbnailUri = thumbnailUri;
66         this.browseIdentifier = browseIdentifier;
67         this.actionIdentifier = actionIdentifier;
68         this.isQueueable = isQueueable;
69     }
70
71     /**
72      * The title (label) of the item
73      *
74      * @return the non-null, non-empty title
75      */
76     public String getTitle() {
77         return title;
78     }
79
80     /**
81      * The thumbnail URI representing the item
82      *
83      * @return a possibly null, possibly empty thumbnail URI
84      */
85     @Nullable
86     public String getThumbnailUri() {
87         return thumbnailUri;
88     }
89
90     /**
91      * The browse identifier
92      *
93      * @return a possibly null, possibly empty browse identifier
94      */
95     @Nullable
96     public String getBrowseIdentifier() {
97         return browseIdentifier;
98     }
99
100     /**
101      * The action identifier
102      *
103      * @return a possibly null, possibly empty action identifier
104      */
105     @Nullable
106     public String getActionIdentifier() {
107         return actionIdentifier;
108     }
109
110     /**
111      * Whether the item is queueable or not
112      *
113      * @return true if queueable, false otherwise
114      */
115     public boolean isQueueable() {
116         return isQueueable;
117     }
118
119     @Override
120     public String toString() {
121         return "NeeoDiscoveryListResultItem [title=" + title + ", thumbnailUri=" + thumbnailUri + ", browseIdentifier="
122                 + browseIdentifier + ", actionIdentifier=" + actionIdentifier + ", isQueueable=" + isQueueable + "]";
123     }
124 }