com.xlrit.gears.base.util.DisplayedHelper Maven / Gradle / Ivy
package com.xlrit.gears.base.util;
public class DisplayedHelper {
private final StringBuilder sb;
private boolean excludeNull = false;
public DisplayedHelper() {
this.sb = new StringBuilder();
}
public DisplayedHelper excludeNulls() {
excludeNull = true;
return this;
}
public DisplayedHelper includeNulls() {
excludeNull = false;
return this;
}
public DisplayedHelper add(String name, Object value) {
if (!excludeNull || value != null) {
if (!sb.isEmpty()) sb.append(", ");
sb.append(name).append(": ").append(value);
}
return this;
}
@Override
public String toString() {
return sb.toString();
}
}