All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.joinedworkz.common.builder.ParameterBuilder Maven / Gradle / Ivy

There is a newer version: 1.3.46
Show newest version
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();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy