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

templates.extendableInnerBuildert Maven / Gradle / Ivy

Go to download

JavaForger can create source code from templates using existing java classes as input.

There is a newer version: 2.0.1
Show newest version

<#if !constructors?? | constructors?size < 1>
  public ${class.name}() {
    // empty constructor which would otherwise be invisible due to the constructor receiving the builder. 
  }


  protected ${class.name}(${class.name}.Builder builder) {
<#list fields as field>
    this.${field.name} = builder.${field.name} == null ? this.${field.name} : builder.${field.name};

  }

  /**
   * 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};


    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};

      return (T) this;
    }
    


    public  ${class.name} build() {
      return new ${class.name}(this);
    }
  }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy