]> git.basschouten.com Git - openhab-addons.git/blob
e743379ea4ab5df5d65161755383abe13c795867
[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.groupepsa.internal.rest.api.dto;
14
15 import java.io.IOException;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19
20 /**
21  * @author Arjan Mels - Initial contribution
22  */
23 @NonNullByDefault
24 class ToStringBuilder implements Appendable, CharSequence {
25     protected StringBuilder stringBuilder = new StringBuilder();
26
27     ToStringBuilder(Object obj) {
28     }
29
30     @Override
31     public int length() {
32         return stringBuilder.length();
33     }
34
35     @Override
36     public char charAt(int index) {
37         return stringBuilder.charAt(index);
38     }
39
40     @Override
41     public CharSequence subSequence(int start, int end) {
42         return stringBuilder.subSequence(start, end);
43     }
44
45     @Override
46     public ToStringBuilder append(@Nullable CharSequence csq) throws IOException {
47         if (stringBuilder.length() != 0) {
48             stringBuilder.append(", ");
49         }
50         stringBuilder.append(csq);
51         return this;
52     }
53
54     @Override
55     public ToStringBuilder append(@Nullable CharSequence csq, int start, int end) throws IOException {
56         if (stringBuilder.length() != 0) {
57             stringBuilder.append(", ");
58         }
59         stringBuilder.append(csq, start, end);
60         return this;
61     }
62
63     @Override
64     public ToStringBuilder append(char c) throws IOException {
65         if (stringBuilder.length() != 0) {
66             stringBuilder.append(", ");
67         }
68         stringBuilder.append(c);
69         return this;
70     }
71
72     public ToStringBuilder append(Object key, @Nullable Object value) {
73         if (stringBuilder.length() != 0) {
74             stringBuilder.append(", ");
75         }
76         stringBuilder.append(key.toString() + ": " + ((value == null) ? "(null)" : value.toString()));
77         return this;
78     }
79
80     @Override
81     public String toString() {
82         return "{ " + stringBuilder.toString() + " }";
83     }
84 }