2 * Copyright (c) 2010-2021 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.io.neeo.internal.servletservices.models;
15 import java.util.List;
17 import org.apache.commons.lang.StringUtils;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20 import org.openhab.io.neeo.internal.models.NeeoDevice;
21 import org.openhab.io.neeo.internal.models.NeeoDeviceChannel;
24 * The class that encapsulates a result of a NEEO Brain call. THe result can be successful or not, include a message and
27 * @author Tim Roberts - Initial Contribution
30 public class ReturnStatus {
32 /** The static success helper */
33 public static final ReturnStatus SUCCESS = new ReturnStatus(true);
35 /** True if the call was successful, false otherwise */
36 private final boolean success;
38 /** The optional message if not successful */
40 private final String message;
42 /** The optional device if successful */
44 private final NeeoDevice device;
46 /** The optional channel if successful */
48 private final List<NeeoDeviceChannel> channels;
51 * Creates a return status of true or not (with no message or device)
53 * @param success whether the call was successful
55 public ReturnStatus(boolean success) {
56 this(success, null, null, null);
60 * Creates a return status of SUCCESS with a device. If device is null, same result as calling 'constructor(true)'
62 * @param device the possibly null device
64 public ReturnStatus(NeeoDevice device) {
65 this(true, null, device, null);
69 * Creates a return status of SUCCESS with a channel. If channel is null, same result as calling 'constructor(true)'
71 * @param channels the possibly null channel
73 public ReturnStatus(@Nullable List<NeeoDeviceChannel> channels) {
74 this(true, null, null, channels);
78 * Creates the return status with the specified message. If the message is empty, same result as calling
79 * 'constructor(true)'. If not empty, success is set to false
81 * @param message the possibly null, possibly empty message
83 public ReturnStatus(@Nullable String message) {
84 this(StringUtils.isEmpty(message), message, null, null);
88 * Creates the return status with the specified message and success indicator
90 * @param success true if successful, false otherwise
91 * @param message the possibly null, possibly empty message
93 public ReturnStatus(boolean success, String message) {
94 this(success, message, null, null);
98 * Creates the returns status for the success, message and optional device or channel.
100 * @param success whether the call was successful
101 * @param message the possibly null, possibly empty message
102 * @param device the possibly null device
103 * @param channels the possibly null channels
105 private ReturnStatus(boolean success, @Nullable String message, @Nullable NeeoDevice device,
106 @Nullable List<NeeoDeviceChannel> channels) {
107 this.success = success;
108 this.message = message;
109 this.device = device;
110 this.channels = channels;
114 * Checks if the call was successful
116 * @return true if successful, false otherwise
118 public boolean isSuccess() {
123 * Gets the related message
125 * @return the possibly empty, possibly null message
128 public String getMessage() {
133 * Gets the related device
135 * @return the possibly null device
138 public NeeoDevice getDevice() {
143 * Gets the related channel
145 * @return the possibly null channel
148 public List<NeeoDeviceChannel> getChannels() {
153 public String toString() {
154 return "ReturnStatus [success=" + success + ", message=" + message + ", device=" + device + ", channels="