Skip to content

Add optional field getters in builder (isSetXxx() and xxx()) #268

Description

@AndreasIgel

Feature Request

Inspired by RecordBuilder's field getter pattern, where the builder exposes accessor methods to read back the current state of each field during construction.

Current State

The TrackedValue infrastructure already has .isSet() and .value() methods, but these are only used internally (in build(), collection add, etc.). There are no public getters on the builder to read field values from outside.

Proposed Feature

Add an optional annotation flag generateFieldGetters = true to @SimpleBuilder / @SimpleMinimalBuilder that generates two methods per field:

// Check if a field was explicitly setpublicbooleanisSetAccreditationName() {
returnthis.accreditationName.isSet();
}
// Read the current value (null if unset)publicStringaccreditationName() {
returnthis.accreditationName.value();
}

Use Cases

  • Conditional logic during building: if (builder.accreditationName() == null) builder.accreditationName("UNKNOWN");
  • Check if explicitly set: if (!builder.isSetAccreditationName()) { /* only set default if user didn't */ }
  • Debugging: Inspect builder state mid-construction
  • Validation: Read value, validate, optionally override before build

Why Optional?

Adding getters increases the builder's API surface. Users who want a minimal builder (like @SimpleMinimalBuilder) may not want these methods. Making it opt-in via a flag keeps the default behavior unchanged.

Implementation Notes

  • Delegates to existing TrackedValue.isSet() and TrackedValue.value() — minimal implementation effort
  • Should be a new generator or enhancer with a configurable priority
  • Consider naming: isSetXxx() vs hasXxx()isSet is consistent with TrackedValue terminology

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions