2 * Copyright (c) 2010-2023 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.binding.hpprinter.internal.api;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
19 * The {@link HPServerResult} is responsible for returning the
20 * reading of data from the HP Embedded Web Server.
22 * @author Stewart Cossey - Initial contribution
25 public class HPServerResult<result> {
26 private final RequestStatus status;
27 private final @Nullable result data;
28 private final String errorMessage;
30 public HPServerResult(RequestStatus status, @Nullable String errorMessage) {
33 this.errorMessage = errorMessage != null ? errorMessage : "";
36 public HPServerResult(result data) {
37 this.status = RequestStatus.SUCCESS;
39 this.errorMessage = "";
42 @SuppressWarnings("null")
43 public result getData() {
44 final result localData = data;
45 if (status != RequestStatus.SUCCESS || localData == null) {
46 throw new IllegalStateException("No data available for result");
51 public RequestStatus getStatus() {
55 public String getErrorMessage() {
59 public enum RequestStatus {