org.joinedworkz.common.builder.ParameterBuilder.xtend 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
class ParameterBuilder {
final StringBuilder buffer = new StringBuilder
final String separator
boolean empty = true
new() {
this(', ')
}
new(String separator) {
this.separator = separator
}
def ParameterBuilder annotationClass(String c) {
buffer.append(c)
return this
}
def appendPrefix(String parameterText) {
buffer.append(parameterText)
}
def append(Object parameterObject) {
if (parameterObject !== null) {
return appendWhenTrue(true, parameterObject.toString)
}
}
def append(String parameterText) {
return appendWhenTrue(true, parameterText)
}
def next() {
appendCommaIfNotEmpty
}
def appendPart(Object parameterText) {
if (parameterText !== null) {
if (empty) {
empty = false
}
buffer.append(parameterText.toString)
}
return this
}
def appendPart(String parameterText) {
if (empty) {
empty = false
}
buffer.append(parameterText)
return this
}
def appendWhenNotNull(Object conditionObject, String parameterText) {
return appendWhenTrue(conditionObject !== null, parameterText)
}
def appendWhenTrue(boolean resultOfCondition, String parameterText) {
if (resultOfCondition) {
appendCommaIfNotEmpty()
buffer.append(parameterText)
}
return this
}
def appendPartWhenTrue(boolean resultOfCondition, String parameterText) {
if (resultOfCondition) {
appendPart(parameterText)
}
return this
}
protected def appendCommaIfNotEmpty() {
if (empty) {
empty = false
} else {
buffer.append(separator)
}
}
def isEmpty() {
return empty
}
def build() {
return buffer.toString
}
override toString() {
return build()
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy