]> git.basschouten.com Git - openhab-addons.git/blob
0af0278070ee7b0b68b8aa4903ace8ef314bac30
[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.binding.lametrictime.internal.api.local;
14
15 import java.util.List;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.lametrictime.internal.api.local.dto.Error;
19 import org.openhab.binding.lametrictime.internal.api.local.dto.Failure;
20
21 /**
22  * Parent class for LaMetricTime exceptions.
23  *
24  * @author Gregory Moyer - Initial contribution
25  */
26 @NonNullByDefault
27 public class LaMetricTimeException extends Exception {
28     private static final long serialVersionUID = 1L;
29
30     public LaMetricTimeException() {
31         super();
32     }
33
34     public LaMetricTimeException(String message) {
35         super(message);
36     }
37
38     public LaMetricTimeException(Throwable cause) {
39         super(cause);
40     }
41
42     public LaMetricTimeException(String message, Throwable cause) {
43         super(message, cause);
44     }
45
46     public LaMetricTimeException(String message, Throwable cause, boolean enableSuppression,
47             boolean writableStackTrace) {
48         super(message, cause, enableSuppression, writableStackTrace);
49     }
50
51     public LaMetricTimeException(Failure failure) {
52         super(buildMessage(failure));
53     }
54
55     private static String buildMessage(Failure failure) {
56         StringBuilder builder = new StringBuilder();
57
58         List<Error> errors = failure.getErrors();
59         if (!errors.isEmpty()) {
60             builder.append(errors.get(0).getMessage());
61         }
62
63         for (int i = 1; i < errors.size(); i++) {
64             builder.append("; ").append(errors.get(i).getMessage());
65         }
66
67         return builder.toString();
68     }
69 }