2 * Copyright (c) 2010-2022 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.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.io.neeo.internal.models.NeeoDevice;
20 import org.openhab.io.neeo.internal.models.NeeoDeviceChannel;
23 * The class that encapsulates a result of a NEEO Brain call. THe result can be successful or not, include a message and
26 * @author Tim Roberts - Initial Contribution
29 public class ReturnStatus {
31 /** The static success helper */
32 public static final ReturnStatus SUCCESS = new ReturnStatus(true);
34 /** True if the call was successful, false otherwise */
35 private final boolean success;
37 /** The optional message if not successful */
38 private final @Nullable String message;
40 /** The optional device if successful */
41 private final @Nullable NeeoDevice device;
43 /** The optional channel if successful */
44 private final @Nullable List<NeeoDeviceChannel> channels;
47 * Creates a return status of true or not (with no message or device)
49 * @param success whether the call was successful
51 public ReturnStatus(boolean success) {
52 this(success, null, null, null);
56 * Creates a return status of SUCCESS with a device. If device is null, same result as calling 'constructor(true)'
58 * @param device the possibly null device
60 public ReturnStatus(NeeoDevice device) {
61 this(true, null, device, null);
65 * Creates a return status of SUCCESS with a channel. If channel is null, same result as calling 'constructor(true)'
67 * @param channels the possibly null channel
69 public ReturnStatus(@Nullable List<NeeoDeviceChannel> channels) {
70 this(true, null, null, channels);
74 * Creates the return status with the specified message. If the message is empty, same result as calling
75 * 'constructor(true)'. If not empty, success is set to false
77 * @param message the possibly null, possibly empty message
79 public ReturnStatus(@Nullable String message) {
80 this(message == null || message.isEmpty(), message, null, null);
84 * Creates the return status with the specified message and success indicator
86 * @param success true if successful, false otherwise
87 * @param message the possibly null, possibly empty message
89 public ReturnStatus(boolean success, String message) {
90 this(success, message, null, null);
94 * Creates the returns status for the success, message and optional device or channel.
96 * @param success whether the call was successful
97 * @param message the possibly null, possibly empty message
98 * @param device the possibly null device
99 * @param channels the possibly null channels
101 private ReturnStatus(boolean success, @Nullable String message, @Nullable NeeoDevice device,
102 @Nullable List<NeeoDeviceChannel> channels) {
103 this.success = success;
104 this.message = message;
105 this.device = device;
106 this.channels = channels;
110 * Checks if the call was successful
112 * @return true if successful, false otherwise
114 public boolean isSuccess() {
119 * Gets the related message
121 * @return the possibly empty, possibly null message
123 public @Nullable String getMessage() {
128 * Gets the related device
130 * @return the possibly null device
132 public @Nullable NeeoDevice getDevice() {
137 * Gets the related channel
139 * @return the possibly null channel
141 public @Nullable List<NeeoDeviceChannel> getChannels() {
146 public String toString() {
147 return "ReturnStatus [success=" + success + ", message=" + message + ", device=" + device + ", channels="