]> git.basschouten.com Git - openhab-addons.git/blob
30f43892177137c31203464cbcee0bffa42d02e6
[openhab-addons.git] /
1 /**
2  * Copyright 2017-2018 Gregory Moyer and contributors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.openhab.binding.lametrictime.api.local;
17
18 import java.util.List;
19
20 import org.openhab.binding.lametrictime.api.local.model.Error;
21 import org.openhab.binding.lametrictime.api.local.model.Failure;
22
23 public class LaMetricTimeException extends Exception
24 {
25     private static final long serialVersionUID = 1L;
26
27     public LaMetricTimeException()
28     {
29         super();
30     }
31
32     public LaMetricTimeException(String message)
33     {
34         super(message);
35     }
36
37     public LaMetricTimeException(Throwable cause)
38     {
39         super(cause);
40     }
41
42     public LaMetricTimeException(String message, Throwable cause)
43     {
44         super(message, cause);
45     }
46
47     public LaMetricTimeException(String message,
48                                  Throwable cause,
49                                  boolean enableSuppression,
50                                  boolean writableStackTrace)
51     {
52         super(message, cause, enableSuppression, writableStackTrace);
53     }
54
55     public LaMetricTimeException(Failure failure)
56     {
57         super(buildMessage(failure));
58     }
59
60     private static String buildMessage(Failure failure)
61     {
62         StringBuilder builder = new StringBuilder();
63
64         List<Error> errors = failure.getErrors();
65         if (!errors.isEmpty())
66         {
67             builder.append(errors.get(0).getMessage());
68         }
69
70         for (int i = 1; i < errors.size(); i++)
71         {
72             builder.append("; ").append(errors.get(i).getMessage());
73         }
74
75         return builder.toString();
76     }
77 }