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.groupepsa.internal.rest.api.dto;
15 import java.io.IOException;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
21 * @author Arjan Mels - Initial contribution
24 class ToStringBuilder implements Appendable, CharSequence {
25 protected StringBuilder stringBuilder = new StringBuilder();
27 ToStringBuilder(Object obj) {
32 return stringBuilder.length();
36 public char charAt(int index) {
37 return stringBuilder.charAt(index);
41 public CharSequence subSequence(int start, int end) {
42 return stringBuilder.subSequence(start, end);
46 public ToStringBuilder append(@Nullable CharSequence csq) throws IOException {
47 if (stringBuilder.length() != 0) {
48 stringBuilder.append(", ");
50 stringBuilder.append(csq);
55 public ToStringBuilder append(@Nullable CharSequence csq, int start, int end) throws IOException {
56 if (stringBuilder.length() != 0) {
57 stringBuilder.append(", ");
59 stringBuilder.append(csq, start, end);
64 public ToStringBuilder append(char c) throws IOException {
65 if (stringBuilder.length() != 0) {
66 stringBuilder.append(", ");
68 stringBuilder.append(c);
72 public ToStringBuilder append(Object key, @Nullable Object value) {
73 if (stringBuilder.length() != 0) {
74 stringBuilder.append(", ");
76 stringBuilder.append(key.toString() + ": " + ((value == null) ? "(null)" : value.toString()));
81 public String toString() {
82 return "{ " + stringBuilder.toString() + " }";