templates.extendableInnerBuildert Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of JavaForger Show documentation
Show all versions of JavaForger Show documentation
JavaForger can create source code from templates using existing java classes as input.
<#if !constructors?? | constructors?size < 1>
public ${class.name}() {
// empty constructor which would otherwise be invisible due to the constructor receiving the builder.
}
#if>
protected ${class.name}(${class.name}.Builder> builder) {
<#list fields as field>
this.${field.name} = builder.${field.name} == null ? this.${field.name} : builder.${field.name};
#list>
}
/**
* Creates builder to build {@link ${class.name}}.
* @return created builder
*/
public static Builder builder() {
return new Builder();
}
/**
* Builder to build {@link ${class.name}}.
*/
@SuppressWarnings("unchecked")
public static class Builder> {
<#list fields as field>
private ${field.type} ${field.name}<#if field.defaultInit??> = ${field.defaultInit}#if>;
#list>
protected Builder() {
// Builder should only be used via the parent class or extending builder
}
<#list fields as field>
public T ${field.name}(${field.type} ${field.name}) {
<#if field.collection>
this.${field.name}.clear();
this.${field.name}.addAll(${field.name});
<#else>
this.${field.name} = ${field.name};
#if>
return (T) this;
}
#list>
public ${class.name} build() {
return new ${class.name}(this);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy