Package io.jonasg.bob
Enum Class ConstructorPolicy
- All Implemented Interfaces:
Serializable,Comparable<ConstructorPolicy>,Constable
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.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionRequires all fields to be explicitly set in the constructor.Allows the object to be constructed even if not all constructor parameters have been explicitly set. -
Method Summary
Modifier and TypeMethodDescriptionstatic ConstructorPolicyReturns the enum constant of this class with the specified name.static ConstructorPolicy[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
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
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.,nullfor object references,0forint,falseforboolean, 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
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
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 nameNullPointerException- if the argument is null
-