org.joinedworkz.common.builder.ParameterBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of common-base Show documentation
Show all versions of common-base Show documentation
DSL based modeling framework - facilities common base
package org.joinedworkz.common.builder;
@SuppressWarnings("all")
public class ParameterBuilder {
private final StringBuilder buffer = new StringBuilder();
private final String separator;
private boolean empty = true;
public ParameterBuilder() {
this(", ");
}
public ParameterBuilder(final String separator) {
this.separator = separator;
}
public ParameterBuilder annotationClass(final String c) {
this.buffer.append(c);
return this;
}
public ParameterBuilder append(final String parameterText) {
return this.appendWhenTrue(true, parameterText);
}
public Object next() {
return this.appendCommaIfNotEmpty();
}
public ParameterBuilder appendPart(final String parameterText) {
if (this.empty) {
this.empty = false;
}
this.buffer.append(parameterText);
return this;
}
public ParameterBuilder appendWhenNotNull(final Object conditionObject, final String parameterText) {
return this.appendWhenTrue((conditionObject != null), parameterText);
}
public ParameterBuilder appendWhenTrue(final boolean resultOfCondition, final String parameterText) {
if (resultOfCondition) {
this.appendCommaIfNotEmpty();
this.buffer.append(parameterText);
}
return this;
}
protected Object appendCommaIfNotEmpty() {
Object _xifexpression = null;
if (this.empty) {
_xifexpression = Boolean.valueOf(this.empty = false);
} else {
_xifexpression = this.buffer.append(this.separator);
}
return _xifexpression;
}
public String build() {
return this.buffer.toString();
}
@Override
public String toString() {
return this.build();
}
}