Package io.jonasg.bob

Enum Class ConstructorPolicy

java.lang.Object
java.lang.Enum<ConstructorPolicy>
io.jonasg.bob.ConstructorPolicy
All Implemented Interfaces:
Serializable, Comparable<ConstructorPolicy>, Constable

public enum ConstructorPolicy extends Enum<ConstructorPolicy>
Enumerates the policies for constructor behavior in the Buildable annotation context. This enumeration defines how the object construction must handle its constructor fields during instantiation through the builder pattern.

These policies allow developers to specify whether all fields must be explicitly set before constructing an object or if missing fields can be initialized with default values.

  • Enum Constant Details

    • ENFORCED

      public static final ConstructorPolicy ENFORCED
      Requires all fields to be explicitly set in the constructor. If any field is not set, the builder will throw an exception. This policy ensures that the constructed object is fully initialized with all the specified fields, promoting immutability and thread-safety, assuming that all fields are properly handled.
    • PERMISSIVE

      public static final ConstructorPolicy PERMISSIVE
      Allows the object to be constructed even if not all constructor parameters have been explicitly set. Fields not explicitly set will be initialized to their default values (e.g., null for object references, 0 for int, false for boolean, etc.).

      This policy is suitable for situations where not all fields are required to have a value, allowing for more flexible object creation.

  • Method Details

    • values

      public static ConstructorPolicy[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static ConstructorPolicy valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null