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