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 StringBuilder appendPrefix(final String parameterText) {
return this.buffer.append(parameterText);
}
public ParameterBuilder append(final Object parameterObject) {
if ((parameterObject != null)) {
return this.appendWhenTrue(true, parameterObject.toString());
}
return null;
}
public ParameterBuilder append(final String parameterText) {
return this.appendWhenTrue(true, parameterText);
}
public Object next() {
return this.appendCommaIfNotEmpty();
}
public ParameterBuilder appendPart(final Object parameterText) {
if ((parameterText != null)) {
if (this.empty) {
this.empty = false;
}
this.buffer.append(parameterText.toString());
}
return this;
}
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;
}
public ParameterBuilder appendPartWhenTrue(final boolean resultOfCondition, final String parameterText) {
if (resultOfCondition) {
this.appendPart(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 boolean isEmpty() {
return this.empty;
}
public String build() {
return this.buffer.toString();
}
@Override
public String toString() {
return this.build();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy