Skip to content

Support for adders instead of setters for Collections record components #5

Description

@sashirestela

This functionality is about to include "adders" methods (instead of setters) to builders for record components of Collection type. For better usability, it would be necessary to create a new annotation such as @Builder.Singular(value=optionalSingularName) to indicate what record components will be singularize and optionally to indicate what singular name to use in case it cannot be deducted from the plural name.

For example:

public record Project(Integer id, String name, @Builder.Singular List<String> members) {}

Project project1 = ProjectBuilder.builder()
    .id(101)
    .name("Special Project")
    .member("Rose")
    .member("Jack")
    .build();

Take as a reference: https://projectlombok.org/features/Builder#Singular

The rules to deriving singular forms from plural words in English are:

  • Words ending in "ves", replace "ves" with "fe". Ex: lives → life
  • Words ending in "ies", replace "ies" with "y". Ex: cities → city
  • Words ending in "es", remove "es". Ex: boxes → box
  • Words ending in "s", remove "s". Ex: names → name
  • Any other case should require to indicate an explicit singular name.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions