View Javadoc
1   package fr.univtln.bruno.samples.java101.tp1.lombok;
2   
3   import lombok.*;
4   
5   /**
6    * Compact Lombok-backed Person example without validation.
7    *
8    * <p>Behavior and generation:
9    * <ul>
10   *   <li>{@code @AllArgsConstructor(access = AccessLevel.PRIVATE, staticName = "of")} generates
11   *       a private all-arguments constructor and a private static factory method
12   *       named {@code of(...)}. Client code can call {@code PersonLombok.of(...)}
13   *       to create an instance via that generated factory.</li>
14   *   <li>{@code @Builder} generates a fluent builder class ({@code PersonLombokBuilder}) that
15   *       can also be used to create instances: {@code PersonLombok.builder().firstName(...).build()}.</li>
16   *   <li>{@code @Getter}, {@code @ToString}, {@code @EqualsAndHashCode} generate the usual
17   *       accessors and utilities. We do not use {@code @Data} here on purpose; {@code @Data}
18   *       would combine several of these annotations (getters/setters/toString/equals/hashCode)
19   *       and is useful for quick prototypes, but it hides generated mutability and can be
20   *       surprising for beginners.</li>
21   *   <li>The field {@code age} is explicitly mutable (annotated with {@code @Setter}) while
22   *       {@code firstName} and {@code lastName} are final — this shows a mixed mutability
23   *       example where identity fields are immutable but a mutable attribute exists.</li>
24   * </ul>
25   *
26   * <p>Validation: this class intentionally does <em>not</em> perform validation. Prefer
27   * {@code PersonLombokSecure} (secure variant) when you need input validation at the
28   * factory/builder boundary. This minimal example is useful to teach tooling (Lombok)
29   * and to compare with manual POJOs and validated variants.</p>
30   */
31  
32  @AllArgsConstructor(access = AccessLevel.PRIVATE, staticName = "of") // Private constructor with static factory method
33  @Builder // Generate a builder for this class
34  @Getter // Generate getters for all fields
35  @ToString // Generate a toString method
36  @EqualsAndHashCode // Generate equals and hashCode methods with all fields
37  @Setter // Generate setters for all fields (simple mutable example)
38  public class PersonLombok {
39      private String firstName;
40      private String lastName;
41      private int age;
42  
43      /**
44       * Protected no-arg constructor for frameworks and Javadoc clarity.
45       * Lombok will generate other constructors and builder methods; this
46       * constructor is intentionally minimal and for documentation only.
47       */
48      protected PersonLombok() {
49          // no-op: present for framework construction and to clarify Javadoc
50      }
51  }